Browse Source

登录调试

zuypeng 1 year ago
parent
commit
1195f9c354

+ 3 - 3
package.json

@@ -11,8 +11,8 @@
     "@dcloudio/uni-app": "3.0.0-4020420240722002",
     "@dcloudio/uni-components": "3.0.0-4020420240722002",
     "@dcloudio/uni-mp-weixin": "3.0.0-4020420240722002",
-    "sass": "^1.65.1",
-    "vue": "^3.4.21",
+    "sass": "1.65.1",
+    "vue": "3.4.21",
     "vue-i18n": "^9.1.9"
   },
   "devDependencies": {
@@ -21,7 +21,7 @@
     "@dcloudio/uni-cli-shared": "3.0.0-4020420240722002",
     "@dcloudio/uni-stacktracey": "3.0.0-4020420240722002",
     "@dcloudio/vite-plugin-uni": "3.0.0-4020420240722002",
-    "@vue/runtime-core": "^3.4.21",
+    "@vue/runtime-core": "3.4.21",
     "@vue/tsconfig": "^0.1.3",
     "typescript": "^4.9.4",
     "vite": "5.2.8",

+ 3 - 0
src/App.vue

@@ -3,9 +3,12 @@ import { fetchToken } from "./utils/auth";
 export default <any>{
   globalData: {
     token: "",
+    userInfo:{},
+    isLogin:false,
     lastData: {},
     stations: [],
     normalCode: "",
+    device:null
   },
   onLaunch() {
     uni.getSystemInfo({

+ 25 - 5
src/components/login-bar/index.vue

@@ -1,14 +1,33 @@
 <template>
-  <view class="login-bar flex flex-inline">
-    <text class="font12">登录以享受更多洗车功能</text>
-    <uv-button class="login-bar_btn"  size="mini" shape="circle" type="primary" open-type="getPhoneNumber"
+  <view class="login-bar flex flex-inline" v-if="!state.isLogin">
+    <text class="font12" >   登录以享受更多洗车功能</text>
+    <uv-button class="login-bar_btn" size="mini" shape="circle" type="primary" open-type="getPhoneNumber"
                @getphonenumber="handleGetPhone">去登录
     </uv-button>
   </view>
 </template>
 <script setup lang="ts" name="loginBar">
-const handleGetPhone = (e) => {
+import {login} from "@/utils/auth";
+import {onLoad} from "@dcloudio/uni-app";
+import {reactive} from "vue";
+
+const state= reactive({
+  isLogin:false
+});
+
+onLoad(()=>{
+  let globalData = getApp<any>().globalData;
+  state.isLogin = globalData.isLogin;
+  console.log("login bar onLoad>>>>", globalData, state.isLogin)
+})
+
+
+const handleGetPhone = (e:any) => {
   console.log(e)
+  login(e).then((token: string) => {
+    console.log(">>>>>>>>>",token)
+      state.isLogin =true;
+  })
 }
 </script>
 
@@ -20,8 +39,9 @@ const handleGetPhone = (e) => {
   border-radius: 8rpx;
   padding: 16rpx 10rpx;
   margin: 20rpx;
+  box-shadow: 5px 5px 15px 5px rgba(0, 0, 0, 0.3);
 
-  &_btn{
+  &_btn {
     margin-right: 30rpx;
   }
 }

+ 3 - 2
src/pages/coupon/index.vue

@@ -54,7 +54,7 @@
 <!--    <view v-if="showClose" class="button-cancel" @click="handleClose">
       不使用
     </view>-->
-
+    <login-bar class="w100 text-center"></login-bar>
     <tab-bar :index="1"/>
   </view>
 </template>
@@ -63,7 +63,8 @@
 <script setup lang="ts">
 import {reactive, ref} from 'vue'
 import {onHide, onShow} from "@dcloudio/uni-app";
-import TabBar from "@/components/tab-bar";
+import TabBar from "@/components/tab-bar/index.vue";
+import LoginBar from "@/components/login-bar/index.vue";
 
 
 const props = defineProps({

+ 2 - 2
src/pages/index/index.vue

@@ -92,8 +92,8 @@
 <script setup lang="ts">
 import {reactive, ref} from 'vue'
 import {onHide, onShow} from "@dcloudio/uni-app";
-import TabBar from "@/components/tab-bar";
-import LoginBar from "@/components/login-bar";
+import TabBar from "@/components/tab-bar/index.vue";
+import LoginBar from "@/components/login-bar/index.vue";
 
 const title = ref('Hello')
 const qrcode_ref = ref()

+ 3 - 2
src/pages/map/index.vue

@@ -60,7 +60,7 @@
       </view>
     </view>
     <!--    站点清单  end-->
-
+    <login-bar class="w100 text-center"></login-bar>
     <tab-bar :index="2"/>
   </view>
 </template>
@@ -69,7 +69,8 @@
 <script setup lang="ts">
 import {reactive, ref} from 'vue'
 import {onHide, onShow} from "@dcloudio/uni-app";
-import TabBar from "@/components/tab-bar";
+import TabBar from "@/components/tab-bar/index.vue";
+import LoginBar from "@/components/login-bar/index.vue";
 
 const mapCtx = ref(); // 地图上下文
 

+ 3 - 1
src/pages/order/index.vue

@@ -42,6 +42,7 @@
         </view>
       </view>
     </scroll-view>
+    <login-bar class="w100 text-center"></login-bar>
     <tab-bar :index="3"/>
   </view>
 </template>
@@ -49,7 +50,8 @@
 <script lang="ts" setup>
 import {reactive} from 'vue'
 import {onHide, onShow} from "@dcloudio/uni-app";
-import TabBar from "@/components/tab-bar";
+import TabBar from "@/components/tab-bar/index.vue";
+import LoginBar from "@/components/login-bar/index.vue";
 
 const initState = () => ({
   orderList: [{

+ 3 - 1
src/pages/user/index.vue

@@ -44,13 +44,15 @@
       </view>
     </view>
   </block>
+  <login-bar class="w100 text-center"></login-bar>
   <tab-bar :index="4"/>
 </template>
 
 <script setup lang="ts">
 import {onLoad, onShow} from "@dcloudio/uni-app";
 import {ref} from "vue";
-import TabBar from "@/components/tab-bar";
+import TabBar from "@/components/tab-bar/index.vue";
+import LoginBar from "@/components/login-bar/index.vue";
 
 const containerStyle = ref({});
 const user = ref<any>({

+ 6 - 5
src/utils/auth.ts

@@ -49,13 +49,13 @@ const _resolveTokenQueue = function (res: any) {
 
 export function login(e: any): Promise<string> {
   return new Promise((resolve, reject) => {
-    if (/deny|cancel/.test(e.detail.errMsg)) {
+    if (/deny|cancel/.test(e.errMsg)) {
       reject();
       return;
     }
-    if (!e.detail.code) {
+    if (!e.code) {
       uni.showModal({
-        title: `${e.detail.errMsg},请重试`,
+        title: `${e.errMsg},请重试`,
       });
       reject();
       return;
@@ -75,7 +75,7 @@ export function login(e: any): Promise<string> {
     uni.login({
       success: (res) => {
         let data = {
-          phoneCode: e.detail.code,
+          phoneCode: e.code,
           code: res.code,
           avatar: "",
           nickname: "",
@@ -95,7 +95,7 @@ export function login(e: any): Promise<string> {
             });
           }
         }).catch(e=>{
-          _resolveTokenQueue
+          _resolveTokenQueue({})
         })
       },
       fail: _resolveTokenQueue,
@@ -157,6 +157,7 @@ export function fetchToken() {
 
 export function setToken(token: string) {
   getApp<any>().globalData.token = token;
+  getApp<any>().globalData.isLogin = true;
   return _tokenStorage.set("token", token);
 }
 

+ 8 - 7
src/utils/https.ts

@@ -16,14 +16,15 @@ isDevelopment = e === "develop" || e === "trial";
 const env: string = isDevelopment ? "dev" : "prd";
 const apis = {
     dev: {
-        serverUrl: "https://dev.kuaiyuman.cn/api/",
+        serverUrl: "http://localhost:8088/api",
         fileUrl: "https://zyp-1258963180.cos.ap-guangzhou.myqcloud.com/"
     },
     prd: {
-        serverUrl: "https://npww.net.cn/cms/",
-        fileUrl: "https://zyp-1258963180.cos.ap-guangzhou.myqcloud.com/",
+        serverUrl: "https://wash.kuaiyuman.cn/api/",
+        fileUrl: "https://wash.kuaiyuman.cn",
     },
 };
+// @ts-ignore
 const cfg = {
     key: {
         token: 'wash.token'
@@ -52,8 +53,8 @@ const isEmptyOrNull = function (exp: any) {
 const get = (url: string, param = {}) => {
     let token = fetchToken() || ""
     if (!isEmptyOrNull(param)) {
-        var params = [];
-        for (var key in param) {
+        let params = [];
+        for (let key in param) {
             // @ts-ignore
             params.push(encodeURIComponent(key) + "=" + encodeURIComponent(param[key]));
         }
@@ -99,9 +100,9 @@ const request = (options: any) => {
             method: options.method,
             header: options.header,
             dataType: options.dataType
-        }).then(res => {
+        }).then((res:any) => {
             // @ts-ignore
-            let response = res[1].data;
+            let response = res.data;
             if (response.code !== 200) {
                 if (response.code == 92213 || response.code == 92305) {
                     uni.showToast({