lgh 1 月之前
父节点
当前提交
dc52ce6b6e
共有 3 个文件被更改,包括 35 次插入18 次删除
  1. 9 1
      apis/user.js
  2. 22 9
      pages/user/index.vue
  3. 4 8
      utils/preCheck.js

+ 9 - 1
apis/user.js

@@ -1,10 +1,18 @@
 import request from "@/request"
 
 
-// 订单分页
+// 登录微信
 export const loginWx = (data) => {
 	return request.post({
 		url: '/api/loginWx',
 		data: data,
 	})
+}
+
+// 退出登录
+export const logout = (data) => {
+	return request.post({
+		url: '/api/logout',
+		data: data,
+	})
 }

+ 22 - 9
pages/user/index.vue

@@ -27,7 +27,7 @@
             </view>
           </view>
           <view class="order-box">
-            <view class="order-box-item" v-for="(item, index) in orderList" :key="index">
+            <view class="order-box-item" v-for="(item, index) in orderList" :key="index" @click="toOrder(item)">
               <image :src="item.icon"></image>
               <text class="name">{{ item.label }}</text>
             </view>
@@ -41,19 +41,20 @@
         </view>
         <image class="more" :src="moreImg"></image>
       </view>
-      <view class="outline">退出登录</view>
+      <view class="outline" @click="outLogin()">退出登录</view>
     </view>
   </view>
 </template>
 
 <script>
 import config from '@/config'
-import { loginWx } from '@/apis/user.js'
+import { loginWx,logout } from '@/apis/user.js'
 export default {
   components: {},
   data() {
     return {
-      name: '',
+      name: uni.getStorageSync('name'),
+      token: uni.getStorageSync('token'),
       code: '',
       bgImg: "https://ovp-shop.oss-cn-hangzhou.aliyuncs.com/static/9dshop/bg_top%403x.png",
       logoImg: "https://ovp-shop.oss-cn-hangzhou.aliyuncs.com/static/9dshop/img_logo%403x.png",
@@ -88,8 +89,11 @@ export default {
   computed: {},
   watch: {},
   onLoad() {
-
-
+    
+    let token = uni.getStorageSync('token')
+    if(!token){
+      this.toLogin()
+    }
     // if(code !== null || code !== "") {
     //     this.getOpenidAndUserinfo(code)
     // }
@@ -102,7 +106,8 @@ export default {
     toLogin() {
       let isWX = this.isWechat()
       if (isWX) {
-        let code = this.getUrlCode('code')
+        // let code = this.getUrlCode('code')
+        let code = '001t0H000xuK7U'
         uni.showToast({
           title: code,
         })
@@ -183,9 +188,17 @@ export default {
         backgroundColor: '#FFF'
       })
     },
-    toOrder() {
+    toOrder(item) {
       this.$router.push({
-        path: '/pages/order/index'
+        path: '/pages/order/index?status=' + item.value 
+      })  
+    },
+    outLogin(){
+      logout().then(res => {
+        uni.removeStorageSync('accessToken')
+        uni.removeStorageSync('name')
+        this.name = ''
+        this.token = ''
       })
     }
   },

+ 4 - 8
utils/preCheck.js

@@ -29,16 +29,12 @@ if (platform() === 'H5') {
 				code: code
 			}).then(res => {
 				const {
-					openId,
-					customerVo,
+					name,
 					token,
 				} = res
-				uni.setStorageSync('openId', openId)
-				const userInfo = uni.getStorageSync('userInfo')
-				if (token && token.accessToken) { // 登录成功 后更新用户信息
-					uni.setStorageSync('accessToken', token.accessToken)
-					uni.setStorageSync('tokenType', token.tokenType)
-					uni.setStorageSync('userInfo', customerVo)
+				if (token) { // 登录成功 后更新用户信息
+					uni.setStorageSync('accessToken', token)
+					uni.setStorageSync('name', name)
 					// 设置默认地址
 					// addressFind().then(addrList => {
 					// 	const defaultAddrIndex = addrList.findIndex(item => item.defaultFlag === 1);