Commit 888fedcc authored by liubinyu's avatar liubinyu

修改生日等信息后重置页面

parent 9a60819e
......@@ -49,8 +49,13 @@
async init() {
this.recordList = []
this.inputText = ''
if (this.x_user.birthday && this.x_user.sex) {
this.inputText = this.getQuestion()
this.send()
} else {
await this.getInfo()
this.getZSYC()
}
},
// 获取星座信息
async getInfo() {
......@@ -81,6 +86,17 @@
const msg = res?.data?.[0]?.message?.content || this.$t('Parsing Failed')
this.addMsg(msg)
},
// 组装生日信息
getQuestion() {
const { birthday, sex } = this.x_user
const lang = this.$i18n.locale
const a = birthday.split(/[-: ]/)
if (lang === 'En') {
return `${this.$g.monthMap[a[1]]} ${a[2]}, ${a[0]}, ${(a[3] % 12) || 12}:${a[4]} ${a[3] < 12 ? 'AM' : 'PM'}, ${sex === '男' ? 'Male' : 'Female'}`
} else {
return `${a[0]}${a[1]}${a[2]}${a[3]}${lang === 'Tc' ? '時' : '时'}${a[4]}${sex}`
}
},
// 是否显示头像,每个用户连续的记录,只显示第一个的头像
showAvatar(item, index) {
if (index === 0) return true
......
......@@ -56,7 +56,8 @@
this.$util.getUserInfo()
uni.showToast({ title: this.$t('Save Success') })
setTimeout(() => {
this.back()
// 重置所有页面
uni.reLaunch({ url: '/pages/user/user' })
}, 1000)
},
back() {
......
......@@ -108,17 +108,21 @@
openSex() {
this.$refs.sex.open()
},
changeSex(e) {
async changeSex(e) {
if (e.indexs[0] === this.sexIndex[0]) return
const val = Object.values(this.$g.sexMap)[e.indexs[0]]
this.save(Object.assign({}, this.x_user, { sex: val }))
await this.save(Object.assign({}, this.x_user, { sex: val }))
// 重置所有页面
uni.reLaunch({ url: '/pages/user/user' })
},
openBirth() {
this.$refs.birth.open()
},
changeBirth(e) {
async changeBirth(e) {
const val = this.$util.dateFormat(e.value, 'YYYY-MM-DD HH:mm')
this.save(Object.assign({}, this.x_user, { birthday: val }))
await this.save(Object.assign({}, this.x_user, { birthday: val }))
// 重置所有页面
uni.reLaunch({ url: '/pages/user/user' })
},
// 获取语言列表
getLocales() {
......@@ -143,7 +147,7 @@
async save(user) {
const res = await this.$api.userEdit(user)
if (!res) return
this.$util.getUserInfo()
await this.$util.getUserInfo()
},
// 页面跳转
go(url) {
......
......@@ -30,4 +30,19 @@ export default {
},
// mapbox的token
mapboxToken: 'pk.eyJ1IjoiYXJjYmxvY2siLCJhIjoiY2xvd2RkY2RyMGhkZDJxcW1rbW52cDFiaSJ9.Q1toKeWpNlhKQllsscB1Ag',
// 英文月份
monthMap: {
'01': 'January',
'02': 'February',
'03': 'March',
'04': 'April',
'05': 'May',
'06': 'June',
'07': 'July',
'08': 'August',
'09': 'September',
'10': 'October',
'11': 'November',
'12': 'December',
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment