瀏覽代碼

no message

张保健 3 年之前
父節點
當前提交
02777a923f
共有 26 個文件被更改,包括 2035 次插入0 次删除
  1. 277 0
      pages/goods_search/index.vue
  2. 二進制
      static/images/support.png
  3. 二進制
      static/images/svip (1).gif
  4. 二進制
      static/images/svip.gif
  5. 二進制
      static/images/svip.png
  6. 二進制
      static/images/three.png
  7. 二進制
      static/images/time.png
  8. 二進制
      static/images/two.png
  9. 二進制
      static/images/up.png
  10. 二進制
      static/images/vacancy.png
  11. 二進制
      static/images/value.jpg
  12. 二進制
      static/images/vip.png
  13. 二進制
      static/images/writeOff.jpg
  14. 二進制
      static/images/written.png
  15. 二進制
      static/img/live-logo.gif
  16. 16 0
      store/getters.js
  17. 13 0
      store/index.js
  18. 110 0
      utils/SubscribeMessage.js
  19. 1 0
      utils/dialog.js
  20. 62 0
      utils/emoji.js
  21. 81 0
      utils/index.js
  22. 245 0
      utils/permission.js
  23. 55 0
      utils/request.js
  24. 549 0
      utils/util-备份.js
  25. 596 0
      utils/util.js
  26. 30 0
      utils/validate.js

+ 277 - 0
pages/goods_search/index.vue 查看文件

@@ -0,0 +1,277 @@
1
+<template>
2
+	<view>
3
+		<view class='searchGood'>
4
+			<view class='search acea-row row-between-wrapper'>
5
+				<view class='input acea-row row-between-wrapper'>
6
+					<text class='iconfont icon-sousuo2'></text>
7
+					<input type='text' v-model='searchValue' @confirm="inputConfirm" confirm-type="search" focus placeholder='点击搜索商品'
8
+					 placeholder-class='placeholder' @input="setValue"></input>
9
+				</view>
10
+				<view class='bnt' @tap='searchBut'>搜索</view>
11
+			</view>
12
+			<template v-if="history.length">
13
+				<view class='title acea-row row-between-wrapper'>
14
+					<view>搜索历史</view>
15
+					<view class="iconfont icon-shanchu" @click="clear"></view>
16
+				</view>
17
+				<view class='list acea-row'>
18
+					<block v-for="(item,index) in history" :key="index">
19
+						<view class='item history-item' @tap='setHotSearchValue(item.keyword)' v-if="item.keyword">{{item.keyword}}</view>
20
+					</block>
21
+				</view>
22
+			</template>
23
+			<view class='title'>热门搜索</view>
24
+			<view class='list acea-row'>
25
+				<block v-for="(item,index) in hotSearchList" :key="index">
26
+					<view class='item' @tap='setHotSearchValue(item.val)' v-if="item.val">{{item.val}}</view>
27
+				</block>
28
+			</view>
29
+			<view class='line'></view>
30
+			<goodList :bastList="bastList" v-if="bastList.length > 0"></goodList>
31
+			<view class='loadingicon acea-row row-center-wrapper' v-if="bastList.length > 0">
32
+				<text class='loading iconfont icon-jiazai' :hidden='loading==false'></text>{{loadTitle}}
33
+			</view>
34
+		</view>
35
+		<view class='noCommodity'>
36
+			<view class='pictrue' v-if="bastList.length == 0">
37
+				<image src='../../static/images/noSearch.png'></image>
38
+			</view>
39
+			<recommend :hostProduct='hostProduct' v-if="bastList.length == 0 && page > 1"></recommend>
40
+		</view>
41
+	</view>
42
+</template>
43
+
44
+<script>
45
+	import {
46
+		getSearchKeyword,
47
+		getProductslist,
48
+		getProductHot
49
+	} from '@/api/store.js';
50
+	import {
51
+		searchList,
52
+		clearSearch
53
+	} from '@/api/api.js';
54
+	import goodList from '@/components/goodList';
55
+	import recommend from '@/components/recommend';
56
+	export default {
57
+		components: {
58
+			goodList,
59
+			recommend
60
+		},
61
+		data() {
62
+			return {
63
+				hostProduct: [],
64
+				searchValue: '',
65
+				focus: true,
66
+				bastList: [],
67
+				hotSearchList: [],
68
+				first: 0,
69
+				limit: 8,
70
+				page: 1,
71
+				loading: false,
72
+				loadend: false,
73
+				loadTitle: '加载更多',
74
+				hotPage: 1,
75
+				isScroll: true,
76
+				history: []
77
+			};
78
+		},
79
+		onShow: function() {
80
+			// this.getRoutineHotSearch();
81
+			this.getHostProduct();
82
+			this.searchList();
83
+			try {
84
+				this.hotSearchList = uni.getStorageSync('hotList');
85
+			} catch (err) {}
86
+		},
87
+		onReachBottom: function() {
88
+			if (this.bastList.length > 0) {
89
+				this.getProductList();
90
+			} else {
91
+				this.getHostProduct();
92
+			}
93
+
94
+		},
95
+		methods: {
96
+			searchList() {
97
+				searchList({
98
+					page: 1,
99
+					limit: 10
100
+				}).then(res => {
101
+					this.history = res.data;
102
+				});
103
+			},
104
+			clear() {
105
+				let that = this;
106
+				clearSearch().then(res => {
107
+					uni.showToast({
108
+						title: res.msg,
109
+						success() {
110
+							that.history = [];
111
+						}
112
+					});
113
+				});
114
+			},
115
+			inputConfirm: function(event) {
116
+				if (event.detail.value) {
117
+					uni.hideKeyboard();
118
+					this.setHotSearchValue(event.detail.value);
119
+				}
120
+			},
121
+			getRoutineHotSearch: function() {
122
+				let that = this;
123
+				getSearchKeyword().then(res => {
124
+					that.$set(that, 'hotSearchList', res.data);
125
+				});
126
+			},
127
+			getProductList: function() {
128
+				let that = this;
129
+				if (that.loadend) return;
130
+				if (that.loading) return;
131
+				that.loading = true;
132
+				that.loadTitle = '';
133
+				getProductslist({
134
+					keyword: that.searchValue,
135
+					page: that.page,
136
+					limit: that.limit
137
+				}).then(res => {
138
+					let list = res.data,
139
+						loadend = list.length < that.limit;
140
+					that.bastList = that.$util.SplitArray(list, that.bastList);
141
+					that.$set(that, 'bastList', that.bastList);
142
+					that.loading = false;
143
+					that.loadend = loadend;
144
+					that.loadTitle = loadend ? "😕人家是有底线的~~" : "加载更多";
145
+					that.page = that.page + 1;
146
+				}).catch(err => {
147
+					that.loading = false,
148
+						that.loadTitle = '加载更多'
149
+				});
150
+			},
151
+			getHostProduct: function() {
152
+				let that = this;
153
+				if (!this.isScroll) return
154
+				getProductHot(that.hotPage, that.limit).then(res => {
155
+					that.isScroll = res.data.length >= that.limit
156
+					that.hostProduct = that.hostProduct.concat(res.data)
157
+					that.hotPage += 1;
158
+				});
159
+			},
160
+			setHotSearchValue: function(event) {
161
+				this.$set(this, 'searchValue', event);
162
+				this.page = 1;
163
+				this.loadend = false;
164
+				this.$set(this, 'bastList', []);
165
+				this.getProductList();
166
+			},
167
+			setValue: function(event) {
168
+				this.$set(this, 'searchValue', event.detail.value);
169
+			},
170
+			searchBut: function() {
171
+				let that = this;
172
+				that.focus = false;
173
+				if (that.searchValue.length > 0) {
174
+					that.page = 1;
175
+					that.loadend = false;
176
+					that.$set(that, 'bastList', []);
177
+					uni.showLoading({
178
+						title: '正在搜索中'
179
+					});
180
+					that.getProductList();
181
+					uni.hideLoading();
182
+				} else {
183
+					return this.$util.Tips({
184
+						title: '请输入要搜索的商品',
185
+						icon: 'none',
186
+						duration: 1000,
187
+						mask: true,
188
+					});
189
+				}
190
+			}
191
+		}
192
+	}
193
+</script>
194
+
195
+<style lang="scss">
196
+	page {
197
+		background-color: #fff !important;
198
+	}
199
+
200
+	.searchGood .search {
201
+		padding-left: 30rpx;
202
+	}
203
+
204
+	.searchGood .search {
205
+		margin-top: 20rpx;
206
+	}
207
+
208
+	.searchGood .search .input {
209
+		width: 598rpx;
210
+		background-color: #f7f7f7;
211
+		border-radius: 33rpx;
212
+		padding: 0 35rpx;
213
+		box-sizing: border-box;
214
+		height: 66rpx;
215
+	}
216
+
217
+	.searchGood .search .input input {
218
+		width: 472rpx;
219
+		font-size: 28rpx;
220
+	}
221
+
222
+	.searchGood .search .input .placeholder {
223
+		color: #bbb;
224
+	}
225
+
226
+	.searchGood .search .input .iconfont {
227
+		color: #000;
228
+		font-size: 35rpx;
229
+	}
230
+
231
+	.searchGood .search .bnt {
232
+		width: 120rpx;
233
+		text-align: center;
234
+		height: 66rpx;
235
+		line-height: 66rpx;
236
+		font-size: 30rpx;
237
+		color: #282828;
238
+	}
239
+
240
+	.searchGood .title {
241
+		font-size: 28rpx;
242
+		color: #999;
243
+		margin: 50rpx 30rpx 25rpx 30rpx;
244
+	}
245
+
246
+	.searchGood .title .iconfont {
247
+		font-size: 28rpx;
248
+	}
249
+
250
+	.searchGood .list {
251
+		padding-left: 10rpx;
252
+	}
253
+
254
+	.searchGood .list .item {
255
+		font-size: 26rpx;
256
+		color: #454545;
257
+		padding: 0 21rpx;
258
+		height: 60rpx;
259
+		border-radius: 3rpx;
260
+		line-height: 60rpx;
261
+		border: 1rpx solid #aaa;
262
+		margin: 0 0 20rpx 20rpx;
263
+	}
264
+
265
+	.searchGood .list .item.history-item {
266
+		height: 50rpx;
267
+		border: none;
268
+		border-radius: 25rpx;
269
+		background-color: #F7F7F7;
270
+		line-height: 50rpx;
271
+	}
272
+
273
+	.searchGood .line {
274
+		border-bottom: 1rpx solid #eee;
275
+		margin: 20rpx 30rpx 0 30rpx;
276
+	}
277
+</style>

