Przeglądaj źródła

Merge branch 'master' of http://115.29.66.169:10080/Fly/yicangzongtai_app_240321

chengziding 1 rok temu
rodzic
commit
7dd80475b2

+ 142 - 101
common/request/index-yg.js

@@ -1,7 +1,7 @@
 /* eslint-disable */
 import Request from './request';
 import {
-  refreshToken
+	refreshToken
 } from '@/api/login';
 import indexConfig from '@/config/global.config.js';
 import mUtil from '@/common/util.js';
@@ -9,122 +9,163 @@ import store from '@/store';
 
 const yghttp = new Request();
 
+const debug_token =
+	"eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJ5Y184NjAzNDg2NyIsInVzZXJfaWQiOjEyLCJtb2JpbGUiOiIxMzQzNzEwNDgxMiIsIm5pY2tuYW1lIjoieWNfODYwMzQ4NjciLCJleHAiOjE3NDE0MDM3MDcsImlhdCI6MTcwOTg2NzcwN30.LwHRcGuKyUV9S4o_cW0QhqO9KYY6L-AW6d1nMzDLCCjDLyEsdHj1Us2EbVqEJgx1Wut-hjIDqZw0iwwszsW_Kw"
+
+
 // request全局参数设置
 yghttp.setConfig(config => {
-  /* 设置全局配置 */
-  config.baseUrl = indexConfig.baseUrl; /* 根域名不同 */
-  const systemInfo = uni.getSystemInfoSync();
-  const systemInfoHeaders = {
-    'device-name': systemInfo.brand, // 设备名称
-    width: systemInfo.screenWidth, // 屏幕宽度
-    height: systemInfo.screenHeight, // 屏幕高度
-    os: systemInfo.platform, // 客户端平台
-    'os-version': systemInfo.system // 操作系统版本
-  };
-  config.header = {
-    ...config.header,
-    ...systemInfoHeaders
-  };
-  return config;
+	/* 设置全局配置 */
+	config.baseUrl = indexConfig.baseUrl; /* 根域名不同 */
+	const systemInfo = uni.getSystemInfoSync();
+	const systemInfoHeaders = {
+		'device-name': systemInfo.brand, // 设备名称
+		width: systemInfo.screenWidth, // 屏幕宽度
+		height: systemInfo.screenHeight, // 屏幕高度
+		os: systemInfo.platform, // 客户端平台
+		'os-version': systemInfo.system // 操作系统版本
+	};
+	config.header = {
+		...config.header,
+		...systemInfoHeaders
+	};
+	return config;
 });
 
 let isRefreshing = false;
 let requests = [];
