Commit 361f6a685d5abbba26f901166d86861e3ddcded2

Authored by 陈威
1 parent 2e502136
Exists in dev

微信公众号,功能优化

frontend/app-user/pages/code.vue
1 1 <template>
2   - <view class="container">
3   - <Navbar canBack></Navbar>
4   - <view class="auth-header">
5   - <view class="auth-logo">
6   - <u-image width="80px" height="80px" src="@/static/lpg-logo.png"></u-image>
7   - </view>
8   - </view>
9   - <view class="loginTitleCss flex flex-direction">
10   - <view class="text-xxl text-bold">
11   - <!-- 账号密码登录 -->
12   - {{accountTile || ""}}
13   - </view>
14   - <view class="margin-top-sm text-gray">
15   - {{accountTip || ""}}{{ formData.phone || ""}}
16   - <!-- 未注册手机号登录后自动生成账号 -->
17   - </view>
18   - </view>
19   - <view class="auth-box">
20   - <view class="margin-top-sm">
21   - <u-code-input v-model="formData.sms" adjustPosition :maxlength="6" mode="line"></u-code-input>
22   - </view>
23   - <view class="flex w100 justify-end">
24   - <view class="btn-group">
25   - <u-button class="auth-btn" shape="circle" :disabled="!formData.sms.length === 6"
26   - :style="{background:formData.sms.length === 6?'#EA5504':'#D5D8DF'}"
27   - @click="handleSubmit">{{btnText}}</u-button>
28   - </view>
29   - </view>
30   - </u--form>
31   - </view>
32   - </view>
  2 + <view class="container">
  3 + <Navbar canBack></Navbar>
  4 + <view class="auth-header">
  5 + <view class="auth-logo">
  6 + <u-image width="80px" height="80px" src="@/static/lpg-logo.png"></u-image>
  7 + </view>
  8 + </view>
  9 + <view class="loginTitleCss flex flex-direction">
  10 + <view class="text-xxl text-bold">
  11 + <!-- 账号密码登录 -->
  12 + {{ accountTile || "" }}
  13 + </view>
  14 + <view class="margin-top-sm text-gray">
  15 + {{ accountTip || "" }}{{ formData.phone || "" }}
  16 + <!-- 未注册手机号登录后自动生成账号 -->
  17 + </view>
  18 + </view>
  19 + <view class="auth-box">
  20 + <view class="margin-top-sm">
  21 + <u-code-input v-model="formData.sms" adjustPosition :maxlength="6" mode="line"></u-code-input>
  22 + </view>
  23 + <view class="flex w100 justify-end">
  24 + <view class="btn-group">
  25 + <u-button class="auth-btn" shape="circle" :disabled="!formData.sms.length === 6"
  26 + :style="{background:formData.sms.length === 6?'#EA5504':'#D5D8DF'}"
  27 + @click="handleSubmit">{{ btnText }}
  28 + </u-button>
  29 + </view>
  30 + </view>
  31 + </u--form>
  32 + </view>
  33 + </view>
33 34 </template>
34 35  
35 36 <script>
36   - import {
37   - sendSmsCode
38   - } from '@/api/auth.js'
  37 +import {
  38 + sendSmsCode
  39 +} from '@/api/auth.js'