二進制
static/images/support.png 查看文件


二進制
static/images/svip (1).gif 查看文件


二進制
static/images/svip.gif 查看文件


二進制
static/images/svip.png 查看文件


二進制
static/images/three.png 查看文件


二進制
static/images/time.png 查看文件


二進制
static/images/two.png 查看文件


二進制
static/images/up.png 查看文件


二進制
static/images/vacancy.png 查看文件


二進制
static/images/value.jpg 查看文件


二進制
static/images/vip.png 查看文件


二進制
static/images/writeOff.jpg 查看文件


二進制
static/images/written.png 查看文件


二進制
static/img/live-logo.gif 查看文件


+ 16 - 0
store/getters.js 查看文件

@@ -0,0 +1,16 @@
1
+export default {
2
+  token: state => state.app.token,
3
+  loginType: state => state.app.loginType,
4
+  isLogin: state => !!state.app.token,
5
+  backgroundColor: state => state.app.backgroundColor,
6
+  userInfo: state => state.app.userInfo || {},
7
+	uid:state => state.app.uid,
8
+	homeActive: state => state.app.homeActive,
9
+	home: state => state.app.home,
10
+};
11
+// export default {
12
+//   token: state => 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJrYWlmYS5jcm1lYi5uZXQiLCJhdWQiOiJrYWlmYS5jcm1lYi5uZXQiLCJpYXQiOjE1NzcwODM1MzQsIm5iZiI6MTU3NzA4MzUzNCwiZXhwIjoxNTc3MDk0MzM0LCJqdGkiOnsiaWQiOjExMCwidHlwZSI6InVzZXIifX0.U-i1pbdRjyXI1gr79Uq2XBPZ89T8f5Ai9jwrR8woTwE',
13
+//   isLogin: state => true,
14
+//   backgroundColor: state => state.app.backgroundColor,
15
+//   userInfo: state => state.app.userInfo || {}
16
+// };

+ 13 - 0
store/index.js 查看文件

@@ -0,0 +1,13 @@
1
+import Vue from "vue";
2
+import Vuex from "vuex";
3
+import modules from "./modules";
4
+import getters from "./getters";
5
+
6
+Vue.use(Vuex);
7
+const debug = process.env.NODE_ENV !== "production";
8
+
9
+export default new Vuex.Store({
10
+  modules,
11
+  getters,
12
+  strict: debug
13
+});

+ 110 - 0
utils/SubscribeMessage.js 查看文件

@@ -0,0 +1,110 @@
1
+import {
2
+	SUBSCRIBE_MESSAGE
3
+} from '../config/cache.js';
4
+
5
+export function auth() {
6
+	let tmplIds = {};
7
+	let messageTmplIds = uni.getStorageSync(SUBSCRIBE_MESSAGE);
8
+	tmplIds = messageTmplIds ? JSON.parse(messageTmplIds) : {};
9
+	return tmplIds;
10
+}
11
+
12
+/**
13
+ * 支付成功后订阅消息id
14
+ * 订阅  确认收货通知 订单支付成功  新订单管理员提醒 
15
+ */
16
+export function openPaySubscribe() {
17
+	let tmplIds = auth();
18
+	return subscribe([
19
+		tmplIds.oreder_takever,
20
+		tmplIds.order_pay_success,
21
+		tmplIds.order_new,
22
+	]);
23
+}
24
+
25
+/**
26
+ * 订单相关订阅消息
27
+ * 送货 发货 取消订单
28
+ */
29
+export function openOrderSubscribe() {
30
+	let tmplIds = auth();
31
+	return subscribe([
32
+		tmplIds.order_deliver_success,
33
+		tmplIds.order_postage_success,
34
+		tmplIds.order_clone
35
+	]);
36
+}
37
+
38
+/**
39
+ * 提现消息订阅
40
+ * 成功 和 失败 消息
41
+ */
42
+export function openExtrctSubscribe() {
43
+	let tmplIds = auth();
44
+	return subscribe([
45
+		tmplIds.user_extract
46
+	]);
47
+}
48
+
49
+/**
50
+ * 拼团成功
51
+ */
52
+export function openPinkSubscribe() {
53
+	let tmplIds = auth();
54
+	return subscribe([
55
+		tmplIds.pink_true
56
+	]);
57
+}
58
+
59
+/**
60
+ * 砍价成功
61
+ */
62
+export function openBargainSubscribe() {
63
+	let tmplIds = auth();
64
+	return subscribe([
65
+		tmplIds.bargain_success
66
+	]);
67
+}
68
+
69
+/**
70
+ * 订单退款
71
+ */
72
+export function openOrderRefundSubscribe() {
73
+	let tmplIds = auth();
74
+	return subscribe([tmplIds.order_refund]);
75
+}
76
+
77
+/**
78
+ * 充值成功
79
+ */
80
+export function openRechargeSubscribe() {
81
+	let tmplIds = auth();
82
+	return subscribe([tmplIds.recharge_success]);
83
+}
84
+
85
+/**
86
+ * 提现
87
+ */
88
+export function openEextractSubscribe() {
89
+	let tmplIds = auth();
90
+	return subscribe([tmplIds.user_extract]);
91
+}
92
+
93
+/**
94
+ * 调起订阅界面
95
+ * array tmplIds 模板id
96
+ */
97
+export function subscribe(tmplIds) {
98
+	 let wecaht = wx;
99
+	return new Promise((reslove, reject) => {
100
+		wecaht.requestSubscribeMessage({
101
+			tmplIds: tmplIds,
102
+			success(res) {
103
+				return reslove(res);
104
+			},
105
+			fail(res) {
106
+				return reslove(res);
107
+			}
108
+		})
109
+	});
110
+}

+ 1 - 0
utils/dialog.js 查看文件

@@ -0,0 +1 @@
1
+

+ 62 - 0
utils/emoji.js 查看文件

@@ -0,0 +1,62 @@
1
+export default [
2
+  "em-smile",
3
+  "em-laughing",
4
+  "em-blush",
5
+  "em-smiley",
6
+  "em-relaxed",
7
+  "em-smirk",
8
+  "em-heart_eyes",
9
+  "em-kissing_heart",
10
+  "em-kissing_closed_eyes",
11
+  "em-flushed",
12
+  "em-relieved",
13
+  "em-satisfied",
14
+  "em-grin",
15
+  "em-wink",
16
+  "em-stuck_out_tongue_winking_eye",
17
+  "em-stuck_out_tongue_closed_eyes",
18
+  "em-grinning",
19
+  "em-kissing",
20
+  "em-kissing_smiling_eyes",
21
+  "em-stuck_out_tongue",
22
+  "em-sleeping",
23
+  "em-worried",
24
+  "em-frowning",
25
+  "em-anguished",
26
+  "em-open_mouth",
27
+  "em-grimacing",
28
+  "em-confused",
29
+  "em-hushed",
30
+  "em-expressionless",
31
+  "em-unamused",
32
+  "em-sweat_smile",
33
+  "em-sweat",
34
+  "em-disappointed_relieved",
35
+  "em-weary",
36
+  "em-pensive",
37
+  "em-disappointed",
38
+  "em-confounded",
39
+  "em-fearful",
40
+  "em-cold_sweat",
41
+  "em-persevere",
42
+  "em-cry",
43
+  "em-sob",
44
+  "em-joy",
45
+  "em-astonished",
46
+  "em-scream",
47
+  "em-tired_face",
48
+  "em-angry",
49
+  "em-rage",
50
+  "em-triumph",
51
+  "em-sleepy",
52
+  "em-yum",
53
+  "em-mask",
54
+  "em-sunglasses",
55
+  "em-dizzy_face",
56
+  "em-imp",
57
+  "em-smiling_imp",
58
+  "em-neutral_face",
59
+  "em-no_mouth",
60
+  "em-innocent",
61
+  "em-alien"
62
+];

+ 81 - 0
utils/index.js 查看文件

