🔥 个人信息:昵称、头像、性别的修改

pull/29/head^2
YunaiV 2023-12-16 22:52:32 +08:00
parent 236b90ae3f
commit 46f3aa7255
3 changed files with 76 additions and 84 deletions

View File

@ -38,7 +38,7 @@
</view> </view>
<view class="bg-white ss-p-x-30"> <view class="bg-white ss-p-x-30">
<!-- 昵称 + 性别 -->
<uni-forms-item name="nickname" label="昵称"> <uni-forms-item name="nickname" label="昵称">
<uni-easyinput <uni-easyinput
v-model="state.model.nickname" v-model="state.model.nickname"
@ -48,24 +48,23 @@
:placeholderStyle="placeholderStyle" :placeholderStyle="placeholderStyle"
/> />
</uni-forms-item> </uni-forms-item>
<uni-forms-item name="sex" label="性别">
<!-- <uni-forms-item name="gender" label="性别">
<view class="ss-flex ss-col-center ss-h-100"> <view class="ss-flex ss-col-center ss-h-100">
<radio-group @change="onChangeGender" class="ss-flex ss-col-center"> <radio-group @change="onChangeGender" class="ss-flex ss-col-center">
<label class="radio" v-for="item in genderRadioMap" :key="item.value"> <label class="radio" v-for="item in sexRadioMap" :key="item.value">
<view class="ss-flex ss-col-center ss-m-r-32"> <view class="ss-flex ss-col-center ss-m-r-32">
<radio <radio
:value="item.value" :value="item.value"
color="var(--ui-BG-Main)" color="var(--ui-BG-Main)"
style="transform: scale(0.8)" style="transform: scale(0.8)"
:checked="item.value == state.model.gender" :checked="parseInt(item.value) === state.model.sex"
/> />
<view class="gender-name">{{ item.name }}</view> <view class="gender-name">{{ item.name }}</view>
</view> </view>
</label> </label>
</radio-group> </radio-group>
</view> </view>
</uni-forms-item> --> </uni-forms-item>
<uni-forms-item name="mobile" label="手机号" @tap="onChangeMobile"> <uni-forms-item name="mobile" label="手机号" @tap="onChangeMobile">
<uni-easyinput <uni-easyinput
@ -105,7 +104,6 @@
v-if="userInfo.verification?.password" v-if="userInfo.verification?.password"
:modelValue="true" :modelValue="true"
/> />
<button v-else class="ss-reset-button ss-flex ss-col-center ss-row-center"> <button v-else class="ss-reset-button ss-flex ss-col-center ss-row-center">
<text class="_icon-forward" style="color: #bbbbbb; font-size: 26rpx"></text> <text class="_icon-forward" style="color: #bbbbbb; font-size: 26rpx"></text>
</button> </button>
@ -185,11 +183,12 @@
</template> </template>
<script setup> <script setup>
import { computed, ref, reactive, onBeforeMount, unref } from 'vue'; import { computed, ref, reactive, onBeforeMount } from 'vue';
import { mobile, password, username } from '@/sheep/validate/form'; import { mobile, password, username } from '@/sheep/validate/form';
import sheep from '@/sheep'; import sheep from '@/sheep';
import { clone } from 'lodash'; import { clone } from 'lodash';
import { showAuthModal } from '@/sheep/hooks/useModal'; import { showAuthModal } from '@/sheep/hooks/useModal';
import FileApi from '@/sheep/api/infra/file';
const state = reactive({ const state = reactive({
model: {}, // model: {}, //
@ -199,59 +198,51 @@
const placeholderStyle = 'color:#BBBBBB;font-size:28rpx;line-height:normal'; const placeholderStyle = 'color:#BBBBBB;font-size:28rpx;line-height:normal';
const genderRadioMap = [ const sexRadioMap = [{
{
name: '男', name: '男',
value: '1', value: '1',
}, },
{ {
name: '女', name: '女',
value: '2', value: '2',
}, }
{
name: '未知',
value: '0',
},
]; ];
const userInfo = computed(() => sheep.$store('user').userInfo); const userInfo = computed(() => sheep.$store('user').userInfo);
// TODO // TODO
function onChangeGender(e) { function onChangeGender(e) {
state.model.gender = e.detail.value; state.model.sex = e.detail.value;
} }
// TODO
const onChangeUsername = () => {
!state.model.verification?.username && showAuthModal('changeUsername');
};
// TODO // TODO
const onChangeMobile = () => { const onChangeMobile = () => {
showAuthModal('changeMobile'); showAuthModal('changeMobile');
}; };
// TODO // TODO
function onChooseAvatar(e) { function onChooseAvatar(e) {
const tempUrl = e.detail.avatarUrl || ''; const tempUrl = e.detail.avatarUrl || '';
uploadAvatar(tempUrl); uploadAvatar(tempUrl);
} }
// TODO //
function onChangeAvatar() { function onChangeAvatar() {
uni.chooseImage({ uni.chooseImage({
success: async (chooseImageRes) => { success: async (chooseImageRes) => {
const tempUrl = chooseImageRes.tempFilePaths[0]; const tempUrl = chooseImageRes.tempFilePaths[0];
uploadAvatar(tempUrl); await uploadAvatar(tempUrl);
}, },
}); });
} }
// TODO //
async function uploadAvatar(tempUrl) { async function uploadAvatar(tempUrl) {
if (!tempUrl) return; if (!tempUrl) {
let { path } = await sheep.$api.app.upload(tempUrl, 'ugc'); return;
state.model.avatar = path; }
let { data } = await FileApi.uploadFile(tempUrl);
state.model.avatar = data;
} }
// / TODO // / TODO
@ -289,28 +280,25 @@
}); });
} }
// TODO //
async function onSubmit() { async function onSubmit() {
// const { error, data } = await sheep.$api.user.update({ const { code } = await sheep.$api.user.update({
// avatar: state.model.avatar,
// nickname: state.model.nickname,
// gender: state.model.gender,
// });
const { code, data } = await sheep.$api.user.update({
avatar: state.model.avatar, avatar: state.model.avatar,
nickname: state.model.nickname, nickname: state.model.nickname,
// gender: state.model.gender, sex: state.model.sex,
}); });
if (code === 0) { if (code === 0) {
getUserInfo(); await getUserInfo();
} }
} }
// TODO //
const getUserInfo = async () => { const getUserInfo = async () => {
//
const userInfo = await sheep.$store('user').getInfo(); const userInfo = await sheep.$store('user').getInfo();
state.model = clone(userInfo); state.model = clone(userInfo);
// TODO
if (sheep.$platform.name !== 'H5') { if (sheep.$platform.name !== 'H5') {
return; return;
// ,, // ,,
@ -321,8 +309,7 @@
} }
}; };
// TODO onBeforeMount(() => {
onBeforeMount(async () => {
getUserInfo(); getUserInfo();
}); });
</script> </script>