39 40  
40   - export default {
41   - data() {
42   - return {
43   - inputType: 'password',
44   - codeDisabled: false,
45   - currentMode: 0,
46   - codeTips: '',
47   - formData: {
48   - phone: "",
49   - sms: '',
50   - yhlx:'hy'
51   - },
52   - btnText: "登录",
53   - checkValue: [],
54   - accountTile: "请输入验证码",
55   - accountTip: "验证码已发送至",
56   - accountPlaceholder: "请输入手机号"
57   - }
58   - },
59   - onLoad(data) {
60   - if (data.mobile) {
61   - this.formData.phone = data.mobile;
62   - }
63   - if (data.mode) {
64   - this.currentMode = parseInt(data.mode);
65   - this.btnText = this.currentMode === 3 ? "下一步" : '登录';
66   - }
67   - },
68   - methods: {
69   - handleSubmit() {
70   - console.log("验证码登录", this.formData.sms);
71   - let that = this;
72   - if (this.formData.sms.length === 6) {
73   - if (this.currentMode === 3) {
74   - console.log("跳转忘记密码页");
75   - uni.navigateTo({
76   - url: `/pages/forgotPassword?account=${that.formData.phone}&sms=${that.formData.sms}`
77   - })
78   - } else {
79   - this.$store.dispatch('codeLogin', this.formData).then(res => {
80   - setTimeout(() => {
81   - uni.$u.toast('登录成功')
82   - uni.switchTab({
83   - url: '/pages/home/home'
84   - })
85   - }, 300)
86   - }).catch((e) => {
87   - console.log("登录失败", e);
88   - if (e.code === 500 && e.msg === '该手机号未注册') {
89   - let option = {
90   - confirmText: "立即注册",
91   - }
92   - console.log("注册数据",that.formData);
93   - this.$modal.confirm('是否注册该账号?', '未注册',option).then(() => {
94   - this.$store.dispatch('Register', that.formData).then(res => {
95   - console.log("注册结果",res);
96   - uni.$u.toast('注册成功');
97   - setTimeout(() => {
98   - uni.switchTab({
99   - url: '/pages/home/home'
100   - })
101   - },1000)
102   - })
103   - }).catch(() => {
104   - console.log("取消");
105   - });
106   - }else{
107   - uni.$u.toast(e.msg);
108   - }
109   - })
110   - }
  41 +export default {
  42 + data() {
  43 + return {
  44 + inputType: 'password',
  45 + codeDisabled: false,
  46 + currentMode: 0,
  47 + codeTips: '',
  48 + formData: {
  49 + phone: "",
  50 + sms: '',
  51 + yhlx: 'hy'
  52 + },
  53 + btnText: "登录",
  54 + checkValue: [],
  55 + accountTile: "请输入验证码",
  56 + accountTip: "验证码已发送至",
  57 + accountPlaceholder: "请输入手机号"
  58 + }
  59 + },
  60 + onLoad(data) {
  61 + if (data.mobile) {
  62 + this.formData.phone = data.mobile;
  63 + }
  64 + if (data.mode) {
  65 + this.currentMode = parseInt(data.mode);
  66 + this.btnText = this.currentMode === 3 ? "下一步" : '登录';
  67 + }
  68 + },
  69 + methods: {
  70 + handleSubmit() {
  71 + console.log("验证码登录", this.formData.sms);
  72 + let that = this;
  73 + if (this.formData.sms.length === 6) {
  74 + if (this.currentMode === 3) {
  75 + console.log("跳转忘记密码页");
  76 + uni.navigateTo({
  77 + url: `/pages/forgotPassword?account=${that.formData.phone}&sms=${that.formData.sms}`
  78 + })
  79 + } else {
  80 + this.$store.dispatch('codeLogin', this.formData).then(res => {
  81 + this.hasOpenId();
  82 + setTimeout(() => {
  83 + uni.$u.toast('登录成功')
  84 + uni.switchTab({
  85 + url: '/pages/home/home'
  86 + })
  87 + }, 300)
  88 + }).catch((e) => {
  89 + console.log("登录失败", e);
  90 + if (e.code === 500 && e.msg === '该手机号未注册') {
  91 + let option = {
  92 + confirmText: "立即注册",
  93 + }
  94 + console.log("注册数据", that.formData);
  95 + this.$modal.confirm('是否注册该账号?', '未注册', option).then(() => {
  96 + this.$store.dispatch('Register', that.formData).then(res => {
  97 + console.log("注册结果", res);
  98 + uni.$u.toast('注册成功');
  99 + setTimeout(() => {
  100 + uni.switchTab({
  101 + url: '/pages/home/home'
  102 + })
  103 + }, 1000)
  104 + })
  105 + }).catch(() => {
  106 + console.log("取消");
  107 + });
  108 + } else {
  109 + uni.$u.toast(e.msg);
  110 + }
  111 + })
  112 + }
111 113  
112   - }
113   - },
114   - }
115   - }
  114 + }
  115 + },
  116 + //是否有openid
  117 + hasOpenId() {
  118 + let openId = uni.getStorageSync('openId');
  119 + console.log("openid----------------->",openId)
  120 + if (openId) {
  121 + this.$api.loginApi.bindOpenId({
  122 + account: this.formData.phone,
  123 + openId: openId
  124 + });
  125 + }
  126 + }
  127 + }
  128 +}
