diff --git a/xuan-deduct-uniapp/src/pages/auth/auth.vue b/xuan-deduct-uniapp/src/pages/auth/auth.vue index 34983d5..bbbd02a 100644 --- a/xuan-deduct-uniapp/src/pages/auth/auth.vue +++ b/xuan-deduct-uniapp/src/pages/auth/auth.vue @@ -1,34 +1,29 @@ @@ -41,28 +36,39 @@ export default { return { avatarUrl: '', nickname: '', - loading: false, - defaultAvatar: '/static/default-avatar.png' - } - }, - computed: { - canSubmit() { - return this.avatarUrl && this.nickname + loading: false } }, methods: { onChooseAvatar(e) { + console.log('选择头像:', e) const { avatarUrl } = e.detail if (avatarUrl) { this.avatarUrl = avatarUrl + this.showNicknameInput() } }, - onNicknameInput(e) { - const value = e.detail.value - if (value) { - this.nickname = value - } + showNicknameInput() { + uni.showModal({ + title: '设置昵称', + editable: true, + placeholderText: '请输入昵称', + success: (res) => { + if (res.confirm && res.content) { + this.nickname = res.content + this.doAuth() + } else if (res.confirm) { + uni.showToast({ + title: '请输入昵称', + icon: 'none' + }) + setTimeout(() => { + this.showNicknameInput() + }, 1500) + } + } + }) }, async doAuth() { @@ -80,13 +86,18 @@ export default { try { const loginRes = await new Promise((resolve, reject) => { - uni.login({ success: resolve, fail: reject }) + uni.login({ + success: resolve, + fail: reject + }) }) if (!loginRes.code) { throw new Error('获取授权失败') } + console.log('获取code成功:', loginRes.code) + const res = await api.userApi.loginOrRegister({ code: loginRes.code, nickname: this.nickname, @@ -94,6 +105,8 @@ export default { }) if (res.success) { + console.log('登录成功:', res.data) + uni.setStorageSync('userId', res.data.userId) uni.setStorageSync('userInfo', JSON.stringify(res.data)) uni.setStorageSync('userCoins', res.data.coins || 10) @@ -101,29 +114,38 @@ export default { uni.setStorageSync('username', res.data.username || res.data.nickname) uni.setStorageSync('userAvatar', res.data.avatarUrl) - uni.showToast({ title: '授权成功', icon: 'success' }) + uni.showToast({ + title: '授权成功', + icon: 'success', + duration: 2000 + }) setTimeout(() => { uni.switchTab({ url: '/pages/index/index' }) - }, 1500) + }, 2000) } else { throw new Error(res.error || '登录失败') } } catch (err) { - uni.showToast({ title: err.message || '授权失败', icon: 'none' }) + console.error('登录失败:', err) + uni.showToast({ + title: err.message || '授权失败,请重试', + icon: 'none', + duration: 3000 + }) } finally { this.loading = false } }, - skipAuth() { + cancelAuth() { uni.showModal({ title: '提示', - content: '暂不授权将无法使用完整功能', - confirmText: '去授权', - cancelText: '稍后再说', + content: '取消登录将无法使用完整功能,确定要取消吗?', + confirmText: '确定取消', + cancelText: '继续登录', success: (res) => { - if (res.cancel) { + if (res.confirm) { uni.switchTab({ url: '/pages/index/index' }) } } @@ -135,123 +157,127 @@ export default {