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

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

View File

@ -72,48 +72,4 @@ export default {
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;