116 129 </script>
117 130  
118 131 <style lang="scss" scoped>
119   - .container {
120   - background: #fff;
121   - height: 100vh;
122   - }
  132 +.container {
  133 + background: #fff;
  134 + height: 100vh;
  135 +}
123 136  
124   - .auth-header {
125   - width: 100%;
126   - height: 200rpx;
  137 +.auth-header {
  138 + width: 100%;
  139 + height: 200 rpx;
127 140  
128   - .auth-logo {
129   - margin: 40px 0 0 40px;
130   - }
131   - }
  141 + .auth-logo {
  142 + margin: 40px 0 0 40px;
  143 + }
  144 +}
132 145  
133   - .auth-box {
134   - margin: 0 40px;
  146 +.auth-box {
  147 + margin: 0 40px;
135 148  
136   - .btn-group {
137   - height: 100px;
138   - width: 120px;
139   - display: flex;
140   - justify-content: flex-end;
141   - align-items: center;
  149 + .btn-group {
  150 + height: 100px;
  151 + width: 120px;
  152 + display: flex;
  153 + justify-content: flex-end;
  154 + align-items: center;
142 155  
143   - .auth-btn {
144   - color: #fff;
145   - height: 90rpx;
146   - font-size: 32rpx;
147   - }
148   - }
149   - }
  156 + .auth-btn {
  157 + color: #fff;
  158 + height: 90 rpx;
  159 + font-size: 32 rpx;
  160 + }
  161 + }
  162 +}
150 163  
151   - .radioCss {
152   - margin-top: 2px;
153   - }
  164 +.radioCss {
  165 + margin-top: 2px;
  166 +}
154 167  
155   - .loginTitleCss {
156   - margin: 0 40px;
157   - }
  168 +.loginTitleCss {
  169 + margin: 0 40px;
  170 +}
158 171  
159   - /deep/.u-form-item__body__right__message {
160   - margin-left: 0px !important;
161   - }
162   -</style>
163 172 \ No newline at end of file
  173 +/deep/ .u-form-item__body__right__message {
  174 + margin-left: 0px !important;
  175 +}
  176 +</style>
... ...
frontend/app-user/pages/jump/weChatOffAcc.vue
1 1 <template>
2   - <view class="container">
3   - <div>微信公众号-授权认证中</div>
4   - </view>
  2 + <view class="container">
  3 + <div>微信公众号-授权认证中</div>
  4 + </view>
