Sfoglia il codice sorgente

style:优化样式

yizhiyang 11 mesi fa
parent
commit
5db8c893c8
4 ha cambiato i file con 331 aggiunte e 321 eliminazioni
  1. 30 29
      src/App.vue
  2. 115 111
      src/pages/client/tabBar/promotionCode/index.vue
  3. 35 25
      src/pages/login/index.vue
  4. 151 156
      src/utils/request.js

+ 30 - 29
src/App.vue

@@ -1,38 +1,39 @@
 <script>
-  import store from './store';
-  export default {
-    async onLaunch() {
-    store.dispatch('getAppSystemInfo')
-	  if(store.getters.scope === 'CUSTOMER'){
+import store from './store';
+export default {
+  async onLaunch() {
+    store.dispatch('getAppSystemInfo');
+    if (store.getters.scope === 'CUSTOMER') {
       uni.switchTab({
-        url:'/pages/client/tabBar/home/index'
-      })
-    }else{
+        url: '/pages/client/tabBar/home/index',
+      });
+    } else {
       uni.navigateTo({
-        url:'/pages/merchant/order/index'
-      })
+        url: '/pages/merchant/order/index',
+      });
     }
-    },
-    mounted() {
-      uni.hideTabBar({
-		  success: () => {
-		  	console.log('hide tabber success');
-		  },fail: () => {
-		  	console.log('hide tabber fail');
-		  }
-	  })
-    }
-  };
+  },
+  mounted() {
+    uni.hideTabBar({
+      success: () => {
+        console.log('hide tabber success');
+      },
+      fail: () => {
+        console.log('hide tabber fail');
+      },
+    });
+  },
+};
 </script>
 
 <style lang="scss">
-  @import 'uview-ui/index.scss';
-  @import 'design/index.scss';
-  @import url('design/common.css');
+@import 'uview-ui/index.scss';
+@import 'design/index.scss';
+@import url('design/common.css');
 
-  page {
-    background-color: #f5f5f5;
-    color: $uni-text-color;
-    font-size: $uni-font-size-base;
-  }
+page {
+  background-color: #f2f2f2;
+  color: $uni-text-color;
+  font-size: $uni-font-size-base;
+}
 </style>

+ 115 - 111
src/pages/client/tabBar/promotionCode/index.vue

@@ -1,6 +1,5 @@
 <template>
   <view class="page">
-
     <view class="img-box">
       <image :src="avatar" class="img" mode="aspectFill"></image>
       <view class="img-text">
@@ -11,7 +10,14 @@
 
     <view class="qrcode-box">
       <view class="qrcode">
-        <uQrcode ref="qr" canvas-id="qr" :value="text" :size="size" @click="remake" @complete="complete($event)">
+        <uQrcode
+          ref="qr"
+          canvas-id="qr"
+          :value="text"
+          :size="size"
+          @click="remake"
+          @complete="complete($event)"
+        >
         </uQrcode>
       </view>
     </view>
@@ -21,123 +27,121 @@
 </template>
 
 <script>