-yghttp.interceptor.request(
-  config => {
 
-    if (config.isToken == false) {
+let goLogin = false;
+
+const onLogin = (msg) => {
+	if (goLogin) return;
+	goLogin = true
+	const pages = getCurrentPages();
+	const route = pages[pages.length - 1].route;
+	console.log('ro = ', route)
+	if (!route || route !== 'pages/login/index') {
+		try {
+			mUtil.toast(msg);
+			uni.removeStorageSync('apiToken');
+			// uni.removeStorageSync('shop')
+			setTimeout(() => {
+				uni.navigateTo({
+					url: '/pages/login/index',
+					success: res => {
+						goLogin = false;
+					}
+				})
+			}, 500)
+		} catch (e) {
+			//TODO handle the exception
+			goLogin = false;
+		}
+	} else {
+		goLogin = false;
+	};
+}
+
+
+yghttp.interceptor.request(
+	config => {
+		if (config.url === '/activity/lottery') {
+			// 设置点击抽奖的接口时间
+			config.timeout = 5000
+		}
+		if (config.isToken == false) {
 
-    } else {
-      config.header['apiToken'] = uni.getStorageSync('apiToken');
-    }
-    /* 请求之前拦截器 */
+		} else {
+			config.header['apiToken'] = uni.getStorageSync('apiToken');
+		}
+		/* 请求之前拦截器 */
 
-    // config.header['client'] = 'applet';
-    config.header['client'] = 'app';
-    // 单商户
-    // config.header['merchant-id'] = uni.getStorageSync('merchantId') || 1;
-    return config;
-  },
-  error => {
-    return Promise.reject(error);
-  }
+		// config.header['client'] = 'applet';
+		config.header['client'] = 'app';
+		// 单商户
+		// config.header['merchant-id'] = uni.getStorageSync('merchantId') || 1;
+		return config;
+	},
+	error => {
+		return Promise.reject(error);
+	}
 );
 
 // 刷新refreshToken
 async function handleRefreshToken(refresh_token) {
-  const params = {};
-  params.group = mUtil.platformGroupFilter();
-  params.refresh_token = refresh_token;
-  await http.post(refreshToken, params).then(async r => {
-    store.commit('login', r.data);
-    isRefreshing = false;
-  });
+	const params = {};
+	params.group = mUtil.platformGroupFilter();
+	params.refresh_token = refresh_token;
+	await http.post(refreshToken, params).then(async r => {
+		store.commit('login', r.data);
+		isRefreshing = false;
+	});
 }
 yghttp.interceptor.response(
-  async response => {
-      if (response.header['refresh_token']) {
-        store.commit('login', response.header.refresh_token);
-        uni.setStorageSync('apiToken', response.header.refresh_token);
-      }
-      /* 请求之后拦截器 */
-      switch (response.data.code) {
-        case 200:
-          return response.data;
-        case 400:
-          mUtil.toast('错误的请求');
-          return Promise.reject(response.data.message);
-          break;
-        case 500:
-          mUtil.toast(response.data.msg);
-          return Promise.reject(response.data.msg);
-          break;
-        case 5001: 
-          mUtil.toast(response.data.msg);
-          return response.data;
-        case 100001:
-          mUtil.toast(response.data.msg);
-          uni.removeStorageSync('apiToken');
-          // uni.removeStorageSync('shop')
-          setTimeout(() => {
-            uni.navigateTo({
-              url: '/pages/login/index'
-            })
-          }, 500)
-          return false
-        case 100004:
-          mUtil.toast(response.data.msg);
-          uni.removeStorageSync('apiToken');
-          // uni.removeStorageSync('shop')
-          setTimeout(() => {
-            uni.navigateTo({
-              url: '/pages/login/index'
-            })
-          }, 500)
-          return false
-        case 100007:
-          mUtil.toast(response.data.msg);
-          setTimeout(() => {
-			  let pages = getCurrentPages();
-			  let currentPage = pages[pages.length - 1];
-			  let url = currentPage.route; // 当前页面路径
-			  if(url!='pages/government/realAttestation'){
-				  uni.navigateTo({
-				    url: '/pages/government/realAttestation'
-				  })
-			  }
-          }, 500)
-          return false
-        default:
-          mUtil.toast(response.data.msg);
-          return Promise.reject(response.data.msg);
-      }
-    },
-    error => {
-      return Promise.reject(error);
-    }
+	async response => {
+			if (response.header['refresh_token']) {
+				store.commit('login', response.header.refresh_token);
+				uni.setStorageSync('apiToken', response.header.refresh_token);
+			}
+			/* 请求之后拦截器 */
+			switch (response.data.code) {
+				case 200:
+					return response.data;
+				case 400:
+					mUtil.toast('错误的请求');
+					return Promise.reject(response.data.message);
+					break;
+				case 500:
+					mUtil.toast(response.data.msg);
+					return Promise.reject(response.data.msg);
+					break;
+				case 5001:
+					mUtil.toast(response.data.msg);
+					return response.data;
+				case 100001:
+					onLogin(response.data.msg)
+					// mUtil.toast(response.data.msg);
+					// uni.removeStorageSync('apiToken');
+					// // uni.removeStorageSync('shop')
+					// setTimeout(() => {
+					// 	uni.navigateTo({
+					// 		url: '/pages/login/index'
+					// 	})
+					// }, 500)
+					return false
+				case 100004:
+					onLogin(response.data.msg)
+					// mUtil.toast(response.data.msg);
+					// uni.removeStorageSync('apiToken');
+					// // uni.removeStorageSync('shop')
+					// setTimeout(() => {
+					// 	uni.navigateTo({
+					// 		url: '/pages/login/index'
+					// 	})
+					// }, 500)
+					return false
+				case 100007:
+					mUtil.toast(response.data.msg);
+					setTimeout(() => {
+						let pages = getCurrentPages();
+						let currentPage = pages[pages.length - 1];
+						let url = currentPage.route; // 当前页面路径
+						if (url != 'pages/government/realAttestation') {
+							uni.navigateTo({
+								url: '/pages/government/realAttestation'
+							})
+						}
+					}, 500)
+					return false
+				default:
+					mUtil.toast(response.data.msg);
+					return Promise.reject(response.data.msg);
+			}
+		},
+		error => {
+			return Promise.reject(error);
+		}
 );
 
 export {
-  yghttp
+	yghttp
 };

BIN
static/font/yige/iconfont.ttf


BIN
static/font/yige/iconfont.woff


BIN
static/font/yige/iconfont.woff2


+ 127 - 1
utils/tool.js

@@ -1,3 +1,10 @@
+// import SparkMD5, {
+// 	hash
+// } from 'spark-md5'
+import $mConfig from '@/config/global.config.js';
+
+
+
 export const getPhotograph = () => {
 	uni.chooseImage({
 		count: 6, //默认9
@@ -64,9 +71,128 @@ export const getPhotograph = () => {
 
 export const distanceCalculate = (num) => {
 	if (num < 1000) {
-		return `${num}米`
+		return `${num.toFixed(1)}米`
 	} else {
 		const n = (num / 1000).toFixed(1);
 		return `${n}公里`
 	};
+}
+
+export const uploadImage = (num = 1, type = 'img') => {
+
+	return new Promise(async (resolve, reject) => {
+		console.log('uploadImage  = ', num)
+		// // #ifdef APP-PLUS
+		// let flag = await permision.showAuthTipModal("android.permission.READ_EXTERNAL_STORAGE")
+		// reject()
+		// if (!flag) return
+		// // #endif
+		// console.log('uploadImage  =  2 ', num)
+		uni.chooseImage({
+			count: num,
+			sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
+			sourceType: ['album'], //从相册选择
+			crop: {
+				quality: 100, // 图片裁剪质量
+				width: 100, // 裁剪的宽度
+				height: 100, //裁剪的高度
+				resize: false //是否将width和height作为裁剪保存图片真实的像素值。默认值为true。注:设置为false时在裁剪编辑界面显示图片的像素值,设置为true时不显示
+			},
+			success: (res) => {
+				// 选中的文件对象
+				const FilePaths = res.tempFilePaths;
+				// 记录失败的个数
+				let failNum = 0;
+				// 上传成功返回的媒体资源
+				const successArr = []
+				uni.showLoading({
+					title: '上传中',
+					mask: true
+				});
+				FilePaths.forEach(el => {
+					SingleFileUpload(el).then(res => {
+						successArr.push(res.url)
+						if ((successArr.length + failNum) >=
+							FilePaths
+							.length) {
+							uni.hideLoading();
+							uni.showToast({
+								title: '上传成功',
+								icon: 'success',
+								duration: 1000
+							})
+							resolve(successArr)
+						}
+					}).catch(err => {
+						failNum++
+					})
+				})
+
+			},
+			complete: () => {
+				uni.hideLoading();
+			}
+		})
+	})
+}
+
+
+export const SingleFileUpload = (file, showLoading = false) => {
+	return new Promise((resolve, reject) => {
+		if (showLoading) {
+			uni.showLoading({
+				title: '上传中',
+				mask: true
+			});
+		}
+		uni.uploadFile({
+			url: $mConfig.baseUrl + '/common/upload',
+			filePath: file,
+			name: 'file',
+			success: (uploadFileRes) => {
+				const data = JSON.parse(uploadFileRes.data)
+					.data;
+				resolve(data)
+
+
+			},
+			fail(fail) {
+				reject()
+				// if ((successArr.length + failNum) >= FilePaths
+				// 	.length) {
+				// 	uni.hideLoading();
+				// }
+			},
+			complete: () => {
+				if (showLoading) {
+					uni.hideLoading();
+				}
+			}
+		})
+	})
+}
+
+
+
+export const getLocation = async () => {
+	// // #ifdef APP-PLUS
+	// let flag = await permision.showAuthTipModal("android.permission.ACCESS_FINE_LOCATION")
+	// if (!flag) return
+	// // #endif
+	return new Promise((resolve, reject) => {
+
+		uni.getLocation({
+			type: 'gcj02',
+			geocode: true,
+			cacheTimeout: 30 * 60,
+			success: res => {
+				console.log('getLocation 666 = ', res)
+				resolve(res)
+			},
+			fail: err => {
+				permision.showManualAuth("android.permission.ACCESS_FINE_LOCATION")
+				return resolve(null)
+			},
+		});
+	})
 }