5 5 </template>
6 6  
7 7 <script>
8   - const {
9   - Base64
10   - } = require('js-base64');
11   - export default {
12   - data() {
13   - return {
14   - currentModeIndex: 2, //1账号密码 2验证码 3忘记密码
15   - inputType: 'password',
16   - codeDisabled: false,
17   - codeTips: '',
18   - formData: {
19   - mobile: '',
20   - password: '',
21   - },
22   - flag: true,
23   - rules: {
24   - mobile: [{
25   - type: 'string',
26   - required: true,
27   - message: '请输入手机号',
28   - trigger: ['blur', 'change']
29   - },
30   - // {
31   - // // 自定义验证函数,见上说明
32   - // validator: (rule, value, callback) => {
33   - // // 上面有说,返回true表示校验通过,返回false表示不通过
34   - // // uni.$u.test.mobile()就是返回true或者false的
35   - // return uni.$u.test.mobile(value)
36   - // },
37   - // message: '手机号码不正确',
38   - // // 触发器可以同时用blur和change
39   - // trigger: ['change', 'blur']
40   - // }
41   - ],
42   - password: {
43   - type: 'string',
44   - min: 4,
45   - max: 16,
46   - required: true,
47   - message: '密码长度4-16位密码',
48   - trigger: ['blur', 'change']
49   - },
50   - code: {
51   - type: 'integer',
52   - len: 4,
53   - required: true,
54   - message: '请填写4位验证码',
55   - trigger: ['blur', 'change']
56   - }
57   - },
58   - isAutoLogin: [], //是否自动登录
59   - hasForgot: false, //忘记密码
60   - loginText: "短信登录",
61   - btnText: "发送验证码",
62   - checkValue: ['agree'],
63   - accountTile: "短信验证码登录",
64   - accountTip: "未注册手机号登录后自动生成账号",
65   - accountPlaceholder: "请输入手机号",
66   - appid: this.$config.appid,
67   - openId: null
68   - }
69   - },
70   - created() {
71   - this.handleAuthorization();
72   - },
73   - methods: {
74   - handleAuthorization() {
75   - console.log("================================");
76   - this.code = "";
77   - console.log("window.location.href", window.location.href);
78   - let local = window.location.href;
79   - console.log("local", local);
80   - let scope = "snsapi_base"; //静默授权 用户无感知
81   - console.log("this.scope", scope);
82   - this.code = this.getParameters('code');
83   - console.log("this.code", this.code);
84   -
85   - // 本地调试可用 设置好地址后无需重定向
86   - // let jumpToUri =
87   - // `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${this.$config.appid}&redirect_uri=${encodeURIComponent(local)}&response_type=code&scope=${scope}&state=hotent#wechat_redirect`
88   - // console.log("jumpToUri", jumpToUri);
89   - // if (this.code == null || this.code === "") {
90   - // window.location.href = jumpToUri;
91   - // } else {
92   - // this.getOpenId(this.code);
93   - // }
94   -
95   - this.getOpenId(this.code);
96   - console.log("================================");
97   - },
98   - getOpenId(code) {
99   - let that = this;
100   - this.$api.loginApi.getWechatOpenId(code).then(res => {
101   - console.log("res", res);
102   - if (res.openid) {
103   - that.openId = res.openid;
104   - //首次登录未绑定账号去登录页登录后触发绑定
105   - console.log("获取openId", that.openId);
106   - uni.setStorageSync('openId', this.openId)
107   - uni.navigateTo({
108   - url:'/pages/login'
109   - })
110   - } else {
111   - //已经绑定直接缓存token 跳转到主页
112   - this.$store.dispatch('wxAuthLogin', res).then(e => {
113   - uni.switchTab({
114   - url: '/pages/home/home'
115   - });
116   - }).catch(err => {
117   - uni.$u.toast(err)
118   - })
119   - }
120   - });
121   - },
122   - getUrlCode() {
123   - let fullUrl = window.location.href;
124   - console.log("fullUrl ", fullUrl);
125   - let theRequest = new Object();
126   - if (fullUrl.indexOf("?") != -1) {
127   - var temp = fullUrl.split("?");
128   - let str = temp[1];
129   - let strs = str.split("&");
130   - for (var i = 0; i < strs.length; i++) {
131   - theRequest[strs[i].split("=")[0]] = strs[i].split("=")[1];
132   - }
133   - }
134   - return theRequest;
135   - },
136   - //获取url中的参数
137   - getParameters(name) {
138   - var locUrl = decodeURI(window.location.search.substr(1))
139   - var aryParams = locUrl.split('&')
140   - var rtn = ''
141   - for (var i = 0; i < aryParams.length; i++) {
142   - var pair = aryParams[i]
143   - var aryEnt = pair.split('=')
144   - var key = aryEnt[0]
145   - var val = aryEnt[1]
146   - if (key != name) continue
147   - if (rtn == '') {
148   - rtn = val
149   - } else {
150   - rtn += ',' + val
151   - }
152   - }
153   - return rtn
154   - },
155   - },
156   - };
  8 +const {Base64} = require('js-base64');
  9 +export default {
  10 + data() {
  11 + return {
  12 + openId: null,
  13 + code: null
  14 + }
  15 + },
  16 + created() {
  17 + this.handleAuthorization();
  18 + },
  19 + methods: {
  20 + handleAuthorization() {
  21 + this.code = this.getParameters('code');
  22 + this.getOpenId(this.code);
  23 + },
  24 + getOpenId(code) {
  25 + let that = this;
  26 + this.$api.loginApi.getWechatOpenId(code).then(res => {
  27 + console.log("res", res);
  28 + if (res.openid) {
  29 + that.openId = res.openid;
  30 + //首次登录未绑定账号去登录页登录后触发绑定
  31 + console.log("获取openId", that.openId);
  32 + uni.setStorageSync('openId', this.openId)
  33 + uni.navigateTo({
  34 + url: '/pages/login'
  35 + })
  36 + } else {
  37 + //已经绑定直接缓存token 跳转到主页
  38 + this.$store.dispatch('wxAuthLogin', res).then(e => {
  39 + uni.switchTab({
  40 + url: '/pages/home/home'
  41 + });
  42 + }).catch(err => {
  43 + uni.$u.toast(err)
  44 + })
  45 + }
  46 + });
  47 + },
  48 + //获取url中的参数
  49 + getParameters(name) {
  50 + var locUrl = decodeURI(window.location.search.substr(1))
  51 + var aryParams = locUrl.split('&')
  52 + var rtn = ''
  53 + for (var i = 0; i < aryParams.length; i++) {
  54 + var pair = aryParams[i]
  55 + var aryEnt = pair.split('=')
  56 + var key = aryEnt[0]
  57 + var val = aryEnt[1]
  58 + if (key != name) continue
  59 + if (rtn == '') {
  60 + rtn = val
  61 + } else {
  62 + rtn += ',' + val
  63 + }
  64 + }
  65 + return rtn
  66 + },
  67 + },
  68 +};