@@ -0,0 +1,81 @@
1
+import { spread } from "@/api/user";
2
+import Cache from "@/utils/cache";
3
+
4
+/**
5
+ * 绑定用户授权
6
+ * @param {Object} puid
7
+ */
8
+export function silenceBindingSpread()
9
+{
10
+	
11
+	
12
+	//#ifdef H5
13
+	let puid = Cache.get('spread'),code = 0;
14
+	//#endif
15
+	
16
+	//#ifdef MP
17
+	let puid = getApp().globalData.spid,code = getApp().globalData.code;
18
+	//#endif
19
+	
20
+	puid = parseInt(puid);
21
+	if(Number.isNaN(puid)){
22
+		puid = 0;
23
+	}
24
+	if(puid){
25
+		spread({puid,code}).then(res=>{
26
+			console.log(res);
27
+			//#ifdef H5
28
+			 Cache.clear('spread');
29
+			//#endif
30
+			
31
+			//#ifdef MP
32
+			 getApp().globalData.spid = 0;
33
+			 getApp().globalData.code = 0;
34
+			//#endif
35
+			
36
+		}).catch(res=>{
37
+			console.log(res);
38
+		});
39
+	}
40
+}
41
+
42
+export function isWeixin() {
43
+  return navigator.userAgent.toLowerCase().indexOf("micromessenger") !== -1;
44
+}
45
+
46
+export function parseQuery() {
47
+  const res = {};
48
+
49
+  const query = (location.href.split("?")[1] || "")
50
+    .trim()
51
+    .replace(/^(\?|#|&)/, "");
52
+
53
+  if (!query) {
54
+    return res;
55
+  }
56
+
57
+  query.split("&").forEach(param => {
58
+    const parts = param.replace(/\+/g, " ").split("=");
59
+    const key = decodeURIComponent(parts.shift());
60
+    const val = parts.length > 0 ? decodeURIComponent(parts.join("=")) : null;
61
+
62
+    if (res[key] === undefined) {
63
+      res[key] = val;
64
+    } else if (Array.isArray(res[key])) {
65
+      res[key].push(val);
66
+    } else {
67
+      res[key] = [res[key], val];
68
+    }
69
+  });
70
+
71
+  return res;
72
+}
73
+
74
+// #ifdef H5
75
+	const VUE_APP_WS_URL = process.env.VUE_APP_WS_URL || `ws://${location.hostname}:20003`;
76
+	export {VUE_APP_WS_URL}
77
+// #endif
78
+
79
+
80
+
81
+export default parseQuery;

+ 245 - 0
utils/permission.js 查看文件

@@ -0,0 +1,245 @@
1
+/// null = 未请求,1 = 已允许,0 = 拒绝|受限, 2 = 系统未开启
2
+
3
+var isIOS
4
+
5
+function album() {
6
+    var result = 0;
7
+    var PHPhotoLibrary = plus.ios.import("PHPhotoLibrary");
8
+    var authStatus = PHPhotoLibrary.authorizationStatus();
9
+    if (authStatus === 0) {
10
+        result = null;
11
+    } else if (authStatus == 3) {
12
+        result = 1;
13
+    } else {
14
+        result = 0;
15
+    }
16
+    plus.ios.deleteObject(PHPhotoLibrary);
17
+    return result;
18
+}
19
+
20
+function camera() {
21
+    var result = 0;
22
+    var AVCaptureDevice = plus.ios.import("AVCaptureDevice");
23
+    var authStatus = AVCaptureDevice.authorizationStatusForMediaType('vide');
24
+    if (authStatus === 0) {
25
+        result = null;
26
+    } else if (authStatus == 3) {
27
+        result = 1;
28
+    } else {
29
+        result = 0;
30
+    }
31
+    plus.ios.deleteObject(AVCaptureDevice);
32
+    return result;
33
+}
34
+
35
+function location() {
36
+    var result = 0;
37
+    var cllocationManger = plus.ios.import("CLLocationManager");
38
+    var enable = cllocationManger.locationServicesEnabled();
39
+    var status = cllocationManger.authorizationStatus();
40
+    if (!enable) {
41
+        result = 2;
42
+    } else if (status === 0) {
43
+        result = null;
44
+    } else if (status === 3 || status === 4) {
45
+        result = 1;
46
+    } else {
47
+        result = 0;
48
+    }
49
+    plus.ios.deleteObject(cllocationManger);
50
+    return result;
51
+}
52
+
53
+function push() {
54
+    var result = 0;
55
+    var UIApplication = plus.ios.import("UIApplication");
56
+    var app = UIApplication.sharedApplication();
57
+    var enabledTypes = 0;
58
+    if (app.currentUserNotificationSettings) {
59
+        var settings = app.currentUserNotificationSettings();
60
+        enabledTypes = settings.plusGetAttribute("types");
61
+        if (enabledTypes == 0) {
62
+            result = 0;
63
+            console.log("推送权限没有开启");
64
+        } else {
65
+            result = 1;
66
+            console.log("已经开启推送功能!")
67
+        }
68
+        plus.ios.deleteObject(settings);
69
+    } else {
70
+        enabledTypes = app.enabledRemoteNotificationTypes();
71
+        if (enabledTypes == 0) {
72
+            result = 3;
73
+            console.log("推送权限没有开启!");
74
+        } else {
75
+            result = 4;
76
+            console.log("已经开启推送功能!")
77
+        }
78
+    }
79
+    plus.ios.deleteObject(app);
80
+    plus.ios.deleteObject(UIApplication);
81
+    return result;
82
+}
83
+
84
+function contact() {
85
+    var result = 0;
86
+    var CNContactStore = plus.ios.import("CNContactStore");
87
+    var cnAuthStatus = CNContactStore.authorizationStatusForEntityType(0);
88
+    if (cnAuthStatus === 0) {
89
+        result = null;
90
+    } else if (cnAuthStatus == 3) {
91
+        result = 1;
92
+    } else {
93
+        result = 0;
94
+    }
95
+    plus.ios.deleteObject(CNContactStore);
96
+    return result;
97
+}
98
+
99
+function record() {
100
+    var result = null;
101
+    var avaudiosession = plus.ios.import("AVAudioSession");
102
+    var avaudio = avaudiosession.sharedInstance();
103
+    var status = avaudio.recordPermission();
104
+    console.log("permissionStatus:" + status);
105
+    if (status === 1970168948) {
106
+        result = null;
107
+    } else if (status === 1735552628) {
108
+        result = 1;
109
+    } else {
110
+        result = 0;
111
+    }
112
+    plus.ios.deleteObject(avaudiosession);
113
+    return result;
114
+}
115
+
116
+function calendar() {
117
+    var result = null;
118
+    var EKEventStore = plus.ios.import("EKEventStore");
119
+    var ekAuthStatus = EKEventStore.authorizationStatusForEntityType(0);
120
+    if (ekAuthStatus == 3) {
121
+        result = 1;
122
+        console.log("日历权限已经开启");
123
+    } else {
124
+        console.log("日历权限没有开启");
125
+    }
126
+    plus.ios.deleteObject(EKEventStore);
127
+    return result;
128
+}
129
+
130
+function memo() {
131
+    var result = null;
132
+    var EKEventStore = plus.ios.import("EKEventStore");
133
+    var ekAuthStatus = EKEventStore.authorizationStatusForEntityType(1);
134
+    if (ekAuthStatus == 3) {
135
+        result = 1;
136
+        console.log("备忘录权限已经开启");
137
+    } else {
138
+        console.log("备忘录权限没有开启");
139
+    }
140
+    plus.ios.deleteObject(EKEventStore);
141
+    return result;
142
+}
143
+
144
+
145
+function requestIOS(permissionID) {
146
+    return new Promise((resolve, reject) => {
147
+        switch (permissionID) {
148
+            case "push":
149
+                resolve(push());
150
+                break;
151
+            case "location":
152
+                resolve(location());
153
+                break;
154
+            case "record":
155
+                resolve(record());
156
+                break;
157
+            case "camera":
158
+                resolve(camera());
159
+                break;
160
+            case "album":
161
+                resolve(album());
162
+                break;
163
+            case "contact":
164
+                resolve(contact());
165
+                break;
166
+            case "calendar":
167
+                resolve(calendar());
168
+                break;
169
+            case "memo":
170
+                resolve(memo());
171
+                break;
172
+            default:
173
+                resolve(0);
174
+                break;
175
+        }
176
+    });
177
+}
178
+
179
+function requestAndroid(permissionID) {
180
+    return new Promise((resolve, reject) => {
181
+        plus.android.requestPermissions(
182
+            [permissionID],
183
+            function(resultObj) {
184
+                var result = 0;
185
+                for (var i = 0; i < resultObj.granted.length; i++) {
186
+                    var grantedPermission = resultObj.granted[i];
187
+                    console.log('已获取的权限:' + grantedPermission);
188
+                    result = 1
189
+                }
190
+                for (var i = 0; i < resultObj.deniedPresent.length; i++) {
191
+                    var deniedPresentPermission = resultObj.deniedPresent[i];
192
+                    console.log('拒绝本次申请的权限:' + deniedPresentPermission);
193
+                    result = 0
194
+                }
195
+                for (var i = 0; i < resultObj.deniedAlways.length; i++) {
196
+                    var deniedAlwaysPermission = resultObj.deniedAlways[i];
197
+                    console.log('永久拒绝申请的权限:' + deniedAlwaysPermission);
198
+                    result = -1
199
+                }
200
+                resolve(result);
201
+            },
202
+            function(error) {
203
+                console.log('result error: ' + error.message)
204
+                resolve({
205
+                    code: error.code,
206
+                    message: error.message
207
+                });
208
+            }
209
+        );
210
+    });
211
+}
212
+
213
+function gotoAppPermissionSetting() {
214
+    if (permission.isIOS) {
215
+        var UIApplication = plus.ios.import("UIApplication");
216
+        var application2 = UIApplication.sharedApplication();
217
+        var NSURL2 = plus.ios.import("NSURL");
218
+        var setting2 = NSURL2.URLWithString("app-settings:");
219
+        application2.openURL(setting2);
220
+        plus.ios.deleteObject(setting2);
221
+        plus.ios.deleteObject(NSURL2);
222
+        plus.ios.deleteObject(application2);
223
+    } else {
224
+        var Intent = plus.android.importClass("android.content.Intent");
225
+        var Settings = plus.android.importClass("android.provider.Settings");
226
+        var Uri = plus.android.importClass("android.net.Uri");
227
+        var mainActivity = plus.android.runtimeMainActivity();
228
+        var intent = new Intent();
229
+        intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
230
+        var uri = Uri.fromParts("package", mainActivity.getPackageName(), null);
231
+        intent.setData(uri);
232
+        mainActivity.startActivity(intent);
233
+    }
234
+}
235
+
236
+const permission = {
237
+    get isIOS(){
238
+        return typeof isIOS === 'boolean' ? isIOS : (isIOS = uni.getSystemInfoSync().platform === 'ios')
239
+    },
240
+    requestIOS: requestIOS,
241
+    requestAndroid: requestAndroid,
242
+    gotoAppSetting: gotoAppPermissionSetting
243
+}
244
+
245
+module.exports = permission

+ 55 - 0
utils/request.js 查看文件

@@ -0,0 +1,55 @@
1
+import { HTTP_REQUEST_URL, HEADER, TOKENNAME} from '@/config/app';
2
+import { toLogin, checkLogin } from '../libs/login';
3
+import store from '../store';
4
+
5
+
6
+/**
7
+ * 发送请求
8
+ */
9
+function baseRequest(url, method, data, {noAuth = false, noVerify = false})
10
+{
11
+  let Url = HTTP_REQUEST_URL, header = HEADER;
12
+  
13
+  if (!noAuth) {
14
+    //登录过期自动登录
15
+	if(!store.state.app.token && !checkLogin()){
16
+		toLogin();
17
+		return Promise.reject({msg:'未登陆'});
18
+	}
19
+  }
20
+  
21
+  if (store.state.app.token) header[TOKENNAME] = 'Bearer ' + store.state.app.token;
22
+
23
+  return new Promise((reslove, reject) => {
24
+    uni.request({
25
+      url: Url + '/api/' + url,
26
+      method: method || 'GET',
27
+      header: header,
28
+      data: data || {},
29
+      success: (res) => {
30
+        if (noVerify)
31
+          reslove(res.data, res);
32
+        else if (res.data.status == 200)
33
+          reslove(res.data, res);
34
+        else if ([410000, 410001, 410002].indexOf(res.data.status) !== -1) {
35
+		  toLogin();
36
+          reject(res.data);
37
+        } else
38
+          reject(res.data.msg || '系统错误');
39
+      },
40
+      fail: (msg) => {
41
+        reject('请求失败');
42
+      }
43
+    })
44
+  });
45
+}
46
+
47
+const request = {};
48
+
49
+['options', 'get', 'post', 'put', 'head', 'delete', 'trace', 'connect'].forEach((method) => {
50
+  request[method] = (api, data, opt) => baseRequest(api, method, data, opt || {})
51
+});
52
+
53
+
54
+
55
+export default request;

+ 549 - 0
utils/util-备份.js 查看文件

@@ -0,0 +1,549 @@
1
+import {
2
+ 	TOKENNAME,
3
+ 	HTTP_REQUEST_URL
4
+ } from '../config/app.js';
5
+ import store from '../store';
6
+ import {
7
+ 	pathToBase64
8
+ } from '@/plugin/image-tools/index.js';
9
+ // #ifdef APP-PLUS
10
+ import permision from "./permission.js"
11
+ // #endif
12
+ export default {
13
+ 	/**
14
+ 	 * opt  object | string
15
+ 	 * to_url object | string
16
+ 	 * 例:
17
+ 	 * this.Tips('/pages/test/test'); 跳转不提示
18
+ 	 * this.Tips({title:'提示'},'/pages/test/test'); 提示并跳转
19
+ 	 * this.Tips({title:'提示'},{tab:1,url:'/pages/index/index'}); 提示并跳转值table上
20
+ 	 * tab=1 一定时间后跳转至 table上
21
+ 	 * tab=2 一定时间后跳转至非 table上
22
+ 	 * tab=3 一定时间后返回上页面
23
+ 	 * tab=4 关闭所有页面跳转至非table上
24
+ 	 * tab=5 关闭当前页面跳转至table上
25
+ 	 */
26
+ 	Tips: function(opt, to_url) {
27
+ 		if (typeof opt == 'string') {
28
+ 			to_url = opt;
29
+ 			opt = {};
30
+ 		}
31
+ 		let title = opt.title || '',
32
+ 			icon = opt.icon || 'none',
33
+ 			endtime = opt.endtime || 2000,
34
+ 			success = opt.success;
35
+ 		if (title) uni.showToast({
36
+ 			title: title,
37
+ 			icon: icon,
38
+ 			duration: endtime,
39
+ 			success
40
+ 		})
41
+ 		if (to_url != undefined) {
42
+ 			if (typeof to_url == 'object') {
43
+ 				let tab = to_url.tab || 1,
44
+ 					url = to_url.url || '';
45
+ 				switch (tab) {
46
+ 					case 1:
47
+ 						//一定时间后跳转至 table
48
+ 						setTimeout(function() {
49
+ 							uni.switchTab({
50
+ 								url: url
51
+ 							})
52
+ 						}, endtime);
53
+ 						break;
54
+ 					case 2:
55
+ 						//跳转至非table页面
56
+ 						setTimeout(function() {
57
+ 							uni.navigateTo({
58
+ 								url: url,
59
+ 							})
60
+ 						}, endtime);
61
+ 						break;
62
+ 					case 3:
63
+ 						//返回上页面
64
+ 						setTimeout(function() {
65
+ 							// #ifndef H5
66
+ 							uni.navigateBack({
67
+ 								delta: parseInt(url),
68
+ 							})
69
+ 							// #endif
70
+ 							// #ifdef H5
71
+ 							history.back();
72
+ 							// #endif
73
+ 						}, endtime);
74
+ 						break;
75
+ 					case 4:
76
+ 						//关闭当前所有页面跳转至非table页面
77
+ 						setTimeout(function() {
78
+ 							uni.reLaunch({
79
+ 								url: url,
80
+ 							})
81
+ 						}, endtime);
82
+ 						break;
83
+ 					case 5:
84
+ 						//关闭当前页面跳转至非table页面
85
+ 						setTimeout(function() {
86
+ 							uni.redirectTo({
87
+ 								url: url,
88
+ 							})
89
+ 						}, endtime);
90
+ 						break;
91
+ 				}
92
+
93
+ 			} else if (typeof to_url == 'function') {
94
+ 				setTimeout(function() {
95
+ 					to_url && to_url();
96
+ 				}, endtime);
97
+ 			} else {
98
+ 				//没有提示时跳转不延迟
99
+ 				setTimeout(function() {
100
+ 					uni.navigateTo({
101
+ 						url: to_url,
102
+ 					})
103
+ 				}, title ? endtime : 0);
104
+ 			}
105
+ 		}
106
+ 	},
107
+ 	/**
108
+ 	 * 移除数组中的某个数组并组成新的数组返回
109
+ 	 * @param array array 需要移除的数组
110
+ 	 * @param int index 需要移除的数组的键值
111
+ 	 * @param string | int 值
112
+ 	 * @return array
113
+ 	 * 
114
+ 	 */
115
+ 	ArrayRemove: function(array, index, value) {
116
+ 		const valueArray = [];
117
+ 		if (array instanceof Array) {
118
+ 			for (let i = 0; i < array.length; i++) {
119
+ 				if (typeof index == 'number' && array[index] != i) {
120
+ 					valueArray.push(array[i]);
121
+ 				} else if (typeof index == 'string' && array[i][index] != value) {
122
+ 					valueArray.push(array[i]);
123
+ 				}
124
+ 			}
125
+ 		}
126
+ 		return valueArray;
127
+ 	},
128
+ 	/**
129
+ 	 * 生成海报获取文字
130
+ 	 * @param string text 为传入的文本
131
+ 	 * @param int num 为单行显示的字节长度
132
+ 	 * @return array 
133
+ 	 */
134
+ 	textByteLength: function(text, num) {
135
+ 		let strLength = 0;
136
+ 		let rows = 1;
137
+ 		let str = 0;
138
+ 		let arr = [];
139
+ 		for (let j = 0; j < text.length; j++) {
140
+ 			if (text.charCodeAt(j) > 255) {
141
+ 				strLength += 2;
142
+ 				if (strLength > rows * num) {
143
+ 					strLength++;
144
+ 					arr.push(text.slice(str, j));
145
+ 					str = j;
146
+ 					rows++;
147
+ 				}
148
+ 			} else {
149
+ 				strLength++;
150
+ 				if (strLength > rows * num) {
151
+ 					arr.push(text.slice(str, j));
152
+ 					str = j;
153
+ 					rows++;
154
+ 				}
155
+ 			}
156
+ 		}
157
+ 		arr.push(text.slice(str, text.length));
158
+ 		return [strLength, arr, rows] //  [处理文字的总字节长度,每行显示内容的数组,行数]
159
+ 	},
160
+
161
+ 	/**
162
+ 	 * 获取分享海报
163
+ 	 * @param array arr2 海报素材
164
+ 	 * @param string store_name 素材文字
165
+ 	 * @param string price 价格
166
+ 	 * @param function successFn 回调函数
167
+ 	 * 
168
+ 	 * 
169
+ 	 */
170
+ 	PosterCanvas: function(arr2, store_name, price, successFn) {
171
+ 		let that = this;
172
+ 		uni.showLoading({
173
+ 			title: '海报生成中',
174
+ 			mask: true
175
+ 		});
176
+ 		const ctx = uni.createCanvasContext('myCanvas');
177
+ 		ctx.clearRect(0, 0, 0, 0);
178
+ 		/**
179
+ 		 * 只能获取合法域名下的图片信息,本地调试无法获取
180
+ 		 * 
181
+ 		 */
182
+ 		uni.getImageInfo({
183
+ 			src: arr2[0],
184
+ 			success: function(res) {
185
+ 				const WIDTH = res.width;
186
+ 				const HEIGHT = res.height;
187
+ 				ctx.drawImage(arr2[0], 0, 0, WIDTH, HEIGHT);
188
+ 				ctx.drawImage(arr2[1], 0, 0, WIDTH, WIDTH);
189
+ 				ctx.save();
190
+ 				let r = 90;
191
+ 				let d = r * 2;
192
+ 				let cx = 40;
193
+ 				let cy = 990;
194
+ 				ctx.arc(cx + r, cy + r, r, 0, 2 * Math.PI);
195
+ 				// ctx.clip();
196
+ 				ctx.drawImage(arr2[2], cx, cy,d,d);
197
+ 				ctx.restore();
198
+ 				const CONTENT_ROW_LENGTH = 40;
199
+ 				let [contentLeng, contentArray, contentRows] = that.textByteLength(store_name, CONTENT_ROW_LENGTH);
200
+ 				if (contentRows > 2) {
201
+ 					contentRows = 2;
202
+ 					let textArray = contentArray.slice(0, 2);
203
+ 					textArray[textArray.length - 1] += '……';
204
+ 					contentArray = textArray;
205
+ 				}
206
+ 				ctx.setTextAlign('center');
207
+ 				ctx.setFontSize(32);
208
+ 				let contentHh = 32 * 1.3;
209
+ 				for (let m = 0; m < contentArray.length; m++) {
210
+ 					ctx.fillText(contentArray[m], WIDTH / 2, 820 + contentHh * m);
211
+ 				}
212
+ 				ctx.setTextAlign('center')
213
+ 				ctx.setFontSize(48);
214
+ 				ctx.setFillStyle('red');
215
+ 				ctx.fillText('¥' + price, WIDTH / 2, 880 + contentHh);
216
+ 				ctx.draw(true, function() {
217
+ 					uni.canvasToTempFilePath({
218
+ 						canvasId: 'myCanvas',
219
+ 						fileType: 'png',
220
+ 						destWidth: WIDTH,
221
+ 						destHeight: HEIGHT,
222
+ 						success: function(res) {
223
+ 							uni.hideLoading();
224
+ 							successFn && successFn(res.tempFilePath);
225
+ 						}
226
+ 					})
227
+ 				});
228
+ 			},
229
+ 			fail: function(err) {
230
+ 				uni.hideLoading();
231
+ 				that.Tips({
232
+ 					title: '无法获取图片信息'
233
+ 				});
234
+ 			}
235
+ 		})
236
+ 	},
237
+ 	/*
238
+ 	 * 单图上传
239
+ 	 * @param object opt
240
+ 	 * @param callable successCallback 成功执行方法 data 
241
+ 	 * @param callable errorCallback 失败执行方法 
242
+ 	 */
243
+ 	uploadImageOne: function(opt, successCallback, errorCallback) {
244
+ 		let that = this;
245
+ 		if (typeof opt === 'string') {
246
+ 			let url = opt;
247
+ 			opt = {};
248
+ 			opt.url = url;
249
+ 		}
250
+ 		let count = opt.count || 1,
251
+ 			sizeType = opt.sizeType || ['compressed'],
252
+ 			sourceType = opt.sourceType || ['album', 'camera'],
253
+ 			is_load = opt.is_load || true,
254
+ 			uploadUrl = opt.url || '',
255
+ 			inputName = opt.name || 'pics';
256
+ 		uni.chooseImage({
257
+ 			count: count, //最多可以选择的图片总数  
258
+ 			sizeType: sizeType, // 可以指定是原图还是压缩图,默认二者都有  
259
+ 			sourceType: sourceType, // 可以指定来源是相册还是相机,默认二者都有  
260
+ 			success: function(res) {
261
+				console.log()
262
+ 				//启动上传等待中...  
263
+ 				uni.showLoading({
264
+ 					title: '图片上传中',
265
+ 				});
266
+				uni.uploadFile({
267
+					url: HTTP_REQUEST_URL + '/api/' + uploadUrl,
268
+					filePath: res.tempFilePaths[0],
269
+					name: inputName,
270
+					formData: {
271
+						'filename': inputName
272
+					},
273
+					header: {
274
+						// #ifdef MP
275
+						"Content-Type": "multipart/form-data",
276
+						// #endif
277
+						[TOKENNAME]: 'Bearer ' + store.state.app.token
278
+					},
279
+					success: function(res) {
280
+						uni.hideLoading();
281
+						if (res.statusCode == 403) {
282
+							that.Tips({
283
+								title: res.data
284
+							});
285
+						} else {
286
+							let data = res.data ? JSON.parse(res.data) : {};
287
+							if (data.status == 200) {
288
+								successCallback && successCallback(data)
289
+							} else {
290
+								errorCallback && errorCallback(data);
291
+								that.Tips({
292
+									title: data.msg
293
+								});
294
+							}
295
+						}
296
+					},
297
+					fail: function(res) {
298
+						uni.hideLoading();
299
+						that.Tips({
300
+							title: '上传图片失败'
301
+						});
302
+					}
303
+				})
304
+ 				// pathToBase64(res.tempFilePaths[0])
305
+ 				// 	.then(imgBase64 => {
306
+ 				// 		console.log(imgBase64);
307
+ 						
308
+ 				// 	})
309
+ 				// 	.catch(error => {
310
+ 				// 		console.error(error)
311
+ 				// 	})
312
+ 			}
313
+ 		})
314
+ 	},
315
+ 	/**
316
+ 	 * 处理服务器扫码带进来的参数
317
+ 	 * @param string param 扫码携带参数
318
+ 	 * @param string k 整体分割符 默认为:&
319
+ 	 * @param string p 单个分隔符 默认为:=
320
+ 	 * @return object
321
+ 	 * 
322
+ 	 */
323
+ 	// #ifdef MP
324
+ 	getUrlParams: function(param, k, p) {
325
+ 		if (typeof param != 'string') return {};
326
+ 		k = k ? k : '&'; //整体参数分隔符
327
+ 		p = p ? p : '='; //单个参数分隔符
328
+ 		var value = {};
329
+ 		if (param.indexOf(k) !== -1) {
330
+ 			param = param.split(k);
331
+ 			for (var val in param) {
332
+ 				if (param[val].indexOf(p) !== -1) {
333
+ 					var item = param[val].split(p);
334
+ 					value[item[0]] = item[1];
335
+ 				}
336
+ 			}
337
+ 		} else if (param.indexOf(p) !== -1) {
338
+ 			var item = param.split(p);
339
+ 			value[item[0]] = item[1];
340
+ 		} else {
341
+ 			return param;
342
+ 		}
343
+ 		return value;
344
+ 	},
345
+ 	// #endif
346
+ 	/*
347
+ 	 * 合并数组
348
+ 	 */
349
+ 	SplitArray(list, sp) {
350
+ 		if (typeof list != 'object') return [];
351
+ 		if (sp === undefined) sp = [];
352
+ 		for (var i = 0; i < list.length; i++) {
353
+ 			sp.push(list[i]);
354
+ 		}
355
+ 		return sp;
356
+ 	},
357
+ 	trim(str) {
358
+ 		return String.prototype.trim.call(str);
359
+ 	},
360
+ 	$h: {
361
+ 		//除法函数,用来得到精确的除法结果
362
+ 		//说明:javascript的除法结果会有误差,在两个浮点数相除的时候会比较明显。这个函数返回较为精确的除法结果。
363
+ 		//调用:$h.Div(arg1,arg2)
364
+ 		//返回值:arg1除以arg2的精确结果
365
+ 		Div: function(arg1, arg2) {
366
+ 			arg1 = parseFloat(arg1);
367
+ 			arg2 = parseFloat(arg2);
368
+ 			var t1 = 0,
369
+ 				t2 = 0,
370
+ 				r1, r2;
371
+ 			try {
372
+ 				t1 = arg1.toString().split(".")[1].length;
373
+ 			} catch (e) {}
374
+ 			try {
375
+ 				t2 = arg2.toString().split(".")[1].length;
376
+ 			} catch (e) {}
377
+ 			r1 = Number(arg1.toString().replace(".", ""));
378
+ 			r2 = Number(arg2.toString().replace(".", ""));
379
+ 			return this.Mul(r1 / r2, Math.pow(10, t2 - t1));
380
+ 		},
381
+ 		//加法函数,用来得到精确的加法结果
382
+ 		//说明:javascript的加法结果会有误差,在两个浮点数相加的时候会比较明显。这个函数返回较为精确的加法结果。
383
+ 		//调用:$h.Add(arg1,arg2)
384
+ 		//返回值:arg1加上arg2的精确结果
385
+ 		Add: function(arg1, arg2) {
386
+ 			arg2 = parseFloat(arg2);
387
+ 			var r1, r2, m;
388
+ 			try {
389
+ 				r1 = arg1.toString().split(".")[1].length
390
+ 			} catch (e) {
391
+ 				r1 = 0
392
+ 			}
393
+ 			try {
394
+ 				r2 = arg2.toString().split(".")[1].length
395
+ 			} catch (e) {
396
+ 				r2 = 0
397
+ 			}
398
+ 			m = Math.pow(100, Math.max(r1, r2));
399
+ 			return (this.Mul(arg1, m) + this.Mul(arg2, m)) / m;
400
+ 		},
401
+ 		//减法函数,用来得到精确的减法结果
402
+ 		//说明:javascript的加法结果会有误差,在两个浮点数相加的时候会比较明显。这个函数返回较为精确的减法结果。
403
+ 		//调用:$h.Sub(arg1,arg2)
404
+ 		//返回值:arg1减去arg2的精确结果
405
+ 		Sub: function(arg1, arg2) {
406
+ 			arg1 = parseFloat(arg1);
407
+ 			arg2 = parseFloat(arg2);
408
+ 			var r1, r2, m, n;
409
+ 			try {
410
+ 				r1 = arg1.toString().split(".")[1].length
411
+ 			} catch (e) {
412
+ 				r1 = 0
413
+ 			}
414
+ 			try {
415
+ 				r2 = arg2.toString().split(".")[1].length
416
+ 			} catch (e) {
417
+ 				r2 = 0
418
+ 			}
419
+ 			m = Math.pow(10, Math.max(r1, r2));
420
+ 			//动态控制精度长度
421
+ 			n = (r1 >= r2) ? r1 : r2;
422
+ 			return ((this.Mul(arg1, m) - this.Mul(arg2, m)) / m).toFixed(n);
423
+ 		},
424
+ 		//乘法函数,用来得到精确的乘法结果
425
+ 		//说明:javascript的乘法结果会有误差,在两个浮点数相乘的时候会比较明显。这个函数返回较为精确的乘法结果。
426
+ 		//调用:$h.Mul(arg1,arg2)
427
+ 		//返回值:arg1乘以arg2的精确结果
428
+ 		Mul: function(arg1, arg2) {
429
+ 			arg1 = parseFloat(arg1);
430
+ 			arg2 = parseFloat(arg2);
431
+ 			var m = 0,
432
+ 				s1 = arg1.toString(),
433
+ 				s2 = arg2.toString();
434
+ 			try {
435
+ 				m += s1.split(".")[1].length
436
+ 			} catch (e) {}
437
+ 			try {
438
+ 				m += s2.split(".")[1].length
439
+ 			} catch (e) {}
440
+ 			return Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m);
441
+ 		},
442
+ 	},
443
+ 	// 获取地理位置;
444
+ 	$L: {
445
+ 		async getLocation() {
446
+ 			// #ifdef APP-PLUS
447
+ 			let status = await this.checkPermission();
448
+ 			if (status !== 1) {
449
+ 				return;
450
+ 			}
451
+ 			// #endif
452
+ 			// #ifdef MP-WEIXIN || MP-TOUTIAO || MP-QQ
453
+ 			let status = await this.getSetting();
454
+ 			if (status === 2) {
455
+ 				this.openSetting();
456
+ 				return;
457
+ 			}
458
+ 			// #endif
459
+
460
+ 			this.doGetLocation();
461
+ 		},
462
+ 		doGetLocation() {
463
+ 			uni.getLocation({
464
+ 				success: (res) => {
465
+ 					uni.removeStorageSync('CACHE_LONGITUDE');
466
+ 					uni.removeStorageSync('CACHE_LATITUDE');
467
+ 					uni.setStorageSync('CACHE_LONGITUDE', res.longitude);
468
+ 					uni.setStorageSync('CACHE_LATITUDE', res.latitude);
469
+ 				},
470
+ 				fail: (err) => {
471
+ 					// #ifdef MP-BAIDU
472
+ 					if (err.errCode === 202 || err.errCode === 10003) { // 202模拟器 10003真机 user deny
473
+ 						this.openSetting();
474
+ 					}
475
+ 					// #endif
476
+ 					// #ifndef MP-BAIDU
477
+ 					if (err.errMsg.indexOf("auth deny") >= 0) {
478
+ 						uni.showToast({
479
+ 							title: "访问位置被拒绝"
480
+ 						})
481
+ 					} else {
482
+ 						uni.showToast({
483
+ 							title: err.errMsg
484
+ 						})
485
+ 					}
486
+ 					// #endif
487
+ 				}
488
+ 			})
489
+ 		},
490
+ 		getSetting: function() {
491
+ 			return new Promise((resolve, reject) => {
492
+ 				uni.getSetting({
493
+ 					success: (res) => {
494
+ 						if (res.authSetting['scope.userLocation'] === undefined) {
495
+ 							resolve(0);
496
+ 							return;
497
+ 						}
498
+ 						if (res.authSetting['scope.userLocation']) {
499
+ 							resolve(1);
500
+ 						} else {
501
+ 							resolve(2);
502
+ 						}
503
+ 					}
504
+ 				});
505
+ 			});
506
+ 		},
507
+ 		openSetting: function() {
508
+ 			uni.openSetting({
509
+ 				success: (res) => {
510
+ 					if (res.authSetting && res.authSetting['scope.userLocation']) {
511
+ 						this.doGetLocation();
512
+ 					}
513
+ 				},
514
+ 				fail: (err) => {}
515
+ 			})
516
+ 		},
517
+ 		async checkPermission() {
518
+ 			let status = permision.isIOS ? await permision.requestIOS('location') :
519
+ 				await permision.requestAndroid('android.permission.ACCESS_FINE_LOCATION');
520
+
521
+ 			if (status === null || status === 1) {
522
+ 				status = 1;
523
+ 			} else if (status === 2) {
524
+ 				uni.showModal({
525
+ 					content: "系统定位已关闭",
526
+ 					confirmText: "确定",
527
+ 					showCancel: false,
528
+ 					success: function(res) {}
529
+ 				})
530
+ 			} else if (status.code) {
531
+ 				uni.showModal({
532
+ 					content: status.message
533
+ 				})
534
+ 			} else {
535
+ 				uni.showModal({
536
+ 					content: "需要定位权限",
537
+ 					confirmText: "设置",
538
+ 					success: function(res) {
539
+ 						if (res.confirm) {
540
+ 							permision.gotoAppSetting();
541
+ 						}
542
+ 					}
543
+ 				})
544
+ 			}
545
+ 			return status;
546
+ 		},
547
+ 	}
548
+
549
+ }

+ 596 - 0
utils/util.js 查看文件

@@ -0,0 +1,596 @@
1
+import {
2
+ 	TOKENNAME,
3
+ 	HTTP_REQUEST_URL
4
+ } from '../config/app.js';
5
+ import store from '../store';
6
+ import {
7
+ 	pathToBase64
8
+ } from '@/plugin/image-tools/index.js';
9
+ // #ifdef APP-PLUS
10
+ import permision from "./permission.js"
11
+ // #endif
12
+ export default {
13
+ 	/**
14
+ 	 * opt  object | string
15
+ 	 * to_url object | string
16
+ 	 * 例:
17
+ 	 * this.Tips('/pages/test/test'); 跳转不提示
18
+ 	 * this.Tips({title:'提示'},'/pages/test/test'); 提示并跳转
19
+ 	 * this.Tips({title:'提示'},{tab:1,url:'/pages/index/index'}); 提示并跳转值table上
20
+ 	 * tab=1 一定时间后跳转至 table上
21
+ 	 * tab=2 一定时间后跳转至非 table上
22
+ 	 * tab=3 一定时间后返回上页面
23
+ 	 * tab=4 关闭所有页面,打开到应用内的某个页面
24
+ 	 * tab=5 关闭当前页面,跳转到应用内的某个页面
25
+ 	 */
26
+ 	Tips: function(opt, to_url) {
27
+ 		if (typeof opt == 'string') {
28
+ 			to_url = opt;
29
+ 			opt = {};
30
+ 		}
31
+ 		let title = opt.title || '',
32
+ 			icon = opt.icon || 'none',
33
+ 			endtime = opt.endtime || 2000,
34
+ 			success = opt.success;
35
+ 		if (title) uni.showToast({
36
+ 			title: title,
37
+ 			icon: icon,
38
+ 			duration: endtime,
39
+ 			success
40
+ 		})
41
+ 		if (to_url != undefined) {
42
+ 			if (typeof to_url == 'object') {
43
+ 				let tab = to_url.tab || 1,
44
+ 					url = to_url.url || '';
45
+ 				switch (tab) {
46
+ 					case 1:
47
+ 						//一定时间后跳转至 table
48
+ 						setTimeout(function() {
49
+ 							uni.navigateTo({
50
+ 								url: url
51
+ 							})
52
+ 						}, endtime);
53
+ 						break;
54
+ 					case 2:
55
+ 						//跳转至非table页面
56
+ 						setTimeout(function() {
57
+ 							uni.navigateTo({
58
+ 								url: url,
59
+ 							})
60
+ 						}, endtime);
61
+ 						break;
62
+ 					case 3:
63
+ 						//返回上页面
64
+ 						setTimeout(function() {
65
+ 							// #ifndef H5
66
+ 							uni.navigateBack({
67
+ 								delta: parseInt(url),
68
+ 							})
69
+ 							// #endif
70
+ 							// #ifdef H5
71
+ 							history.back();
72
+ 							// #endif
73
+ 						}, endtime);
74
+ 						break;
75
+ 					case 4:
76
+ 						//关闭所有页面,打开到应用内的某个页面
77
+ 						setTimeout(function() {
78
+ 							uni.reLaunch({
79
+ 								url: url,
80
+ 							})
81
+ 						}, endtime);
82
+ 						break;
83
+ 					case 5:
84
+ 						//关闭当前页面,跳转到应用内的某个页面
85
+ 						setTimeout(function() {
86
+ 							uni.redirectTo({
87
+ 								url: url,
88
+ 							})
89
+ 						}, endtime);
90
+ 						break;
91
+ 				}
92
+
93
+ 			} else if (typeof to_url == 'function') {
94
+ 				setTimeout(function() {
95
+ 					to_url && to_url();
96
+ 				}, endtime);
97
+ 			} else {
98
+ 				//没有提示时跳转不延迟
99
+ 				setTimeout(function() {
100
+ 					uni.navigateTo({
101
+ 						url: to_url,
102
+ 					})
103
+ 				}, title ? endtime : 0);
104
+ 			}
105
+ 		}
106
+ 	},
107
+ 	/**
108
+ 	 * 移除数组中的某个数组并组成新的数组返回
109
+ 	 * @param array array 需要移除的数组
110
+ 	 * @param int index 需要移除的数组的键值
111
+ 	 * @param string | int 值
112
+ 	 * @return array
113
+ 	 * 
114
+ 	 */
115
+ 	ArrayRemove: function(array, index, value) {
116
+ 		const valueArray = [];
117
+ 		if (array instanceof Array) {
118
+ 			for (let i = 0; i < array.length; i++) {
119
+ 				if (typeof index == 'number' && array[index] != i) {
120
+ 					valueArray.push(array[i]);
121
+ 				} else if (typeof index == 'string' && array[i][index] != value) {
122
+ 					valueArray.push(array[i]);
123
+ 				}
124
+ 			}
125
+ 		}
126
+ 		return valueArray;
127
+ 	},
128
+ 	/**
129
+ 	 * 生成海报获取文字
130
+ 	 * @param string text 为传入的文本
131
+ 	 * @param int num 为单行显示的字节长度
132
+ 	 * @return array 
133
+ 	 */
134
+ 	textByteLength: function(text, num) {
135
+ 		let strLength = 0;
136
+ 		let rows = 1;
137
+ 		let str = 0;
138
+ 		let arr = [];
139
+ 		for (let j = 0; j < text.length; j++) {
140
+ 			if (text.charCodeAt(j) > 255) {
141
+ 				strLength += 2;
142
+ 				if (strLength > rows * num) {
143
+ 					strLength++;
144
+ 					arr.push(text.slice(str, j));
145
+ 					str = j;
146
+ 					rows++;
147
+ 				}
148
+ 			} else {
149
+ 				strLength++;
150
+ 				if (strLength > rows * num) {
151
+ 					arr.push(text.slice(str, j));
152
+ 					str = j;
153
+ 					rows++;
154
+ 				}
155
+ 			}
156
+ 		}
157
+ 		arr.push(text.slice(str, text.length));
158
+ 		return [strLength, arr, rows] //  [处理文字的总字节长度,每行显示内容的数组,行数]
159
+ 	},
160
+
161
+ 	/**
162
+ 	 * 获取分享海报
163
+ 	 * @param array arr2 海报素材
164
+ 	 * @param string store_name 素材文字
165
+ 	 * @param string price 价格
166
+	 * @param string ot_price 原始价格
167
+ 	 * @param function successFn 回调函数
168
+ 	 * 
169
+ 	 * 
170
+ 	 */
171
+ 	PosterCanvas: function(arr2, store_name, price,ot_price, successFn) {
172
+ 		let that = this;
173
+ 		uni.showLoading({
174
+ 			title: '海报生成中',
175
+ 			mask: true
176
+ 		});
177
+ 		const ctx = uni.createCanvasContext('myCanvas');
178
+ 		ctx.clearRect(0, 0, 0, 0);
179
+		
180
+		
181
+ 		/**
182
+ 		 * 只能获取合法域名下的图片信息,本地调试无法获取
183
+ 		 * 
184
+ 		 */
185
+		ctx.fillStyle = '#fff';
186
+		ctx.fillRect(0, 0, 750, 1150);
187
+ 		uni.getImageInfo({
188
+ 			src: arr2[0],
189
+ 			success: function(res) {
190
+ 				const WIDTH = res.width;
191
+ 				const HEIGHT = res.height;
192
+ 				// ctx.drawImage(arr2[0], 0, 0, WIDTH, 1050);
193
+ 				ctx.drawImage(arr2[1], 0, 0, WIDTH, WIDTH);
194
+ 				ctx.save();
195
+ 				let r = 130;
196
+ 				let d = r * 2;
197
+ 				let cx = 460;
198
+ 				let cy = 790;
199
+ 				ctx.arc(cx + r, cy + r, r, 0, 2 * Math.PI);
200
+ 				// ctx.clip();
201
+ 				ctx.drawImage(arr2[2], cx, cy,d,d);
202
+ 				ctx.restore();
203
+ 				const CONTENT_ROW_LENGTH = 20;
204
+ 				let [contentLeng, contentArray, contentRows] = that.textByteLength(store_name, CONTENT_ROW_LENGTH);
205
+ 				if (contentRows > 2) {
206
+ 					contentRows = 2;
207
+ 					let textArray = contentArray.slice(0, 2);
208
+ 					textArray[textArray.length - 1] += '……';
209
+ 					contentArray = textArray;
210
+ 				}
211
+ 				ctx.setTextAlign('left');
212
+ 				ctx.setFontSize(36);
213
+				ctx.setFillStyle('#000');
214
+ 				let contentHh = 36 * 1.5;
215
+ 				for (let m = 0; m < contentArray.length; m++) {
216
+ 					ctx.fillText(contentArray[m], 50, 1000 + contentHh * m,750);
217
+ 				}
218
+ 				ctx.setTextAlign('left')
219
+ 				ctx.setFontSize(72);
220
+ 				ctx.setFillStyle('#DA4F2A');
221
+ 				ctx.fillText('¥' + price, 40, 820 + contentHh);
222
+				
223
+				ctx.setTextAlign('left')
224
+				ctx.setFontSize(36);
225
+				ctx.setFillStyle('#999');
226
+				ctx.fillText('¥' + ot_price, 50, 880 + contentHh);
227
+				
228
+				var underline = function(ctx, text, x, y, size, color, thickness ,offset){ 
229
+					var width = ctx.measureText(text).width; 
230
+					
231
+					 switch(ctx.textAlign){ 
232
+					 case "center": 
233
+					 x -= (width/2); break; 
234
+					 case "right": 
235
+					 x -= width; break; 
236
+					 } 
237
+					
238
+					 y += size+offset; 
239
+					
240
+					 ctx.beginPath(); 
241
+					 ctx.strokeStyle = color; 
242
+					 ctx.lineWidth = thickness; 
243
+					 ctx.moveTo(x,y); 
244
+					 ctx.lineTo(x+width,y); 
245
+					 ctx.stroke(); 
246
+				} 
247
+				underline(ctx,'¥'+ot_price, 55,880,36,'#999',2,0)
248
+				
249
+				
250
+				
251
+				
252
+				
253
+				ctx.setTextAlign('left')
254
+				ctx.setFontSize(28);
255
+				ctx.setFillStyle('#999');
256
+				ctx.fillText('长按或扫描查看', 490, 1030 + contentHh);
257
+				
258
+				
259
+
260
+					
261
+ 				ctx.draw(true, function() {
262
+ 					uni.canvasToTempFilePath({
263
+ 						canvasId: 'myCanvas',
264
+ 						fileType: 'png',
265
+ 						destWidth: WIDTH,
266
+ 						destHeight: HEIGHT,
267
+ 						success: function(res) {
268
+ 							uni.hideLoading();
269
+ 							successFn && successFn(res.tempFilePath);
270
+ 						}
271
+ 					})
272
+ 				});
273
+ 			},
274
+ 			fail: function(err) {
275
+ 				uni.hideLoading();
276
+ 				that.Tips({
277
+ 					title: '无法获取图片信息'
278
+ 				});
279
+ 			}
280
+ 		})
281
+ 	},
282
+ 	/*
283
+ 	 * 单图上传
284
+ 	 * @param object opt
285
+ 	 * @param callable successCallback 成功执行方法 data 
286
+ 	 * @param callable errorCallback 失败执行方法 
287
+ 	 */
288
+ 	uploadImageOne: function(opt, successCallback, errorCallback) {
289
+ 		let that = this;
290
+ 		if (typeof opt === 'string') {
291
+ 			let url = opt;
292
+ 			opt = {};
293
+ 			opt.url = url;
294
+ 		}
295
+ 		let count = opt.count || 1,
296
+ 			sizeType = opt.sizeType || ['compressed'],
297
+ 			sourceType = opt.sourceType || ['album', 'camera'],
298
+ 			is_load = opt.is_load || true,
299
+ 			uploadUrl = opt.url || '',
300
+ 			inputName = opt.name || 'pics',
301
+			fileType = opt.fileType || 'image';
302
+ 		uni.chooseImage({
303
+ 			count: count, //最多可以选择的图片总数  
304
+ 			sizeType: sizeType, // 可以指定是原图还是压缩图,默认二者都有  
305
+ 			sourceType: sourceType, // 可以指定来源是相册还是相机,默认二者都有  
306
+ 			success: function(res) {
307
+				console.log()
308
+ 				//启动上传等待中...  
309
+ 				uni.showLoading({
310
+ 					title: '图片上传中',
311
+ 				});
312
+				uni.uploadFile({
313
+					url: HTTP_REQUEST_URL + '/api/' + uploadUrl,
314
+					filePath: res.tempFilePaths[0],
315
+					fileType: fileType,
316
+					name: inputName,
317
+					formData: {
318
+						'filename': inputName
319
+					},
320
+					header: {
321
+						// #ifdef MP
322
+						"Content-Type": "multipart/form-data",
323
+						// #endif
324
+						[TOKENNAME]: 'Bearer ' + store.state.app.token
325
+					},
326
+					success: function(res) {
327
+						uni.hideLoading();
328
+						if (res.statusCode == 403) {
329
+							that.Tips({
330
+								title: res.data
331
+							});
332
+						} else {
333
+							let data = res.data ? JSON.parse(res.data) : {};
334
+							if (data.status == 200) {
335
+								successCallback && successCallback(data)
336
+							} else {
337
+								errorCallback && errorCallback(data);
338
+								that.Tips({
339
+									title: data.msg
340
+								});
341
+							}
342
+						}
343
+					},
344
+					fail: function(res) {
345
+						uni.hideLoading();
346
+						that.Tips({
347
+							title: '上传图片失败'
348
+						});
349
+					}
350
+				})
351
+ 				// pathToBase64(res.tempFilePaths[0])
352
+ 				// 	.then(imgBase64 => {
353
+ 				// 		console.log(imgBase64);
354
+ 						
355
+ 				// 	})
356
+ 				// 	.catch(error => {
357
+ 				// 		console.error(error)
358
+ 				// 	})
359
+ 			}
360
+ 		})
361
+ 	},
362
+ 	/**
363
+ 	 * 处理服务器扫码带进来的参数
364
+ 	 * @param string param 扫码携带参数
365
+ 	 * @param string k 整体分割符 默认为:&
366
+ 	 * @param string p 单个分隔符 默认为:=
367
+ 	 * @return object
368
+ 	 * 
369
+ 	 */
370
+ 	// #ifdef MP
371
+ 	getUrlParams: function(param, k, p) {
372
+ 		if (typeof param != 'string') return {};
373
+ 		k = k ? k : '&'; //整体参数分隔符
374
+ 		p = p ? p : '='; //单个参数分隔符
375
+ 		var value = {};
376
+ 		if (param.indexOf(k) !== -1) {
377
+ 			param = param.split(k);
378
+ 			for (var val in param) {
379
+ 				if (param[val].indexOf(p) !== -1) {
380
+ 					var item = param[val].split(p);
381
+ 					value[item[0]] = item[1];
382
+ 				}
383
+ 			}
384
+ 		} else if (param.indexOf(p) !== -1) {
385
+ 			var item = param.split(p);
386
+ 			value[item[0]] = item[1];
387
+ 		} else {
388
+ 			return param;
389
+ 		}
390
+ 		return value;
391
+ 	},
392
+ 	// #endif
393
+ 	/*
394
+ 	 * 合并数组
395
+ 	 */
396
+ 	SplitArray(list, sp) {
397
+ 		if (typeof list != 'object') return [];
398
+ 		if (sp === undefined) sp = [];
399
+ 		for (var i = 0; i < list.length; i++) {
400
+ 			sp.push(list[i]);
401
+ 		}
402
+ 		return sp;
403
+ 	},
404
+ 	trim(str) {
405
+ 		return String.prototype.trim.call(str);
406
+ 	},
407
+ 	$h: {
408
+ 		//除法函数,用来得到精确的除法结果
409
+ 		//说明:javascript的除法结果会有误差,在两个浮点数相除的时候会比较明显。这个函数返回较为精确的除法结果。
410
+ 		//调用:$h.Div(arg1,arg2)
411
+ 		//返回值:arg1除以arg2的精确结果
412
+ 		Div: function(arg1, arg2) {
413
+ 			arg1 = parseFloat(arg1);
414
+ 			arg2 = parseFloat(arg2);
415
+ 			var t1 = 0,
416
+ 				t2 = 0,
417
+ 				r1, r2;
418
+ 			try {
419
+ 				t1 = arg1.toString().split(".")[1].length;
420
+ 			} catch (e) {}
421
+ 			try {
422
+ 				t2 = arg2.toString().split(".")[1].length;
423
+ 			} catch (e) {}
424
+ 			r1 = Number(arg1.toString().replace(".", ""));
425
+ 			r2 = Number(arg2.toString().replace(".", ""));
426
+ 			return this.Mul(r1 / r2, Math.pow(10, t2 - t1));
427
+ 		},
428
+ 		//加法函数,用来得到精确的加法结果
429
+ 		//说明:javascript的加法结果会有误差,在两个浮点数相加的时候会比较明显。这个函数返回较为精确的加法结果。
430
+ 		//调用:$h.Add(arg1,arg2)
431
+ 		//返回值:arg1加上arg2的精确结果
432
+ 		Add: function(arg1, arg2) {
433
+ 			arg2 = parseFloat(arg2);
434
+ 			var r1, r2, m;
435
+ 			try {
436
+ 				r1 = arg1.toString().split(".")[1].length
437
+ 			} catch (e) {
438
+ 				r1 = 0
439
+ 			}
440
+ 			try {
441
+ 				r2 = arg2.toString().split(".")[1].length
442
+ 			} catch (e) {
443
+ 				r2 = 0
444
+ 			}
445
+ 			m = Math.pow(100, Math.max(r1, r2));
446
+ 			return (this.Mul(arg1, m) + this.Mul(arg2, m)) / m;
447
+ 		},
448
+ 		//减法函数,用来得到精确的减法结果
449
+ 		//说明:javascript的加法结果会有误差,在两个浮点数相加的时候会比较明显。这个函数返回较为精确的减法结果。
450
+ 		//调用:$h.Sub(arg1,arg2)
451
+ 		//返回值:arg1减去arg2的精确结果
452
+ 		Sub: function(arg1, arg2) {
453
+ 			arg1 = parseFloat(arg1);
454
+ 			arg2 = parseFloat(arg2);
455
+ 			var r1, r2, m, n;
456
+ 			try {
457
+ 				r1 = arg1.toString().split(".")[1].length
458
+ 			} catch (e) {
459
+ 				r1 = 0
460
+ 			}
461
+ 			try {
462
+ 				r2 = arg2.toString().split(".")[1].length
463
+ 			} catch (e) {
464
+ 				r2 = 0
465
+ 			}
466
+ 			m = Math.pow(10, Math.max(r1, r2));
467
+ 			//动态控制精度长度
468
+ 			n = (r1 >= r2) ? r1 : r2;
469
+ 			return ((this.Mul(arg1, m) - this.Mul(arg2, m)) / m).toFixed(n);
470
+ 		},
471
+ 		//乘法函数,用来得到精确的乘法结果
472
+ 		//说明:javascript的乘法结果会有误差,在两个浮点数相乘的时候会比较明显。这个函数返回较为精确的乘法结果。
473
+ 		//调用:$h.Mul(arg1,arg2)
474
+ 		//返回值:arg1乘以arg2的精确结果
475
+ 		Mul: function(arg1, arg2) {
476
+ 			arg1 = parseFloat(arg1);
477
+ 			arg2 = parseFloat(arg2);
478
+ 			var m = 0,
479
+ 				s1 = arg1.toString(),
480
+ 				s2 = arg2.toString();
481
+ 			try {
482
+ 				m += s1.split(".")[1].length
483
+ 			} catch (e) {}
484
+ 			try {
485
+ 				m += s2.split(".")[1].length
486
+ 			} catch (e) {}
487
+ 			return Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m);
488
+ 		},
489
+ 	},
490
+ 	// 获取地理位置;
491
+ 	$L: {
492
+ 		async getLocation() {
493
+ 			// #ifdef APP-PLUS
494
+ 			let status = await this.checkPermission();
495
+ 			if (status !== 1) {
496
+ 				return;
497
+ 			}
498
+ 			// #endif
499
+ 			// #ifdef MP-WEIXIN || MP-TOUTIAO || MP-QQ
500
+ 			let status = await this.getSetting();
501
+ 			if (status === 2) {
502
+ 				this.openSetting();
503
+ 				return;
504
+ 			}
505
+ 			// #endif
506
+
507
+ 			this.doGetLocation();
508
+ 		},
509
+ 		doGetLocation() {
510
+ 			uni.getLocation({
511
+ 				success: (res) => {
512
+ 					uni.removeStorageSync('CACHE_LONGITUDE');
513
+ 					uni.removeStorageSync('CACHE_LATITUDE');
514
+ 					uni.setStorageSync('CACHE_LONGITUDE', res.longitude);
515
+ 					uni.setStorageSync('CACHE_LATITUDE', res.latitude);
516
+ 				},
517
+ 				fail: (err) => {
518
+ 					// #ifdef MP-BAIDU
519
+ 					if (err.errCode === 202 || err.errCode === 10003) { // 202模拟器 10003真机 user deny
520
+ 						this.openSetting();
521
+ 					}
522
+ 					// #endif
523
+ 					// #ifndef MP-BAIDU
524
+ 					if (err.errMsg.indexOf("auth deny") >= 0) {
525
+ 						uni.showToast({
526
+ 							title: "访问位置被拒绝"
527
+ 						})
528
+ 					} else {
529
+ 						uni.showToast({
530
+ 							title: err.errMsg
531
+ 						})
532
+ 					}
533
+ 					// #endif
534
+ 				}
535
+ 			})
536
+ 		},
537
+ 		getSetting: function() {
538
+ 			return new Promise((resolve, reject) => {
539
+ 				uni.getSetting({
540
+ 					success: (res) => {
541
+ 						if (res.authSetting['scope.userLocation'] === undefined) {
542
+ 							resolve(0);
543
+ 							return;
544
+ 						}
545
+ 						if (res.authSetting['scope.userLocation']) {
546
+ 							resolve(1);
547
+ 						} else {
548
+ 							resolve(2);
549
+ 						}
550
+ 					}
551
+ 				});
552
+ 			});
553
+ 		},
554
+ 		openSetting: function() {
555
+ 			uni.openSetting({
556
+ 				success: (res) => {
557
+ 					if (res.authSetting && res.authSetting['scope.userLocation']) {
558
+ 						this.doGetLocation();
559
+ 					}
560
+ 				},
561
+ 				fail: (err) => {}
562
+ 			})
563
+ 		},
564
+ 		async checkPermission() {
565
+ 			let status = permision.isIOS ? await permision.requestIOS('location') :
566
+ 				await permision.requestAndroid('android.permission.ACCESS_FINE_LOCATION');
567
+
568
+ 			if (status === null || status === 1) {
569
+ 				status = 1;
570
+ 			} else if (status === 2) {
571
+ 				uni.showModal({
572
+ 					content: "系统定位已关闭",
573
+ 					confirmText: "确定",
574
+ 					showCancel: false,
575
+ 					success: function(res) {}
576
+ 				})
577
+ 			} else if (status.code) {
578
+ 				uni.showModal({
579
+ 					content: status.message
580
+ 				})
581
+ 			} else {
582
+ 				uni.showModal({
583
+ 					content: "需要定位权限",
584
+ 					confirmText: "设置",
585
+ 					success: function(res) {
586
+ 						if (res.confirm) {
587
+ 							permision.gotoAppSetting();
588
+ 						}
589
+ 					}
590
+ 				})
591
+ 			}
592
+ 			return status;
593
+ 		},
594
+ 	}
595
+
596
+ }

+ 30 - 0
utils/validate.js 查看文件

@@ -0,0 +1,30 @@
1
+/**
2
+ * 验证小数点后两位及多个小数
3
+ * money 金额
4
+*/ 
5
+export function isMoney(money) {
6
+  var reg = /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/
7
+  if (reg.test(money)) {
8
+    return true
9
+  } else {
10
+    return false
11
+  }
12
+}
13
+
14
+/**
15
+ * 验证手机号码
16
+ * money 金额
17
+*/ 
18
+export function checkPhone(phone) {
19
+  var reg = /^1(3|4|5|6|7|8|9)\d{9}$/
20
+  if (reg.test(phone)) {
21
+    return true
22
+  } else {
23
+    return false
24
+  }
25
+}
26
+
27
+
28
+
29
+
30
+