From dfb2221c1cafd8b4195cbaa7ad6e1a52b4501c70 Mon Sep 17 00:00:00 2001 From: lsl Date: Fri, 5 May 2023 16:53:20 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=9C=9F=E5=AE=9E=E6=89=AB?= =?UTF-8?q?=E7=A0=81=E5=92=8C=E7=99=BB=E5=87=BA=E5=8A=9F=E8=83=BD=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/home/me/indexx.js | 40 ++++++++++++++++++++++++++++++++++++++- pages/home/me/indexx.json | 3 ++- pages/home/me/indexx.wxml | 4 +++- pages/index/index.js | 23 ++++++++++++++++++++-- project.config.json | 2 +- utils/request.js | 4 ++-- 6 files changed, 68 insertions(+), 8 deletions(-) diff --git a/pages/home/me/indexx.js b/pages/home/me/indexx.js index e7b84aa..e4bf7cc 100644 --- a/pages/home/me/indexx.js +++ b/pages/home/me/indexx.js @@ -1,5 +1,6 @@ // pages/home/me/indexx.js import Toast from 'tdesign-miniprogram/toast/index'; +import Dialog from 'tdesign-miniprogram/dialog/index'; const app = getApp();//新建页面时 默认引入 const req = app.xzjlReq();//初始化一个的request() 实例 Page({ @@ -8,6 +9,7 @@ Page({ * 页面的初始数据 */ data: { + showConfirm: false }, ReqData(){ @@ -87,5 +89,41 @@ Page({ ljXzjl(){ console.log(app.globalData.xx) - } + }, + logout() { + const dialogConfig = { + context: this, + title: '退出登录', + content: '星座精灵是一款快速能够让你快速了解自己的星座特征以及星座运势,确定需要退出吗?', + confirmBtn: '确定', + cancelBtn: '取消', + }; + + Dialog.confirm(dialogConfig) + .then(() => { + req.deleteRequest('/api/user/logout',{}).then((res)=>{ + if(res.data.code===200){ + wx.navigateTo({ + url: '/pages/index/index' + }) + Toast({ + context: this, + selector: '#t-toast', + message: '退出成功!', + }); + } + }).catch((err)=>{ + Toast({ + context: this, + selector: '#t-toast', + message: '退出失败!', + }); + }) + + }) + .catch(() => console.log('点击了取消')) + .finally(() => { + wx.setStorageSync('token', '') + Dialog.close()}); + }, }) \ No newline at end of file diff --git a/pages/home/me/indexx.json b/pages/home/me/indexx.json index c24414c..fd94b68 100644 --- a/pages/home/me/indexx.json +++ b/pages/home/me/indexx.json @@ -2,6 +2,7 @@ "usingComponents": { "t-cell": "tdesign-miniprogram/cell/cell", "t-icon": "tdesign-miniprogram/icon/icon", - "t-toast": "tdesign-miniprogram/toast/toast" + "t-toast": "tdesign-miniprogram/toast/toast", + "t-dialog": "tdesign-miniprogram/dialog/dialog" } } \ No newline at end of file diff --git a/pages/home/me/indexx.wxml b/pages/home/me/indexx.wxml index 0016214..40ed9f5 100644 --- a/pages/home/me/indexx.wxml +++ b/pages/home/me/indexx.wxml @@ -52,9 +52,11 @@ 小程序版本 V1.0 - + 退出登录 + + diff --git a/pages/index/index.js b/pages/index/index.js index a8b5438..7db75a4 100644 --- a/pages/index/index.js +++ b/pages/index/index.js @@ -81,8 +81,27 @@ Page({ }, scanCodeEvent(){ var that = this; - // 暂时注释掉扫码的 var DEV_CODE = "34ADE4201285" + //扫码代码 + wx.scanCode({ + onlyFromCamera: true,// 只允许从相机扫码 + success(res){ + console.log("扫码成功:"+JSON.stringify(res)) + DEV_CODE = res.result + }, + fail (err) { + // console.log(err) + wx.showToast({ + title:'扫描失败', + icon: 'none', + duration: 1000 + }) + } + }) + + + + var PUBLIC_KEY = "" req.getRequest('/api/dict/value/login-public-key',{}).then((res)=>{ if(res.data.code==200){//扫码登录成功 @@ -98,7 +117,7 @@ Page({ // 此处执行登录获取token操作 req.postRequest('/api/user/login',{'mac':mac}).then((res)=>{ wx.setStorageSync('token', res.data.data) - console.log(res) + console.log('token是:'+res.data.data) wx.showToast({ title:'扫描登录成功', icon: 'none', diff --git a/project.config.json b/project.config.json index 1bad225..e9bf0bc 100644 --- a/project.config.json +++ b/project.config.json @@ -44,7 +44,7 @@ }, "compileType": "miniprogram", "libVersion": "2.19.4", - "appid": "wx0a5f61e439e70c4a", + "appid": "wxa0d7db44777041f7", "projectname": "miniprogram-92", "condition": {}, "editorSetting": { diff --git a/utils/request.js b/utils/request.js index a2b0bd0..06535fb 100644 --- a/utils/request.js +++ b/utils/request.js @@ -2,7 +2,7 @@ class request { constructor() { this._baseUrl = 'https://xzjl-api.windymuse.cn'; this._token = wx.getStorageSync('token'); - this._header = {'Authorization': 'Bearer ' + this._token} + this._header = {'Authorization': this._token} } /** @@ -41,7 +41,7 @@ class request { wx.request({ url: this._baseUrl + url, data: data, - header: header, + header: {'Authorization': wx.getStorageSync('token')}, method: method, success: (res => { if (res.statusCode === 200) {