diff --git a/components/FunctionCard.vue b/components/FunctionCard.vue index fc9da54..2ae53c8 100644 --- a/components/FunctionCard.vue +++ b/components/FunctionCard.vue @@ -45,11 +45,13 @@ 资产套餐历史 - + 绑定手机号 - 绑定手机号 + + {{ alreadyBindPhone ? '已绑定' : '绑定手机号' }} + @@ -94,13 +96,22 @@ \ No newline at end of file diff --git a/pages/device-exchange/device-exchange.vue b/pages/device-exchange/device-exchange.vue index 2390531..af0d074 100644 --- a/pages/device-exchange/device-exchange.vue +++ b/pages/device-exchange/device-exchange.vue @@ -125,6 +125,14 @@ uni.showToast({ title: '请输入收件人电话', icon: 'none' }); return; } + + // 手机号格式校验 + const phoneReg = /^1[3-9]\d{9}$/; + if (!phoneReg.test(form.recipient_phone)) { + uni.showToast({ title: '请输入正确的手机号', icon: 'none' }); + return; + } + if (!form.recipient_address) { uni.showToast({ title: '请输入收货地址', icon: 'none' }); return; diff --git a/pages/index/index.vue b/pages/index/index.vue index 48e5f4d..d69973e 100644 --- a/pages/index/index.vue +++ b/pages/index/index.vue @@ -320,15 +320,85 @@ showModifyWifi.value = false; }; - const connectKF = () => uni.showToast({ - title: '正在跳转客服', - icon: 'none' - }); + const connectKF = () => { + const kfUrl = 'https://work.weixin.qq.com/kfid/kfc0fd79f27686fb65e?enc_scene=ENCfR9AVui6UfvvxySGVuvaG&scene_param=commonlink'; - const enterBack = () => uni.showToast({ - title: '正在跳转后台', - icon: 'none' - }); + // #ifdef H5 + window.location.href = kfUrl; + // #endif + + // #ifdef MP-WEIXIN + // 微信小程序跳转到企业微信客服 + wx.openCustomerServiceChat({ + extInfo: { url: kfUrl }, + corpId: 'ww4e3b7f9f7c8a9b0c', + success: () => { + console.log('打开客服会话成功'); + }, + fail: (err) => { + console.error('打开客服会话失败', err); + // 失败时使用网页跳转 + uni.navigateTo({ + url: `/pages/webview/webview?url=${encodeURIComponent(kfUrl)}` + }); + } + }); + // #endif + + // #ifndef H5 || MP-WEIXIN + // 其他平台,复制链接 + uni.showModal({ + title: '联系客服', + content: '是否复制客服链接?', + confirmText: '复制', + success: (res) => { + if (res.confirm) { + uni.setClipboardData({ + data: kfUrl, + success: () => { + uni.showToast({ title: '客服链接已复制', icon: 'success' }); + } + }); + } + } + }); + // #endif + }; + + const enterBack = () => { + if (!deviceInfo.lan_ip || deviceInfo.lan_ip === '-') { + uni.showToast({ + title: '暂无后台地址', + icon: 'none' + }); + return; + } + + // 跳转到设备后台管理地址 + const url = deviceInfo.lan_ip.startsWith('http') ? deviceInfo.lan_ip : `http://${deviceInfo.lan_ip}`; + + // #ifdef H5 + window.location.href = url; + // #endif + + // #ifndef H5 + uni.showModal({ + title: '后台地址', + content: url, + confirmText: '复制', + success: (res) => { + if (res.confirm) { + uni.setClipboardData({ + data: url, + success: () => { + uni.showToast({ title: '地址已复制', icon: 'success' }); + } + }); + } + } + }); + // #endif + }; const YesRestart = async () => { try { @@ -496,11 +566,62 @@ showSmsCode.value = false; }; - const onSync = () => { - uni.showToast({ - title: '同步成功', - icon: 'success' + const onSync = async () => { + const identifier = userStore.state.identifier; + if (!identifier) { + uni.showToast({ + title: '请先登录', + icon: 'none' + }); + return; + } + + uni.showLoading({ + title: '同步中...', + mask: true }); + + try { + const data = await assetApi.refresh(identifier); + + uni.hideLoading(); + + if (data.accepted) { + const refreshTypeText = data.refresh_type === 'device' ? '设备' : '卡'; + uni.showToast({ + title: `${refreshTypeText}数据同步成功`, + icon: 'success', + duration: 2000 + }); + + // 同步成功后,延迟重新加载资产信息 + setTimeout(() => { + loadAssetInfo(); + }, 2000); + } else { + uni.showToast({ + title: '同步失败,请稍后重试', + icon: 'none' + }); + } + } catch (e) { + uni.hideLoading(); + console.error('同步数据失败', e); + + // 如果是冷却时间错误,显示提示 + if (e.msg && e.msg.includes('冷却')) { + uni.showToast({ + title: e.msg, + icon: 'none', + duration: 2000 + }); + } else { + uni.showToast({ + title: '同步失败', + icon: 'none' + }); + } + } }; const enterDetail = (name) => { diff --git a/pages/login/login.vue b/pages/login/login.vue index e7d6aad..a883b7d 100644 --- a/pages/login/login.vue +++ b/pages/login/login.vue @@ -98,7 +98,13 @@ const loginData = await authApi.wechatLogin(verifyData.asset_token, 'mock_code'); userStore.setToken(loginData.token); uni.setStorageSync('identifier', userStore.state.identifier); - uni.redirectTo({ url: '/pages/index/index' }); + + // 判断是否需要绑定手机号 + if (loginData.need_bind_phone) { + uni.redirectTo({ url: '/pages/bind/bind?fromLogin=true' }); + } else { + uni.redirectTo({ url: '/pages/index/index' }); + } return; } @@ -123,9 +129,16 @@ try { const loginData = await authApi.wechatLogin(assetToken, code); userStore.setToken(loginData.token); - uni.setStorageSync('identifier', userStore.state.identifier); - uni.redirectTo({ url: '/pages/index/index' }); + + // 判断是否需要绑定手机号 + if (loginData.need_bind_phone) { + // 需要绑定手机号,跳转到绑定页面 + uni.redirectTo({ url: '/pages/bind/bind?fromLogin=true' }); + } else { + // 不需要绑定,直接进入首页 + uni.redirectTo({ url: '/pages/index/index' }); + } } catch (e) { console.error('微信登录失败', e); loading.value = false;