157 69 </script>
158 70  
159 71 <style lang="scss" scoped>
160   - .container {
161   - display: flex;
162   - justify-content: center;
163   - align-items: center;
164   - height: 100vh;
165   - }
166   -</style>
167 72 \ No newline at end of file
  73 +.container {
  74 + display: flex;
  75 + justify-content: center;
  76 + align-items: center;
  77 + height: 100vh;
  78 +}
  79 +</style>
... ...
frontend/app-user/pages/login.vue
... ... @@ -52,7 +52,7 @@
52 52 placeholder="请填写验证码"></u--input>
53 53 <u-button slot="right" @tap="getCode" :text="codeTips" type="success" size="mini"
54 54 :disabled="codeDisabled"></u-button>
55   -
  55 +
56 56 </u-form-item> -->
57 57 <view class="flex align-start margin-top" v-if="!hasForgot">
58 58 <view class="radioCss">
... ... @@ -195,13 +195,13 @@
195 195 let isWechatBrowser = this.isWechatBrowser();
196 196 this.openId = uni.getStorageSync("openId");
197 197 console.log("openId", this.openId);
198   - if (isWechatBrowser) {
199   - if (!this.openId) {
200   - uni.reLaunch({
201   - url: '/pages/jump/weChatOffAcc'
202   - })
203   - }
204   - }
  198 + // if (isWechatBrowser) {
  199 + // if (!this.openId) {
  200 + // uni.reLaunch({
  201 + // url: '/pages/jump/weChatOffAcc'
  202 + // })
  203 + // }
  204 + // }
205 205 },
206 206 onReady() {
207 207 // 如果需要兼容微信小程序,并且校验规则中含有方法等,只能通过setRules方法设置规则
... ... @@ -214,7 +214,7 @@
214 214 console.log("有openid", this.openId);
215 215 if (this.openId) {
216 216 this.bindWxOffAcc(this.openId)
217   - // 默认静默绑定
  217 + // 默认静默绑定
218 218 // this.$modal.confirm('是否绑定公众号,以便下次免登录', '温馨提示', )
219 219 // .then(() => {
220 220 // this.bindWxOffAcc(this.openId)
... ... @@ -235,10 +235,10 @@
235 235 }).then((res) => {
236 236 if (res.state) {
237 237 // 绑定成功
238   - uni.removeStorageSync('openId');
239   - uni.switchTab({
240   - url: '/pages/home/home'
241   - });
  238 + // uni.removeStorageSync('openId');
  239 + // uni.switchTab({
  240 + // url: '/pages/home/home'
  241 + // });
242 242 }
243 243 })
244 244 },
... ... @@ -409,7 +409,11 @@
409 409 uni.setStorageSync('myAvatorImg', '');
410 410 // 只在微信浏览器环境生效并去绑定openid
411 411 if (this.isWechatBrowser()) {
412   - this.hasOpenId();
  412 + // 非微信环境登录直接进入主页
  413 + this.hasOpenId();
  414 + uni.switchTab({
  415 + url: '/pages/home/home'
  416 + });
413 417 }else{
414 418 // 非微信环境登录直接进入主页
415 419 uni.switchTab({
... ... @@ -469,4 +473,4 @@
469 473 /deep/.u-form-item__body__right__message {
470 474 margin-left: 0px !important;
471 475 }
472   -</style>
473 476 \ No newline at end of file
  477 +</style>
... ...