Browse Source

token管理及网点详情页修改

zuypeng 1 year ago
parent
commit
3183737d82

+ 44 - 15
src/App.vue

@@ -6,28 +6,36 @@ import {groupByKey} from "@/utils/common";
 export default <any>{
   globalData: {
     token: "",
-    user: {
-    },
+    user: {},
     isLogin: false,
-    last:{},
+    last: {},
     device: {},
-    deviceId:null,
-    manualLogout:false
+    deviceId: null,
+    manualLogout: false
   },
   onLaunch() {
-    uni.getSystemInfo({
-      success: (res) => {
-        this.globalData.device = res;
+    console.log("onLaunch clean token")
+    let device =  uni.getWindowInfo();
+    uni.removeStorageSync("token")
+    let initGlobalData = {
+      token: "",
+      user: {},
+      isLogin: false,
+      last: {},
+      device: {
+        windowWidth:device.windowWidth,
+        windowHeight:device.windowHeight,
+        screenTop: device.screenTop,
+        windowTop: device.windowTop,
       },
-    });
-    setTimeout(()=>{
-      console.log("onLaunch clean token")
-      clearToken()
-    })
+      deviceId: null,
+      manualLogout: false
+    }
+    this.globalData = Object.assign({},  initGlobalData)
 
     body(`/dict/list`).then((res: any) => {
       if (res) {
-        let dicts = res.map((k:any) => {
+        let dicts = res.map((k: any) => {
           let {code, name, value, color} = k;
           return {code, name, value, color}
         })
@@ -36,7 +44,28 @@ export default <any>{
       }
     })
 
-    this.globalData.token = fetchToken();
+    // this.globalData.token = fetchToken();
+  },
+  onShow(options: any) {
+    console.log("app onShow", options)
+    let device = uni.getWindowInfo();
+    let backup = uni.getStorageSync('backup')
+    console.log("backup", backup)
+    getApp<any>().globalData = Object.assign({}, getApp<any>().globalData, {
+      device: {
+        windowWidth: device.windowWidth,
+        windowHeight: device.windowHeight,
+        screenTop: device.screenTop,
+        windowTop: device.windowTop,
+      }
+    }, backup)
+    console.log("backup", backup,getApp<any>().globalData)
+  },
+  onHide() {
+    console.log("app onHide", getApp<any>().globalData)
+    //backup
+    let backup = {...getApp<any>().globalData}
+    uni.setStorageSync('backup', backup)
   },
   onPageNotFound() {
     uni.switchTab({

+ 80 - 68
src/components/tab-bar/index.vue

@@ -5,7 +5,9 @@
             v-for="(item, index) in state.tabbarList" :key="index"
             :class="[item.centerItem ? ' center-item' : '']"
             @click="handleTabbarClick(item)">
-        <view class="item-top"><image :src="state.currentItem == item.id ? item.selectIcon : item.icon"  mode="widthFit"></image></view>
+        <view class="item-top">
+          <image :src="state.currentItem == item.id ? item.selectIcon : item.icon" mode="widthFit"></image>
+        </view>
         <view class="item-bottom" :class="[state.currentItem == item.id ? 'item-active' : '',state.isIOS?'ios11':'']">
           <text>{{ item.text }}</text>
         </view>
@@ -15,81 +17,81 @@
 </template>
 
 <script setup lang="ts" name="TabBar">
-  import {onMounted, reactive, ref} from 'vue'
-  import {onLoad, onShow} from "@dcloudio/uni-app";
+import {onMounted, reactive, ref} from 'vue'
+import {onLoad, onShow} from "@dcloudio/uni-app";
 
-  const props = defineProps({
-    index: {
-      type: Number,
-      default: 0
-    }
-  })
+const props = defineProps({
+  index: {
+    type: Number,
+    default: 0
+  }
+})
 
-  const state = reactive({
-    currentItem:0,
-    isIOS:false,
-
-    tabbarList:[
-      {
-        id: 0,
-        path: '/pages/index/index',
-        icon: '/static/iconfont/default/wash.svg',
-        selectIcon: '/static/iconfont/wash.svg',
-        text: '网点',
-        centerItem: false
-      },
-      {
-        id: 1,
-        path: '/pages-wash/scan/index',
-        icon: '/static/iconfont/scan.svg',
-        selectIcon: '/static/iconfont/scan.svg',
-        text: '扫码',
-        centerItem: true
-      },
-      {
-        id: 2,
-        path: '/pages/user/index',
-        icon: '/static/iconfont/default/me.svg',
-        selectIcon: '/static/iconfont/me.svg',
-        text: '我的',
-        centerItem: false
-      }
-    ]
-  })
+const state = reactive({
+  currentItem: 0,
+  isIOS: false,
 
-  onLoad(() => {
-    state.currentItem = props.index;
+  tabbarList: [
+    {
+      id: 0,
+      path: '/pages/index/index',
+      icon: '/static/iconfont/default/wash.svg',
+      selectIcon: '/static/iconfont/wash.svg',
+      text: '网点',
+      centerItem: false
+    },
+    {
+      id: 1,
+      path: '/pages-wash/scan/index',
+      icon: '/static/iconfont/scan.svg',
+      selectIcon: '/static/iconfont/scan.svg',
+      text: '扫码',
+      centerItem: true
+    },
+    {
+      id: 2,
+      path: '/pages/user/index',
+      icon: '/static/iconfont/default/me.svg',
+      selectIcon: '/static/iconfont/me.svg',
+      text: '我的',
+      centerItem: false
+    }
+  ]
+})
 
-  })
+onLoad(() => {
+  state.currentItem = props.index;
 
-  onShow(() => {
-    state.currentItem = props.index;
-    const device = uni.getSystemInfoSync();
-    state.isIOS = device.osName === "ios";
-  })
+})
 
-  onMounted(()=>{
-    state.currentItem = props.index;
-  })
+onShow(() => {
+  state.currentItem = props.index;
+  const device = uni.getDeviceInfo();
+  state.isIOS = device.system.includes("ios");
+})
 
+onMounted(() => {
+  state.currentItem = props.index;
+})
 
-  const handleTabbarClick = (item: string) => {
-    if(item.path.includes("scan")){
-      uni.navigateTo({url:item.path})
-      return;
-    }
 
-    uni.switchTab({
-      url: item?.path,
-      success: (e: any) => {
-        console.log("tabbar switch>>>>", item,e)
-      },
-      fail: (e: any) => {
-        console.error("swtich error >>>>>", JSON.stringify(e))
-      }
-    })
+const handleTabbarClick = (item: string) => {
+  if (item.path.includes("scan")) {
+    uni.navigateTo({url: item.path})
+    return;
   }
 
+  uni.switchTab({
+    url: item?.path,
+    success: (e: any) => {
+      console.log("tabbar switch>>>>", item, e)
+    },
+    fail: (e: any) => {
+      console.error("swtich error >>>>>", JSON.stringify(e))
+    }
+  })
+}
+
 </script>
 <style lang="scss" scoped>
 view {
@@ -97,6 +99,7 @@ view {
   margin: 0;
   box-sizing: border-box;
 }
+
 .tabbar-container {
   position: fixed;
   bottom: 0;
@@ -109,8 +112,9 @@ view {
   padding: 25rpx 0;
   //color: #999999;
 
-  box-shadow:  0 -2px 5px #efefef;
+  box-shadow: 0 -2px 5px #efefef;
 }
+
 .tabbar-container .tabbar-item {
   width: 33.3%;
   height: 100rpx;
@@ -120,18 +124,22 @@ view {
   align-items: center;
   text-align: center;
 }
+
 .tabbar-container .item-active {
   color: $uni-color-primary;
 }
+
 .tabbar-container .center-item {
   display: block;
   position: relative;
 }
+
 .tabbar-container .tabbar-item .item-top {
   width: 70rpx;
   height: 70rpx;
   padding: 10rpx;
 }
+
 .tabbar-container .center-item .item-top {
   //flex-shrink: 0;
   width: 120rpx;
@@ -148,24 +156,28 @@ view {
 
   box-shadow: 0 0 10px #efefef; /* 阴影效果 */
 }
-.tabbar-container .center-item .item-top image{
+
+.tabbar-container .center-item .item-top image {
   //width: 110rpx !important;
   //height: 110rpx !important;
 }
+
 .tabbar-container .tabbar-item .item-top image {
   width: 100%;
   height: 100%;
 }
+
 .tabbar-container .tabbar-item .item-bottom {
   font-size: 22rpx;
   width: 100%;
 }
+
 .tabbar-container .center-item .item-bottom {
   position: absolute;
   bottom: 0;
 }
 
-.ios{
+.ios {
   bottom: 30rpx !important;
 }
 </style>

+ 1 - 1
src/pages-user/wallet/recharge.vue

@@ -101,7 +101,7 @@ const confirm = () => {
           icon:'success'
         })
         setTimeout(()=>{
-          uni.redirectTo({
+          uni.switchTab({
             url:'/pages/user/index'
           })
         },500)

+ 0 - 1
src/pages-user/wallet/refund.vue

@@ -1,5 +1,4 @@
 <template>
-  <uv-navbar leftIcon="" title="退款申请" ></uv-navbar>
   <view class="page">
     <view class="block">
       <view class="fs-28 color-000 fw-500">退款金额</view>

+ 36 - 19
src/pages-wash/station/index.vue

@@ -1,7 +1,7 @@
 <template>
   <uv-navbar leftIcon="arrow-left" @leftClick="handleLeftClick" title="门店详情"></uv-navbar>
-  <view :class="['page']">
-    <image :src="state.station.pictures" mode="widthFix" class="station-bg"></image>
+  <view class="page">
+    <image :src="state.station.pictures" mode="widthFix" class="station-bg" :style="state.imageStyle"></image>
 
     <view class="station-box">
       <view class=" station_wrapper">
@@ -21,14 +21,14 @@
             <view></view>
             <text class="device-item_body_header-short">服务:{{ device.functionList.join("、") }}</text>
           </view>
-<!--          <view class="device-item_body_func">
-            <view class="device-item_body_func-tag">
-              <uv-text text="服务:" size="mini" plain plainFill  color="black" ></uv-text>
-            </view>
-            <view class="device-item_body_func-tag" v-for="f in device.functionList" :key="f">
-              <uv-text :text="f" size="mini" plain plainFill  color="black" ></uv-text>
-            </view>
-          </view>-->
+          <!--          <view class="device-item_body_func">
+                      <view class="device-item_body_func-tag">
+                        <uv-text text="服务:" size="mini" plain plainFill  color="black" ></uv-text>
+                      </view>
+                      <view class="device-item_body_func-tag" v-for="f in device.functionList" :key="f">
+                        <uv-text :text="f" size="mini" plain plainFill  color="black" ></uv-text>
+                      </view>
+                    </view>-->
         </div>
 
       </view>
@@ -38,7 +38,7 @@
     <view class="station-bottom">
       <view class="station-bottom-box">
         <view class="bottom-left">
-          <uv-button shape="circle" type="info"   text="门店导航" @click="handleNavStation"></uv-button>
+          <uv-button shape="circle" type="info" text="门店导航" @click="handleNavStation"></uv-button>
         </view>
         <view class="bottom-right">
           <uv-button shape="circle" type="primary" icon="scan" iconColor="white" color="#C6171E" text="扫码洗车" @click="handleClickScan"></uv-button>
@@ -54,6 +54,7 @@ import {reactive, ref} from "vue";
 import {get} from "@/utils/https";
 import {fmtDictName} from "@/utils/common";
 import WashStation from "@/components/station/index.vue"
+import {rpxToPx} from "@/utils/device";
 
 const station_ref = ref()
 
@@ -62,7 +63,11 @@ const initState = () => ({
   station: {
     id: 0
   },
-  currentUserId: 0
+  currentUserId: 0,
+  imageStyle: {
+    height: '180px',
+    width: '100%',
+  }
 })
 
 const state = reactive(initState())
@@ -87,6 +92,14 @@ const handleLeftClick = () => {
 });*/
 
 onShow(() => {
+  //设置图片的宽高
+  let {windowWidth, windowHeight} = getApp<any>().globalData.device
+  let width = windowWidth - rpxToPx(20)
+  let height = windowHeight * 3 / 4
+  state.imageStyle = {
+    width: `${width}px`,
+    height: `${height}px`,
+  }
   let station = getApp<any>().globalData.last.station;
   if (station) {
     state.station = station;
@@ -140,8 +153,8 @@ const handleClickDevice = (device: any) => {
 
 <style lang="scss" scoped>
 .page {
-  margin-top: 44px;
-  height: calc(100vh - 44px);
+  margin-top: 104px;
+  height: calc(100vh - 164px);
   width: 100%;
   background-color: #eee;
   display: flex;
@@ -149,9 +162,10 @@ const handleClickDevice = (device: any) => {
 }
 
 .station-bg {
+  z-index: 1;
   border-radius: 10px;
-  width: calc(100vw - 20rpx);
-  margin: 40px auto 0 auto;
+  //width: calc(100vw - 20rpx);
+  margin: 10px auto 0 auto;
 }
 
 .block {
@@ -167,11 +181,14 @@ const handleClickDevice = (device: any) => {
   width: calc(100vw - 80rpx);
   margin: -80rpx auto 0 auto;
   border-radius: 15rpx;
+  z-index: 10;
 }
 
 .device-box {
+  flex:1;
+  overflow-y: scroll;
   width: calc(100vw - 80rpx);
-  margin: 30rpx auto 100rpx;
+  margin: 30rpx auto 30rpx;
 }
 
 .device-item {
@@ -243,7 +260,7 @@ const handleClickDevice = (device: any) => {
   width: 100%;
 
   position: fixed;
-  bottom: 10rpx;
+  bottom: 20rpx;
   left: 20rpx;
 
   &-box {
@@ -261,7 +278,7 @@ const handleClickDevice = (device: any) => {
   }
 }
 
-.success{
+.success {
   background-color: $uni-color-success;
   color: #fff;
 }

+ 5 - 22
src/pages/index/index.vue

@@ -13,21 +13,7 @@
           <image :src="item" mode="scaleToFill" :style="state.customStyle" @click="handleBannerClick(idx)"></image>
         </swiper-item>
       </swiper>
-
-      <!--      <uv-swiper
-                style="width: 100%"
-                :list="state.swiperList"
-                @click="handleBannerClick"
-                circular
-                :autoplay="true"
-                bgColor="#ffffff">
-            </uv-swiper>-->
     </view>
-    <!--
-        <view class="w100">
-          <uv-notice-bar mode="closable" speed="50" url="/pages/coupon/index" :text="state.notice"></uv-notice-bar>
-        </view>
-    -->
 
     <view class="w100 gap"></view>
 
@@ -81,9 +67,8 @@
 
 <script setup lang="ts">
 import {nextTick, reactive, ref} from 'vue'
-import {onHide, onShow, onLoad} from "@dcloudio/uni-app";
+import {onHide, onLoad, onShow} from "@dcloudio/uni-app";
 import TabBar from "@/components/tab-bar/index.vue";
-import LoginBar from "@/components/login-bar/index.vue";
 import WashStation from "@/components/station/index.vue"
 import {get, post} from "@/utils/https";
 import {calcMapDistance} from "@/utils/common"
@@ -142,10 +127,9 @@ const initState = () => ({
 const state = reactive(initState())
 
 onLoad((e: any) => {
-  let height = uni.getSystemInfoSync().windowHeight;
-  let width = uni.getSystemInfoSync().windowWidth;
-  console.log(height, width, "screen")
-  state.screenWidth = width;
+  let height = uni.getWindowInfo().windowHeight;
+  // console.log(height, width, "screen")
+  state.screenWidth = uni.getWindowInfo().windowWidth;
   // const bound = uni.getMenuButtonBoundingClientRect();
   // width: 100%;height:170px;
   state.customStyle = {
@@ -162,7 +146,7 @@ onLoad((e: any) => {
 })
 
 onShow(() => {
-  let height = uni.getSystemInfoSync().windowHeight;
+  let height = uni.getWindowInfo().windowHeight;
   // const bound = uni.getMenuButtonBoundingClientRect();
   // width: 100%;height:170px;
   state.customStyle = {
@@ -330,7 +314,6 @@ const loadWashStationList = () => {
     return;
   }
   post(`/wash-station/listStation`, {pageSize: 5}).then((res: any) => {
-    console.log(res)
     let {list, total} = res;
     list.forEach((station: any) => {
       if (station.location) {

+ 0 - 15
src/uni_modules/uv-ui-tools/libs/function/index.js

@@ -39,21 +39,6 @@ function sleep(value = 30) {
 		}, value)
 	})
 }
-/**
- * @description 运行期判断平台
- * @returns {string} 返回所在平台(小写)
- * @link 运行期判断平台 https://uniapp.dcloud.io/frame?id=判断平台
- */
-function os() {
-	return uni.getSystemInfoSync().platform.toLowerCase()
-}
-/**
- * @description 获取系统信息同步接口
- * @link 获取系统信息同步接口 https://uniapp.dcloud.io/api/system/info?id=getsysteminfosync
- */
-function sys() {
-	return uni.getSystemInfoSync()
-}
 
 /**
  * @description 取一个区间数

+ 33 - 20
src/utils/auth.ts

@@ -76,12 +76,12 @@ export function login(e: any): Promise<string> {
                     code: res.code,
                     avatar: "",
                     nickname: "",
-                    shortId:e.shortId
+                    shortId: e.shortId
                 }
                 body(`/user/wxLogin`, data).then(async (res: any) => {
                     let {satoken, userId} = res;
                     if (satoken) {
-                        getApp<any>().globalData.user.id=userId
+                        getApp<any>().globalData.user.id = userId
                         // _resolveTokenQueue(satoken);
                         setToken(satoken);
                         await loadUserInfo();
@@ -91,7 +91,7 @@ export function login(e: any): Promise<string> {
                         uni.showModal({
                             title: `登录失败`,
                             icon: 'none',
-                            duration:2000
+                            duration: 2000
                         });
                         uni.hideLoading();
                         // _resolveTokenQueue({
@@ -102,16 +102,16 @@ export function login(e: any): Promise<string> {
                     uni.showModal({
                         title: `${e}`,
                         icon: 'none',
-                        duration:2000
+                        duration: 2000
                     });
                     uni.hideLoading();
                 })
             },
-            fail: ()=>{
+            fail: () => {
                 uni.showModal({
                     title: `登录失败`,
                     icon: 'none',
-                    duration:2000
+                    duration: 2000
                 });
                 uni.hideLoading();
             },
@@ -122,7 +122,7 @@ export function login(e: any): Promise<string> {
 export function tryLogin() {
     return new Promise(((resolve, reject) => {
         let ftoken = fetchToken();
-        console.log("ftoken", ftoken)
+        // console.log("ftoken", ftoken)
         if (ftoken) {
             resolve(ftoken)
             return;
@@ -139,7 +139,7 @@ export function tryLogin() {
                 body(`/user/wxLogin`, data).then(async (res: any) => {
                     const {satoken, userId} = res;
                     if (satoken) {
-                        getApp<any>().globalData.user.id=userId
+                        getApp<any>().globalData.user.id = userId
                         setToken(satoken);
                         await loadUserInfo();
                         resolve(satoken)
@@ -182,8 +182,9 @@ export function checkLogin() {
 export async function loadUserInfo() {
     getApp<any>().globalData.manualLogout = false;
     get(`/user/me`).then((res: any) => {
-        getApp<any>().globalData.user = res;
-        getApp<any>().globalData.isLogin = true;
+        // getApp<any>().globalData.user = res;
+        // getApp<any>().globalData.isLogin = true;
+        getApp<any>().globalData = Object.assign({}, {...getApp<any>().globalData},{user:res,isLogin:true,manualLogout:false})
         uni.$emit('login', {isLogin: true})
     })
 }
@@ -232,29 +233,41 @@ export function refresh(): Promise<string> {
 
 export function fetchToken() {
     let tk = uni.getStorageSync("token");
-    console.log(tk)
-    if(tk.length>16){
+    // console.log(tk)
+    if (tk.length > 16) {
         return tk;
     }
     return null;
 }
 
 export function setToken(token: string) {
-    if(!token){
+    if (!token) {
         console.error("empty token")
         return;
-    }else{
-        console.log("set token",token)
+    } else {
+        console.log("set token", token)
     }
-    getApp<any>().globalData.token = token;
-    getApp<any>().globalData.isLogin = true;
+    getApp<any>().globalData = Object.assign({}, {...getApp<any>().globalData},{token,isLogin:true})
     uni.setStorageSync("token", token)
 }
 
 export function clearToken() {
-    getApp<any>().globalData.token = "";
-    getApp<any>().globalData.isLogin = false;
-    getApp<any>().globalData.user = {};
+    let device =  uni.getWindowInfo();
+    let initGlobalData = {
+        token: "",
+        user: {},
+        isLogin: false,
+        last: {},
+        device: {
+            windowWidth:device.windowWidth,
+            windowHeight:device.windowHeight,
+            screenTop: device.screenTop,
+            windowTop: device.windowTop,
+        },
+        deviceId: null,
+        manualLogout: false
+    }
     uni.$emit('logout')
     uni.removeStorageSync("token")
+    getApp<any>().globalData = Object.assign({}, initGlobalData)
 }

+ 16 - 10
src/utils/device.ts

@@ -1,17 +1,23 @@
 export function rpxToPx(unirpx: number): number {
-  if (getApp<any>().globalData.device) {
-    return (unirpx * getApp<any>().globalData.device.windowWidth) / 750;
-  }
-  return unirpx;
+    let gd = getApp<any>().globalData
+    if (gd && gd.device && gd.device.windowWidth) {
+        return (unirpx * gd.device.windowWidth) / 750;
+    } else {
+        return (unirpx * uni.getWindowInfo().windowWidth) / 750;
+    }
+    return unirpx;
 }
 
 export function pxToRpx(px: number): number {
-  if (getApp<any>().globalData.device) {
-    return (750 * px) / getApp<any>().globalData.device.windowWidth;
-  }
-  return px;
+    let gd = getApp<any>().globalData
+    if (gd && gd.device && gd.device.windowWidth) {
+        return (750 * px) / gd.device.windowWidth;
+    } else {
+        return (750 * px) / uni.getWindowInfo().windowWidth;
+    }
+    return px;
 }
 
 export const isDevTool =
-  getApp<any>().globalData.device &&
-  getApp<any>().globalData.device.platform === "devtools";
+    getApp<any>().globalData.device &&
+    getApp<any>().globalData.device.platform === "devtools";

+ 8 - 5
src/utils/https.ts

@@ -43,6 +43,7 @@ const isEmptyOrNull = function (exp: any) {
  */
 const get = (url: string, param = {}) => {
     let token = fetchToken() || ""
+    console.log(token, url, new Date().toLocaleString())
     if (!isEmptyOrNull(param)) {
         let params = [];
         for (let key in param) {
@@ -67,6 +68,7 @@ const get = (url: string, param = {}) => {
 
 const post = (url: string, param = {}) => {
     let token = fetchToken() || ""
+    console.log(token, url, new Date().toLocaleString())
     let options = {
         url: fillUrl(url),
         data: param,
@@ -84,6 +86,7 @@ const post = (url: string, param = {}) => {
 
 const body = (url: string, param = {}) => {
     let token = fetchToken() || ""
+    console.log(token, url, new Date().toLocaleString())
     let options = {
         url: fillUrl(url),
         data: param,
@@ -101,7 +104,6 @@ const body = (url: string, param = {}) => {
 
 
 const request = (options: any) => {
-    console.log("url>>>>",options.url)
     return new Promise((resolve, reject) => {
         uni.request({
             url: options.url,
@@ -115,15 +117,16 @@ const request = (options: any) => {
             if (response.code !== 200) {
                 let errMsg = response.message || '服务异常,请稍后重试';
                 console.error("error=>", errMsg);
-                if(response.code!==301){
+                if (response.code !== 301) {
                     uni.showToast({
                         title: errMsg,
                         icon: 'error',
-                        duration:5000
+                        duration: 5000
                     });
                 }
-                if(response.code==1001){
+                if (response.code == 1001) {
                     //清除登录状态
+                    console.error("清除登录状态XXXXXXXXXXXXX")
                     clearToken();
                 }
                 reject(errMsg);
@@ -144,7 +147,7 @@ const request = (options: any) => {
 
 const upload = (url: string, param: any = {}) => {
     let token = fetchToken() || ""
-    console.log("upload", url, param, token)
+    console.log(token, url, new Date().toLocaleString())
     return new Promise((resolve, reject) => {
         uni.uploadFile({
             url: fillUrl(url),