绿满眶商城微信小程序-uniapp
zxl
4 天以前 c9928dd4f6d25e2339ea1400f59ec58674a927a7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<template>
  <view class="container">
    <u-navbar title="扫码登录授权"></u-navbar>
    <view class="wx-auth-container">
      <div class="box">
        <!-- <div v-if="!errorMsg"> -->
        <div>
          <view class="small-tips flex flex-center">
            <u-image
              width="400rpx"
              height="300rpx"
              src="https://lili-system.oss-cn-beijing.aliyuncs.com/confirm.png"
            ></u-image>
            <div>电脑端登录确认</div>
            <div>为确保帐号安全,请确认是您本人操作</div>
          </view>
 
          <view class="btns">
            <button @click="confirmLogin()" class="btn-auth">确认登录</button>
            <div @click="cancelLogin()" class="btn-callback">取消登录</div>
          </view>
        </div>
      </div>
    </view>
  </view>
</template>
 
<script>
import '@/components/uview-components/uview-ui'
import { scannerCodeLogin, scannerCodeLoginConfirm } from "@/api/login";
export default {
  data() {
    return {
      errorMsg: "",
      token: "",
    };
  },
  watch: {
    errorMsg(val) {
      if (val) {
        uni.showToast({
          title: val,
          icon: "none",
        });
        // uni.navigateBack()
      }
    },
  },
  onShow() {
    this.$options.filters.forceLogin();
    scannerCodeLogin({ token: this.token }).then((res) => {
      if (res.data.code == 200) {
        let code = res.data.result;
        switch (code) {
          case 0:
          case 1:
            this.errorMsg = "";
            break;
          case 2:
          case 3:
            this.errorMsg = "请勿重复扫码";
            break;
          case 4:
            this.errorMsg = "二维码已过期,重新扫码";
            break;
          default:
            this.errorMsg = "状态异常";
        }
      } else {
        this.errorMsg = res.data.message;
      }
    });
  },
  onLoad(params) {
    this.token = params.token;
    if (this.token == undefined || this.token == "") {
      this.errorMsg = "信息异常";
    }
  },
  methods: {
    confirmLogin() {
      this.config(1);
    },
    cancelLogin() {
      this.config(0);
    },
    config(code) {
      scannerCodeLoginConfirm({ token: this.token, code: code }).then((res) => {
        let title = res.data.success ? "操作成功" : "操作失败";
        uni.showToast({
          title: title,
          duration: 1500,
          icon: "none",
        });
        setTimeout(function () {
          uni.navigateBack();
        }, 1000);
      });
    },
  },
};
</script>
<style lang="scss" scoped>
page {
  background: #fff;
}
</style>
<style lang="scss" scoped>
.container {
  background-color: #fff;
  width: 100vw;
  height: 100vh;
}
.wx-auth-container {
  width: 100%;
  background: #fff;
  margin-top: 20%;
}
text.title,
text.shop {
  display: inline-block;
  font-size: 60rpx;
  color: #333;
}
 
.box {
  margin: 0 32rpx;
}
 
/* 文字提示*/
.small-tips {
  width: 100%;
 
  padding: 20rpx;
  font-size: 29rpx;
  margin: 0 0 20rpx;
  color: #999;
}
 
.btn-auth {
  width: 92%;
  background: $main-color;
  color: #fff;
  margin: 0 auto 40rpx;
  border-radius: 100px;
}
.btn-callback {
  text-align: center;
  font-size: 30rpx;
  background: #ededed;
  height: 90rpx;
  line-height: 90rpx;
  border-radius: 100px;
  width: 92%;
  margin: 0 auto;
}
 
.btns {
  margin-top: 100rpx;
  display: flex;
  flex-direction: column;
  width: 100%;
  justify-content: center;
}
</style>