-  import uQrcode from '@/uni_modules/Sansnn-uQRCode/components/u-qrcode/u-qrcode.vue';
-  import { mapGetters } from "vuex"
-  export default {
-    data() {
-      return {
-        text:'https://image.baidu.com/search/index?tn=baiduimage&ps=1&ct=201326592&lm=-1&cl=2&nc=1&ie=utf-8&dyTabStr=MCwxLDMsMiw2LDQsNSw3LDgsOQ%3D%3D&word=giao',
-        size: 200
-      };
+import uQrcode from '@/uni_modules/Sansnn-uQRCode/components/u-qrcode/u-qrcode.vue';
+import { mapGetters } from 'vuex';
+export default {
+  data() {
+    return {
+      text: 'https://image.baidu.com/search/index?tn=baiduimage&ps=1&ct=201326592&lm=-1&cl=2&nc=1&ie=utf-8&dyTabStr=MCwxLDMsMiw2LDQsNSw3LDgsOQ%3D%3D&word=giao',
+      size: 200,
+    };
+  },
+  components: {
+    uQrcode,
+  },
+  computed: {
+    ...mapGetters(['location', 'avatar', 'nickname']),
+  },
+  methods: {
+    complete(e) {
+      if (e.success) {
+        console.log('生成成功');
+      } else {
+        console.log('生成失败');
+      }
     },
-    components: {
-      uQrcode
+    remake() {
+      // const ref = this.$refs['qr'];
+      // ref.remake();
     },
-	computed:{
-		...mapGetters(['location','avatar','nickname'])
-	},
-    methods: {
-      complete(e) {
-        if (e.success) {
-          console.log('生成成功');
-        } else {
-          console.log('生成失败');
-        }
-      },
-      remake() {
-        // const ref = this.$refs['qr'];
-        // ref.remake();
-      },
-      save() {
-        uni.showLoading({
-          title: '保存中',
-          mask: true
-        });
-        const ref = this.$refs['qr'];
-        ref.save({
-          success: res => {
-            uni.hideLoading();
-            uni.showToast({
-              icon: 'success',
-              title: '保存成功'
-            });
-          },
-          fail: err => {
-            uni.showToast({
-              icon: 'none',
-              title: JSON.stringify(err)
-            });
-          }
-        });
-
-      }
-    }
-  };
+    save() {
+      uni.showLoading({
+        title: '保存中',
+        mask: true,
+      });
+      const ref = this.$refs['qr'];
+      ref.save({
+        success: res => {
+          uni.hideLoading();
+          uni.showToast({
+            icon: 'success',
+            title: '保存成功',
+          });
+        },
+        fail: err => {
+          uni.showToast({
+            icon: 'none',
+            title: JSON.stringify(err),
+          });
+        },
+      });
+    },
+  },
+};
 </script>
 
 <style lang="scss" scoped>
-  .img-box{
-      display: flex;
-      align-items: center;
-      margin: 280rpx auto 0;
-      padding: 20rpx;
-      border-radius: 20rpx;
-      width: 90%;
-      background: linear-gradient(to right, #f3904f, #3b4371);
-      .img{
-        width: 160rpx;
-        height: 160rpx;
-        border-radius: 20rpx;
-        margin-left: 12%;
-      }
-
-    }
-    .img-text{
-      font-size: 28rpx;
-      font-weight: bold;
-      margin-left: 20rpx;
-      display: flex;
-      flex-direction: column;
-      align-content: space-evenly;
-      .name{
-        font-size: 36rpx;
-        color: #fff;
-      }
-      .address{
-        // color: #B5B5B5;
-        color: #fff;
-        margin-top: 24rpx;
-      }
-    }
-  .qrcode-box {
-    display: flex;
-    flex-direction: column;
-    align-items: center;
-    padding: 0 30px;
-    margin-top: 100rpx;
+.img-box {
+  display: flex;
+  align-items: center;
+  margin: 280rpx auto 0;
+  padding: 20rpx;
+  border-radius: 20rpx;
+  width: 90%;
+  background: linear-gradient(to right, #f3904f, #3b4371);
+  .img {
+    width: 160rpx;
+    height: 160rpx;
+    border-radius: 20rpx;
+    margin-left: 12%;
   }
-  .scan-text{
-    text-align: center;
-    font-size:28rpx;
-    color: #B7B7B7;
-    margin-top: 40rpx;
+}
+.img-text {
+  font-size: 28rpx;
+  font-weight: bold;
+  margin-left: 20rpx;
+  display: flex;
+  flex-direction: column;
+  align-content: space-evenly;
+  .name {
+    font-size: 36rpx;
+    color: #fff;
   }
-
-  .qrcode {
-    padding: 16px;
-    background-color: #ffffff;
-    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.1);
-    border-radius: 2px;
-    overflow: hidden;
+  .address {
+    // color: #B5B5B5;
+    color: #fff;
+    margin-top: 24rpx;
   }
+}
+.qrcode-box {
+  display: flex;
+  flex-direction: column;
+  align-items: center;
+  padding: 0 30px;
+  margin-top: 100rpx;
+}
+.scan-text {
+  text-align: center;
+  font-size: 28rpx;
+  color: #b7b7b7;
+  margin-top: 40rpx;
+}
 
-  .msg {
-    margin-top: 15px;
-    font-size: 14px;
-    color: #9a9b9c;
-  }
+.qrcode {
+  padding: 16px;
+  background-color: #ffffff;
+  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.1);
+  border-radius: 2px;
+  overflow: hidden;
+}
 
-  .save {
-    margin-top: 10px;
-  }
+.msg {
+  margin-top: 15px;
+  font-size: 14px;
+  color: #9a9b9c;
+}
+
+.save {
+  margin-top: 10px;
+}
 </style>

+ 35 - 25
src/pages/login/index.vue

@@ -41,8 +41,16 @@
       <u-checkbox-group v-model="agree">
         <u-checkbox shape="circle" name="1" label="我已阅读并同意" />
       </u-checkbox-group>
-      <view @click="$Router.push('/pages/webview/index?target=http://8.137.122.65:88/用户协议.html')" class="agreement">《用户协议》</view>
-      <view @click="$Router.push('/pages/webview/index?target=http://8.137.122.65:88/隐私政策.html')" class="agreement">《隐私政策》</view>
+      <view
+        @click="$Router.push('/pages/webview/index?target=http://8.137.122.65:88/用户协议.html')"
+        class="agreement"
+        >《用户协议》</view
+      >
+      <view
+        @click="$Router.push('/pages/webview/index?target=http://8.137.122.65:88/隐私政策.html')"
+        class="agreement"
+        >《隐私政策》</view
+      >
     </view>
 
     <!-- 第三方 -->
@@ -64,9 +72,9 @@ import { getWxLoginCode } from '@/api/login.js';
 export default {
   data() {
     return {
-      agree:[],
-      code:'',
-      mobile:'', // 手机号密文并非真实手机号
+      agree: [],
+      code: '',
+      mobile: '', // 手机号密文并非真实手机号
       isUserAgreement: false,
       loading: false,
       title: '',
@@ -92,44 +100,44 @@ export default {
       },
     };
   },
-  computed:{
-    checked(){
-      return this.agree && this.agree.length > 0
-    }
+  computed: {
+    checked() {
+      return this.agree && this.agree.length > 0;
+    },
   },
   methods: {
-    checkAgree(){
+    checkAgree() {
       if (!this.checked) {
-        return uni.$u.toast('请阅读并勾选底部协议')
+        return uni.$u.toast('请阅读并勾选底部协议');
       }
     },
     //点击微信用户一键登录
     async login(e) {
-      if(e.detail.errMsg != 'getPhoneNumber:ok'){
-        return uni.$u.toast('您已取消登录')
+      if (e.detail.errMsg != 'getPhoneNumber:ok') {
+        return uni.$u.toast('您已取消登录');
       }
-      this.mobile = e.detail.code
+      this.mobile = e.detail.code;
       this.code = await getWxLoginCode();
-      if(!this.code || !this.mobile) {
-        this.loading = false
-        uni.$u.toast('微信授权失败,请稍后重试')
-        return
+      if (!this.code || !this.mobile) {
+        this.loading = false;
+        uni.$u.toast('微信授权失败,请稍后重试');
+        return;
       }
       this.loading = true;
       const data = {
-        code:this.code,
-        mobile:this.mobile,
-      }
+        code: this.code,
+        mobile: this.mobile,
+      };
       this.$store
         .dispatch('LoginByWxCode', data)
         .then(() => {
-          this.$store.dispatch('SwitchIdentity','CUSTOMER')
+          this.$store.dispatch('SwitchIdentity', 'CUSTOMER');
           this.$Router.pushTab('/pages/client/tabBar/home/index');
           this.loading = false;
-          this.$store.dispatch('GetUserInfo')
+          this.$store.dispatch('GetUserInfo');
           uni.$u.toast('登录成功');
         })
-        .catch((err) => {
+        .catch(err => {
           this.loading = false;
           uni.$u.toast(`${err.message}`);
         });
@@ -156,7 +164,6 @@ export default {
     handleConfirm() {
       this.show = false; //关闭弹框
     },
-
   },
 };
 </script>
@@ -166,6 +173,9 @@ export default {
   height: 100vh;
   padding: 0 70rpx;
   background-color: #f2f5f9;
+  background-color: #fff;
+  padding-top: 150rpx;
+  box-sizing: border-box;
   .t-b {
     text-align: left;
     font-size: 46rpx;

+ 151 - 156
src/utils/request.js

@@ -1,165 +1,160 @@
-import axios from "axios";
+import axios from 'axios';
+import { UniAdapter } from 'uniapp-axios-adapter';
+import store from '@/store';
 import {
-	UniAdapter
-} from 'uniapp-axios-adapter'
-import store from '@/store'
-import {
-	getAccessToken,
-	setAccessToken,
-	setRefreshToken,
-	refreshToken,
-	isRefreshRequest
-} from "./auth"
+  getAccessToken,
+  setAccessToken,
+  setRefreshToken,
+  refreshToken,
+  isRefreshRequest,
+} from './auth';
 
 // 每次请求都创建一个新的实例
 const instance = axios.create({
-	// baseURL: "https://test.api.chelvc.com",
-	// baseURL: "http://192.168.68.77:11000",
-	baseURL: "https://358175z5l5.yicp.fun",
-	timeout: 10000,
-	adapter: UniAdapter
+  baseURL: 'https://test.api.chelvc.com',
+  // baseURL: "http://192.168.68.77:11000",
+  // baseURL: "https://358175z5l5.yicp.fun",
+  timeout: 10000,
+  adapter: UniAdapter,
 });
 
-instance.interceptors.request.use((config) => {
-	uni.showLoading({
-		title: '加载中'
-	})
-	// 带上token 和其他请求头信息
-	if (store.getters.accessToken) {
-		config.headers['Authorization'] = `Bearer ${getAccessToken()}`
-	}
-	console.log("@@@@config",config)
-	config.headers = {
-		...config.headers,
-		platform: store.getters.app.system.osName.toUpperCase(),
-		terminal: 'APPLET', // TODO:
-		version: store.getters.app.system.appVersion.toUpperCase(),
-		// scope: store.getters.scope,
-		device: store.getters.app.system.deviceId,
-		timestamp: new Date().getTime()
-	}
-	return config
-})
-
-instance.interceptors.response.use(async (res) => {
-	uni.hideLoading()
-	const {
-		code,
-		data,
-		message
-	} = res.data
-	if (data && data.accessToken) {
-		setAccessToken(data.accessToken)
-	}
-	if (data && data.refreshToken) {
-		setRefreshToken(data.refreshToken)
-	}
-	// 未知错误
-	if (code === 'ERROR') {
-		uni.showToast({
-			title: `${message ? message :'未知错误'}`,
-			icon: 'none'
-		})
-		return res.data
-	}
-	// 请求错误
-	if (code === 'BAD_REQUEST') {
-		uni.showToast({
-			title: `${message ? message :'请求异常'}`,
-			icon: 'none'
-		})
-		return res.data
-	}
-	// 拒绝访问
-	if (code === 'FORBIDDEN') {
-		uni.showToast({
-			title: `${message ? message :'拒绝访问'}`,
-			icon: 'none'
-		})
-		return
-	}
-	// 请求参数异常
-	if (code === 'PARAMETER_INVALID') {
-		const errorTextList = Object.keys(res.data.data).map(key => {
-			return res.data.data[key]
-		})
-		uni.showToast({
-			title: errorTextList.join(','),
-			icon: 'none'
-		})
-		return res.data
-	}
-	// 访问资源异常
-	if (code === 'UNAVAILABLE') {
-		uni.showToast({
-			title: `${message ? message :'访问资源不可用'}`,
-			icon: 'none'
-		})
-		return
-	}
-	// 未登录
-	if (code === 'UNAUTHORIZED') {
-		uni.navigateTo({
-			url: '/pages/login/index'
-		})
-		return res.data
-	}
-	// 身份切换
-	if (code === 'SCOPE_CHANGED') {
-		uni.reLaunch({
-			url: '/pages/login/index'
-		})
-		uni.showToast({
-			title: '您的身份信息已切换',
-			icon: 'none',
-		})
-		return res.data
-	}
-	if (code === 'TOKEN_CHANGED') {
-		uni.showModal({
-			title: '提示',
-			content: res.data.messsage,
-			showCancel: false,
-			success: (res) => {
-				if (res.confirm) {
-					// 小程序用户跳转到我的页面 , 登录状态为未登录
-
-				}
-			}
-		})
-		return res.data
-	}
-	// token过期处理
-	if (code === 'TOKEN_EXPIRED' && !isRefreshRequest(res.config)) {
-		// 刷新token
-		const isSuccess = await refreshToken()
-		if (isSuccess) {
-			// 重新请求
-			instance.config.headers.authorization = `Bearer ${getAccessToken()}`
-			const resp = await instance.request(res.config)
-			return resp
-		} else {
-			// 无权限
-			store.commit('SET_ACCESS_TOKEN', '')
-			store.commit('SET_REFRESH_TOKEN', '')
-			uni.showModal({
-				title: '提示',
-				content: "您的登录信息已过期,请重新登录",
-				showCancel: false,
-				success: (res) => {
-					uni.navigateTo({
-						url: '/pages/login/index'
-					})
-				}
-			})
-			return res.data
-		}
-
-	}
-	return res.data
-}, (err) => {
-	console.log("->", err)
-	uni.hideLoading()
+instance.interceptors.request.use(config => {
+  uni.showLoading({
+    title: '加载中',
+  });
+  // 带上token 和其他请求头信息
+  if (store.getters.accessToken) {
+    config.headers['Authorization'] = `Bearer ${getAccessToken()}`;
+  }
+  console.log('@@@@config', config);
+  config.headers = {
+    ...config.headers,
+    platform: store.getters.app.system.osName.toUpperCase(),
+    terminal: 'APPLET', // TODO:
+    version: store.getters.app.system.appVersion.toUpperCase(),
+    // scope: store.getters.scope,
+    device: store.getters.app.system.deviceId,
+    timestamp: new Date().getTime(),
+  };
+  return config;
 });
 
+instance.interceptors.response.use(
+  async res => {
+    uni.hideLoading();
+    const { code, data, message } = res.data;
+    if (data && data.accessToken) {
+      setAccessToken(data.accessToken);
+    }
+    if (data && data.refreshToken) {
+      setRefreshToken(data.refreshToken);
+    }
+    // 未知错误
+    if (code === 'ERROR') {
+      uni.showToast({
+        title: `${message ? message : '未知错误'}`,
+        icon: 'none',
+      });
+      return res.data;
+    }
+    // 请求错误
+    if (code === 'BAD_REQUEST') {
+      uni.showToast({
+        title: `${message ? message : '请求异常'}`,
+        icon: 'none',
+      });
+      return res.data;
+    }
+    // 拒绝访问
+    if (code === 'FORBIDDEN') {
+      uni.showToast({
+        title: `${message ? message : '拒绝访问'}`,
+        icon: 'none',
+      });
+      return;
+    }
+    // 请求参数异常
+    if (code === 'PARAMETER_INVALID') {
+      const errorTextList = Object.keys(res.data.data).map(key => {
+        return res.data.data[key];
+      });
+      uni.showToast({
+        title: errorTextList.join(','),
+        icon: 'none',
+      });
+      return res.data;
+    }
+    // 访问资源异常
+    if (code === 'UNAVAILABLE') {
+      uni.showToast({
+        title: `${message ? message : '访问资源不可用'}`,
+        icon: 'none',
+      });
+      return;
+    }
+    // 未登录
+    if (code === 'UNAUTHORIZED') {
+      uni.navigateTo({
+        url: '/pages/login/index',
+      });
+      return res.data;
+    }
+    // 身份切换
+    if (code === 'SCOPE_CHANGED') {
+      uni.reLaunch({
+        url: '/pages/login/index',
+      });
+      uni.showToast({
+        title: '您的身份信息已切换',
+        icon: 'none',
+      });
+      return res.data;
+    }
+    if (code === 'TOKEN_CHANGED') {
+      uni.showModal({
+        title: '提示',
+        content: res.data.messsage,
+        showCancel: false,
+        success: res => {
+          if (res.confirm) {
+            // 小程序用户跳转到我的页面 , 登录状态为未登录
+          }
+        },
+      });
+      return res.data;
+    }
+    // token过期处理
+    if (code === 'TOKEN_EXPIRED' && !isRefreshRequest(res.config)) {
+      // 刷新token
+      const isSuccess = await refreshToken();
+      if (isSuccess) {
+        // 重新请求
+        instance.config.headers.authorization = `Bearer ${getAccessToken()}`;
+        const resp = await instance.request(res.config);
+        return resp;
+      } else {
+        // 无权限
+        store.commit('SET_ACCESS_TOKEN', '');
+        store.commit('SET_REFRESH_TOKEN', '');
+        uni.showModal({
+          title: '提示',
+          content: '您的登录信息已过期,请重新登录',
+          showCancel: false,
+          success: res => {
+            uni.navigateTo({
+              url: '/pages/login/index',
+            });
+          },
+        });
+        return res.data;
+      }
+    }
+    return res.data;
+  },
+  err => {
+    console.log('->', err);
+    uni.hideLoading();
+  },
+);
+
 export default instance;