Initial commit
This commit is contained in:
@@ -119,23 +119,12 @@ export const asyncRoutes = [
|
||||
meta: { title: '教学中心', icon: 'user' }
|
||||
},
|
||||
{
|
||||
path: 'coupons',
|
||||
name: 'Coupons',
|
||||
component: () => import('@/views/crm/coupon'),
|
||||
meta: { title: '优惠券管理', icon: 'money' }
|
||||
},
|
||||
{
|
||||
path: 'issued-coupons',
|
||||
name: 'IssuedCoupons',
|
||||
component: () => import('@/views/crm/issued_coupon'),
|
||||
meta: { title: '已发优惠券', icon: 'list' }
|
||||
},
|
||||
{
|
||||
path: 'banners',
|
||||
name: 'Banners',
|
||||
component: () => import('@/views/crm/banner'),
|
||||
meta: { title: '轮播图管理', icon: 'drag' }
|
||||
},
|
||||
path: 'users',
|
||||
name: 'CrmUsers',
|
||||
component: () => import('@/views/crm/index'),
|
||||
redirect: '/crm/users/students',
|
||||
meta: { title: '用户管理', icon: 'peoples' },
|
||||
children: [
|
||||
{
|
||||
path: 'students',
|
||||
name: 'Students',
|
||||
@@ -147,6 +136,35 @@ export const asyncRoutes = [
|
||||
name: 'Honors',
|
||||
component: () => import('@/views/crm/honor'),
|
||||
meta: { title: '学员荣誉管理', icon: 'medal' }
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
path: 'coupon-manage',
|
||||
name: 'CouponManage',
|
||||
component: () => import('@/views/crm/index'),
|
||||
redirect: '/crm/coupon-manage/settings',
|
||||
meta: { title: '优惠券管理', icon: 'money' },
|
||||
children: [
|
||||
{
|
||||
path: 'settings',
|
||||
name: 'Coupons',
|
||||
component: () => import('@/views/crm/coupon'),
|
||||
meta: { title: '优惠券设置', icon: 'money' }
|
||||
},
|
||||
{
|
||||
path: 'issued',
|
||||
name: 'IssuedCoupons',
|
||||
component: () => import('@/views/crm/issued_coupon'),
|
||||
meta: { title: '已发优惠券', icon: 'list' }
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
path: 'banners',
|
||||
name: 'Banners',
|
||||
component: () => import('@/views/crm/banner'),
|
||||
meta: { title: '轮播图管理', icon: 'drag' }
|
||||
},
|
||||
{
|
||||
path: 'showcases',
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 2.4 KiB |
@@ -3,12 +3,20 @@ const app = getApp()
|
||||
Page({
|
||||
data: {
|
||||
coupons: [],
|
||||
user: {}
|
||||
user: {},
|
||||
loading: true
|
||||
},
|
||||
onLoad() {
|
||||
this.fetchCoupons();
|
||||
},
|
||||
onShow() {
|
||||
// Optimistically update from global data
|
||||
if (app.globalData.userInfo && app.globalData.userInfo.phone) {
|
||||
this.setData({
|
||||
user: app.globalData.userInfo,
|
||||
loading: false
|
||||
});
|
||||
}
|
||||
this.getUserInfo();
|
||||
this.fetchCoupons();
|
||||
},
|
||||
@@ -19,12 +27,14 @@ Page({
|
||||
// Fetch latest user info from backend to check if phone exists in DB
|
||||
request({ url: '/user/' }).then(user => {
|
||||
app.globalData.userInfo = user; // Sync global data
|
||||
this.setData({ user: user });
|
||||
this.setData({ user: user, loading: false });
|
||||
}).catch(err => {
|
||||
console.error('Failed to fetch user info', err)
|
||||
// Fallback to global data if fetch fails
|
||||
if (app.globalData.userInfo) {
|
||||
this.setData({ user: app.globalData.userInfo });
|
||||
this.setData({ user: app.globalData.userInfo, loading: false });
|
||||
} else {
|
||||
this.setData({ loading: false });
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
</view>
|
||||
|
||||
<!-- VIP Banner -->
|
||||
<view class="vip-banner" wx:if="{{!user.phone}}">
|
||||
<view class="vip-banner" wx:if="{{!loading && !user.phone}}">
|
||||
<view class="vip-info">
|
||||
<view class="vip-title">VIP会员权益</view>
|
||||
<view class="vip-desc">开通会员享受更多优惠</view>
|
||||
|
||||
@@ -3,7 +3,6 @@ const { request } = require('../../utils/request')
|
||||
|
||||
Page({
|
||||
data: {
|
||||
hasUserInfo: false,
|
||||
hasPhone: false
|
||||
},
|
||||
onLoad() {
|
||||
@@ -24,16 +23,14 @@ Page({
|
||||
// If we are here, user probably needs to authorize.
|
||||
|
||||
// Update UI state
|
||||
const hasNick = user.wechat_nickname && user.wechat_nickname !== '微信用户';
|
||||
const hasPhone = !!user.phone;
|
||||
|
||||
this.setData({
|
||||
hasUserInfo: hasNick,
|
||||
hasPhone: hasPhone
|
||||
})
|
||||
|
||||
// If somehow we ended up here but profile is full, go home
|
||||
if (hasNick && hasPhone) {
|
||||
if (hasPhone) {
|
||||
wx.switchTab({ url: '/pages/index/index' })
|
||||
}
|
||||
} else {
|
||||
@@ -46,46 +43,6 @@ Page({
|
||||
}
|
||||
}
|
||||
},
|
||||
getUserProfile(e) {
|
||||
wx.getUserProfile({
|
||||
desc: '用于完善会员资料',
|
||||
success: (res) => {
|
||||
const { userInfo } = res
|
||||
console.log('getUserProfile success', userInfo)
|
||||
|
||||
// Update backend
|
||||
// We need user ID from globalData
|
||||
if (app.globalData.userInfo && app.globalData.userInfo.id) {
|
||||
this.updateUserInfo(userInfo)
|
||||
} else {
|
||||
// Should not happen if app.js login succeeded
|
||||
wx.showToast({ title: '登录状态异常,请重启', icon: 'none' })
|
||||
}
|
||||
},
|
||||
fail: (err) => {
|
||||
console.error('getUserProfile failed', err)
|
||||
wx.showToast({ title: '需要授权才能继续', icon: 'none' })
|
||||
}
|
||||
})
|
||||
},
|
||||
updateUserInfo(wxUserInfo) {
|
||||
request({
|
||||
url: `/students/${app.globalData.userInfo.id}/`,
|
||||
method: 'PATCH',
|
||||
data: {
|
||||
wechat_nickname: wxUserInfo.nickName,
|
||||
avatar: wxUserInfo.avatarUrl
|
||||
// name: wxUserInfo.nickName // Optional: sync name too
|
||||
}
|
||||
}).then(res => {
|
||||
console.log('Update user info success', res)
|
||||
app.globalData.userInfo = { ...app.globalData.userInfo, ...res }
|
||||
this.setData({ hasUserInfo: true })
|
||||
}).catch(err => {
|
||||
console.error('Update user info failed', err)
|
||||
wx.showToast({ title: '更新资料失败', icon: 'none' })
|
||||
})
|
||||
},
|
||||
getPhoneNumber(e) {
|
||||
console.log('getPhoneNumber', e)
|
||||
if (e.detail.errMsg === 'getPhoneNumber:ok') {
|
||||
@@ -98,34 +55,16 @@ Page({
|
||||
}).then(res => {
|
||||
console.log('Get phone success', res)
|
||||
if (res.phone) {
|
||||
app.globalData.userInfo = { ...app.globalData.userInfo, ...res }
|
||||
this.setData({ hasPhone: true })
|
||||
if (app.globalData.userInfo) {
|
||||
app.globalData.userInfo.phone = res.phone
|
||||
}
|
||||
|
||||
wx.showToast({
|
||||
title: '登录成功',
|
||||
icon: 'success'
|
||||
})
|
||||
|
||||
// Redirect to home
|
||||
setTimeout(() => {
|
||||
wx.switchTab({ url: '/pages/index/index' })
|
||||
}, 1500)
|
||||
}
|
||||
}).catch(err => {
|
||||
console.error('Get phone failed', err)
|
||||
wx.showToast({ title: '获取手机号失败', icon: 'none' })
|
||||
})
|
||||
} else {
|
||||
console.log('User denied phone number')
|
||||
// If user denies, we can optionally let them in anyway if that's the requirement?
|
||||
// User said: "If openID exists, direct login".
|
||||
// This implies for NEW users, they MIGHT need to authorize phone.
|
||||
// But strictly speaking, once they authorized UserProfile (Avatar/Nick),
|
||||
// the OpenID exists.
|
||||
// But the "User Phone" part is usually critical.
|
||||
// Let's keep strict requirement for phone for NEW users for now unless asked otherwise.
|
||||
wx.showToast({ title: '需要授权手机号才能继续', icon: 'none' })
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -8,11 +8,7 @@
|
||||
<view class="content">
|
||||
<view class="tips">为了提供更好的服务,请授权以下信息</view>
|
||||
|
||||
<block wx:if="{{!hasUserInfo}}">
|
||||
<button class="btn-login" bindtap="getUserProfile">获取微信昵称</button>
|
||||
</block>
|
||||
|
||||
<block wx:if="{{hasUserInfo && !hasPhone}}">
|
||||
<block wx:if="{{!hasPhone}}">
|
||||
<button class="btn-login" open-type="getPhoneNumber" bindgetphonenumber="getPhoneNumber">获取手机号码</button>
|
||||
</block>
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@
|
||||
<view class="form-title-bar" bindtap="toggleForm">
|
||||
<view class="title-left">
|
||||
<image class="menu-icon" src="/assets/icons/profile-icon.png" mode="aspectFit"></image>
|
||||
<text class="form-title">个人信息</text>
|
||||
<text class="form-title">我的信息</text>
|
||||
</view>
|
||||
<text class="toggle-icon">{{isFormOpen ? '▲' : '▼'}}</text>
|
||||
</view>
|
||||
|
||||
Reference in New Issue
Block a user