View File

@ -72,48 +72,4 @@ export default {
method: 'GET' method: 'GET'
}), }),
}, },
//上传
upload: (file, group = 'ugc', callback) => {
const token = uni.getStorageSync('token');
uni.showLoading({
title: '上传中',
});
return new Promise((resolve, reject) => {
// 此处先换成yudao
uni.uploadFile({
url: 'http://api-dashboard.yudao.iocoder.cn' + '/app-api/infra/file/upload',
filePath: file,
name: 'file',
formData: {
group,
},
header: {
// Accept: 'text/json',
// Authorization: token,
Accept : '*/*',
'tenant-id' :'1',
Authorization: 'Bearer test247',
},
success: (uploadFileRes) => {
let result = JSON.parse(uploadFileRes.data);
if (result.error === 1) {
uni.showToast({
icon: 'none',
title: result.msg,
});
} else {
return resolve(result.data);
}
},
fail: (error) => {
console.log('上传失败:', error);
return resolve(false);
},
complete: () => {
uni.hideLoading();
},
});
});
},
}; };

49
sheep/api/infra/file.js Normal file
View File

@ -0,0 +1,49 @@
import request2 from '@/sheep/request2';
const FileApi = {
// 上传文件
uploadFile: (file) => {
const token = uni.getStorageSync('token');
uni.showLoading({
title: '上传中',
});
return new Promise((resolve, reject) => {
// 此处先换成yudao
// TODO 芋艿:后续搞下
uni.uploadFile({
// url: 'http://api-dashboard.yudao.iocoder.cn' + '/app-api/infra/file/upload',
url: 'http://127.0.0.1:48080' + '/app-api/infra/file/upload',
filePath: file,
name: 'file',
header: {
// Accept: 'text/json',
// Authorization: token,
Accept : '*/*',
'tenant-id' :'1',
Authorization: 'Bearer test247',
},
success: (uploadFileRes) => {
debugger
let result = JSON.parse(uploadFileRes.data);
if (result.error === 1) {
uni.showToast({
icon: 'none',
title: result.msg,
});
} else {
return resolve(result);
}
},
fail: (error) => {
console.log('上传失败:', error);
return resolve(false);
},
complete: () => {
uni.hideLoading();
},
});
});
},
};
export default FileApi;