| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- <template>
- <view class="">
- <u-loading-page iconSize="160" :loading="true" loading-text="loading..."
- image="/static/images/common/loading.png"></u-loading-page>
- </view>
- </template>
- <script>
- import {
- setToken
- } from '@/utils/auth'
- import {
- login,
- verifyScanCode
- } from '@/api/login'
- import {
- getScanData
- } from '@/api/scan'
- export default {
- data() {
- return {
- scanCode: 'a37d38ad0e1f3472',
- path: '',
- status: false
- }
- },
- onLoad(options) {
- uni.removeStorageSync("scanCode");
- uni.removeStorageSync("Authorization-status");
- // 获取并解码 q 参数
- let qlink = decodeURIComponent(options.q || '');
- if (qlink) {
- const decodedUrl = decodeURIComponent(qlink); // 先解码
- // 1. 去掉域名部分,提取路径
- const scanCode = decodedUrl.replace('https://scantest.dnzc.vip/', ''); // 得到 "a7e4a3f2947004f6"
- this.scanCode = scanCode;
- }
- this.login(); // 调用登录方法
- },
- methods: {
- login() {
- let that = this;
- if (this.scanCode == '' || this.scanCode == undefined) {
- this.status = true;
- }
- wx.login({
- success(res) {
- if (res.code) {
- // 例如发送到服务器进行登录态验证等操作
- login(that.scanCode, res.code).then(res => {
- console.log('登录成功', res);
- if (res.code === 0) {
- if (res.data.isWxAuth == 1) {
- uni.setStorageSync('Authorization-status', true);
- }
- that.scanCode = res.data.qrCode;
- setToken(res.data.sessionId)
- that.path = res.data.page_path;
- that.verify();
- } else {
- console.log('登录失败!' + res.msg);
- }
- })
- } else {
- console.log('登录失败!' + res.errMsg);
- uni.showToast({ title: res.msg || '登录失败', icon: 'none' });
- }
- },
- fail(err) {
- uni.showToast({ title: err.msg || '登录失败', icon: 'none' });
- console.log('登录失败', err);
- }
- });
- },
- verify() {
- verifyScanCode(this.scanCode).then(res => {
- console.log(res);
- if (res.code === 0) {
- uni.setStorageSync("scanCode", this.scanCode);
- if (res.data.url !== null && res.data.url !== undefined && res.data.url !== '') {
- uni.redirectTo({
- url: '/pages/' + this.path + '/index/authCode'
- })
- return;
- }
- if (this.status) {
- uni.redirectTo({
- url: '/pages/' + this.path + '/my/my'
- })
- return;
- }
- getScanData(this.scanCode).then(res => {
- if (res.code === 0) {
- let url = '/pages/' + this.path + '/index/' + res.data.url;
- uni.setStorageSync('scanDetail', res.data);
- uni.redirectTo({
- url: url
- })
- } else {
- }
- })
- } else {
- let url = '/pages/' + this.path + '/error?msg=' + res.msg;
- uni.redirectTo({
- url: url // 目标页面路径
- })
- }
- })
- }
- }
- }
- </script>
|