From ea689dd91eaa72425dc01759042c3b4eb2186512 Mon Sep 17 00:00:00 2001
From: doum <doum>
Date: 星期三, 17 六月 2026 10:14:44 +0800
Subject: [PATCH] 新增智能电表、空调管理
---
h5/pages/login.vue | 147 +++++++++++++++++++++++++++++-------------------
1 files changed, 88 insertions(+), 59 deletions(-)
diff --git a/h5/pages/login.vue b/h5/pages/login.vue
index b742a89..a7ce852 100644
--- a/h5/pages/login.vue
+++ b/h5/pages/login.vue
@@ -2,6 +2,7 @@
<view class="login">
<view class="login_title">娆㈣繋鐧诲綍</view>
<view class="login_title login_title2">闃滃畞鏂囦綋涓績</view>
+ <view v-if="devMockTip" class="dev-tip">{{ devMockTip }}</view>
<view class="login_list">
<view class="login_list_item">
<image src="@/static/login_ic_phone@2x.png" mode="widthFix" />
@@ -29,8 +30,13 @@
loginPost,
getUserInfo,
sendSMsPost,
- ywWxAuthorize
+ ywWxAuthorize,
+
+ getRecordByUserPoint
} from '@/api'
+ import { devWechatMock } from '@/utils/config.js'
+ import { runWechatOAuthFlow } from '@/utils/wechatAuth.js'
+ import { requestLoginSmsCode } from '@/utils/loginSms.js'
import {
mapState,
mapMutations
@@ -44,36 +50,57 @@
phone: '',
code: ''
},
+ ywinfo: {},
downTime: 0,
- code: '111'
- // code: ''
+ code: '',
+ devMockTip: devWechatMock.enabled ? `寮�鍙戞ā寮忥細妯℃嫙 openid ${devWechatMock.openId}` : ''
}
},
-
+ onLoad(option) {
+ console.log('onLoad');
+ // https://zhcg.fnwtzx.com/#/pages/login?type=0&ywid=ywid
+ const ywinfo = uni.getStorageSync('ywinfo') || {}
+ if (ywinfo.ywid && (ywinfo.type || ywinfo.type == 0)) {
+ this.ywinfo = ywinfo
+ uni.setStorageSync('ywinfo', {})
+ }
+ if (option.ywid || option.ywid == 0) {
+ uni.setStorageSync('ywinfo', {
+ type: option.type,
+ ywid: option.ywid
+ })
+ }
+ },
onShow() {
- // return
- var that = this
- let url = window.location.href
- if (url.indexOf('code=') !== -1 || this.code) {
- let code = ''
- const query = url.split('?')
- for (const q of query) {
- if (q.indexOf('code=') !== -1) {
- let statusIndex = q.indexOf('&state')
- code = q.substring(q.indexOf('code=') + 5, statusIndex)
- }
- }
- ywWxAuthorize({
- code: code || this.code
- }).then(res => {
- if (res.code === 200) {
- console.log('res', res);
+ const that = this
+ runWechatOAuthFlow({
+ authorizeApi: ywWxAuthorize,
+ fallbackCode: this.code,
+ onSuccess: (res) => {
+ if (res.data.openid) {
that.$store.commit('setOpenId', res.data.openid)
- if (res.data.token && res.data.token != '') {
- that.$store.commit('setToken', res.data.token)
- getUserInfo().then(ress => {
- that.$store.commit('setUserInfo', ress.data)
+ }
+ if (res.data.token && res.data.token != '') {
+ that.$store.commit('setToken', res.data.token)
+ getUserInfo().then(ress => {
+ that.$store.commit('setUserInfo', ress.data)
+ })
+ const ywinfo = this.ywinfo
+ if (ywinfo.ywid && (ywinfo.type || ywinfo.type == 0)) {
+ getRecordByUserPoint({
+ pointCode: ywinfo.ywid
+ }).then(res => {
+ if (res.data && res.data.id) {
+ uni.redirectTo({
+ url: "/pages/polling/point?id=" + res.data.id
+ })
+ } else {
+ uni.redirectTo({
+ url: "/pages/polling/empty?message=" + res.message
+ })
+ }
})
+ } else {
setTimeout(() => {
uni.redirectTo({
url: "/pages/index"
@@ -81,23 +108,9 @@
}, 300)
}
}
- })
- } else {
- let url = 'https://zhcg.fnwtzx.com/yunwei_h5'
- const appID = 'wx95ac1efb67f0330d'
- let uri = encodeURIComponent(url)
- let authURL =
- `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appID}&redirect_uri=${uri}&response_type=code&scope=snsapi_base#wechat_redirect`
- window.location.href = authURL
- }
-
+ }
+ })
},
- // onBackPress(options) {
- // uni.redirectTo({
- // url: '/pages/login/login'
- // })
- // return true
- // },
methods: {
...mapMutations(["setToken", "setUserInfo"]),
onLogin() {
@@ -123,9 +136,28 @@
this.showToast('鐧诲綍鎴愬姛')
getUserInfo().then(ress => {
this.setUserInfo(ress.data)
- uni.redirectTo({
- url: "/pages/index"
- })
+ const ywinfo = this.ywinfo
+ if (ywinfo.ywid && (ywinfo.type || ywinfo.type == 0)) {
+ // getRecordByUserPoint({pointCode: ywinfo.ywid}).then(res => {
+ getRecordByUserPoint({
+ pointCode: ywinfo.ywid
+ }).then(res => {
+ if (res.data && res.data.id) {
+ uni.redirectTo({
+ url: "/pages/polling/point?id=" + res.data.id
+ })
+ } else {
+ uni.redirectTo({
+ url: "/pages/polling/empty?message=" + res.message
+ })
+ }
+ })
+ // })
+ } else {
+ uni.redirectTo({
+ url: "/pages/index"
+ })
+ }
})
}
})
@@ -134,20 +166,7 @@
},
sendSms() {
- this.downTime = 60
- let timer = setInterval(() => {
- if (this.downTime == 0) return clearInterval(timer)
- this.downTime = this.downTime - 1
- }, 1000)
- const {
- form
- } = this
- sendSMsPost({
- phone: form.phone,
- type: 0
- }).then(res => {
- this.showToast('鐭俊鍙戦�佹垚鍔�')
- })
+ requestLoginSmsCode(this, this.form.phone, sendSMsPost, { phone: this.form.phone, userType: 0 })
},
}
}
@@ -175,7 +194,17 @@
.login_title2 {
margin-top: 10rpx;
- margin-bottom: 80rpx;
+ margin-bottom: 40rpx;
+ }
+
+ .dev-tip {
+ width: 100%;
+ padding: 0 60rpx;
+ box-sizing: border-box;
+ font-size: 24rpx;
+ color: #e6a23c;
+ margin-bottom: 40rpx;
+ line-height: 1.5;
}
.login_list {
--
Gitblit v1.9.3