1
|
-import Vue from "vue";
|
|
|
2
|
-import moment from "moment";
|
|
|
3
|
-const DATE_TIME_FORMAT = "YYYY-MM-DD HH:mm:ss";
|
|
|
4
|
-//手机号中间4位为*
|
|
|
5
|
-Vue.filter("phone", function (val) {
|
|
|
6
|
- var tel = val;
|
|
|
7
|
- tel = "" + tel;
|
|
|
8
|
- var telShort = tel.replace(tel.substring(3, 7), "****");
|
|
|
9
|
- return telShort;
|
|
|
10
|
-});
|
|
|
11
|
-//获取系统信息、判断ipX安全距离
|
|
|
12
|
-export const getTabbarHeight = function () {
|
|
|
13
|
- var systemInfo = uni.getSystemInfoSync();
|
|
|
14
|
- var data = {
|
|
|
15
|
- ...systemInfo,
|
|
|
16
|
- tabbarH: 50, //tabbar高度--单位px
|
|
|
17
|
- tabbarPaddingB: 0, //tabbar底部安全距离高度--单位px
|
|
|
18
|
- device: systemInfo.system.indexOf("iOS") != -1 ? "iOS" : "Android", //苹果或者安卓设备
|
|
|
19
|
- };
|
|
|
20
|
- let modelArr = [
|
|
|
21
|
- "10,3",
|
|
|
22
|
- "10,6",
|
|
|
23
|
- "X",
|
|
|
24
|
- "XR",
|
|
|
25
|
- "XS",
|
|
|
26
|
- "11",
|
|
|
27
|
- "12",
|
|
|
28
|
- "13",
|
|
|
29
|
- "14",
|
|
|
30
|
- "15",
|
|
|
31
|
- "16",
|
|
|
32
|
- ];
|
|
|
33
|
- let model = systemInfo.model;
|
|
|
34
|
- model &&
|
|
|
35
|
- modelArr.forEach((item) => {
|
|
|
36
|
- //适配iphoneX以上的底部,给tabbar一定高度的padding-bottom
|
|
|
37
|
- if (
|
|
|
38
|
- model.indexOf(item) != -1 &&
|
|
|
39
|
- (model.indexOf("iPhone") != -1 || model.indexOf("iphone") != -1)
|
|
|
40
|
- ) {
|
|
|
41
|
- data.tabbarH = 70;
|
|
|
42
|
- data.tabbarPaddingB = 20;
|
|
|
43
|
- }
|
|
|
44
|
- });
|
|
|
45
|
- return data;
|
|
|
46
|
-};
|
|
|
47
|
-
|
|
|
48
|
-// px转upx
|
|
|
49
|
-export const px2upx = function (n) {
|
|
|
50
|
- return n / (uni.upx2px(n) / n);
|
|
|
51
|
-};
|
|
|
52
|
-
|
|
|
53
|
-// 小程序获取定位权限判断
|
|
|
54
|
-// isOpenSetting 默认false:不检验授权,true:检验授权后获取地址
|
|
|
55
|
-function getMpLocation(successCallback, errCallback, isOpenSetting) {
|
|
|
56
|
- uni.getSetting({
|
|
|
57
|
- success: (res) => {
|
|
|
58
|
- if (res.authSetting["scope.userLocation"] || !isOpenSetting) {
|
|
|
59
|
- uni.getLocation({
|
|
|
60
|
- // #ifndef MP-ALIPAY
|
|
|
61
|
- type: "gcj02",
|
|
|
62
|
- // #endif
|
|
|
63
|
- success(res) {
|
|
|
64
|
- console.log("successCallback");
|
|
|
65
|
- successCallback(res);
|
|
|
66
|
- },
|
|
|
67
|
- fail(err) {
|
|
|
68
|
- console.log("位置信息错误", err);
|
|
|
69
|
- errCallback("位置信息获取失败");
|
|
|
70
|
- },
|
|
|
71
|
- });
|
|
|
72
|
- } else {
|
|
|
73
|
- errCallback("“位置信息”未授权");
|
|
|
74
|
- isOpenSetting &&
|
|
|
75
|
- uni.showModal({
|
|
|
76
|
- title: "提示",
|
|
|
77
|
- content: "请先在设置页面打开“位置信息”使用权限",
|
|
|
78
|
- confirmText: "去设置",
|
|
|
79
|
- cancelText: "再逛会",
|
|
|
80
|
- success: (res) => {
|
|
|
81
|
- if (res.confirm) {
|
|
|
82
|
- uni.openSetting();
|
|
|
83
|
- }
|
|
|
84
|
- },
|
|
|
85
|
- });
|
|
|
86
|
- }
|
|
|
87
|
- },
|
|
|
88
|
- });
|
|
|
89
|
-}
|
|
|
90
|
-// 获取地址信息
|
|
|
91
|
-let locationAuthorize = true;
|
|
|
92
|
-export const getAppLatLon = function (
|
|
|
93
|
- successCallback,
|
|
|
94
|
- errCallback,
|
|
|
95
|
- isOpenSetting
|
|
|
96
|
-) {
|
|
|
97
|
- const _this = this;
|
|
|
98
|
- // #ifdef MP-WEIXIN
|
|
|
99
|
- if (locationAuthorize && isOpenSetting) {
|
|
|
100
|
- uni.authorize({
|
|
|
101
|
- scope: "scope.userLocation",
|
|
|
102
|
- success: () => {
|
|
|
103
|
- getMpLocation(successCallback, errCallback, isOpenSetting);
|
|
|
104
|
- locationAuthorize = false;
|
|
|
105
|
- },
|
|
|
106
|
- fail: () => {
|
|
|
107
|
- locationAuthorize = false;
|
|
|
108
|
- },
|
|
|
109
|
- });
|
|
|
110
|
- } else {
|
|
|
111
|
- getMpLocation(successCallback, errCallback, isOpenSetting);
|
|
|
112
|
- }
|
|
|
113
|
- // #endif
|
|
|
114
|
- // #ifdef MP-ALIPAY
|
|
|
115
|
- getMpLocation(successCallback, errCallback, false);
|
|
|
116
|
- // #endif
|
|
|
117
|
- // #ifdef H5
|
|
|
118
|
- uni.getLocation({
|
|
|
119
|
- type: "gcj02",
|
|
|
120
|
- success(res) {
|
|
|
121
|
- console.log("successCallback");
|
|
|
122
|
- successCallback(res);
|
|
|
123
|
- },
|
|
|
124
|
- fail(err) {
|
|
|
125
|
- console.log("位置信息错误", err);
|
|
|
126
|
- errCallback("位置信息获取失败");
|
|
|
127
|
- },
|
|
|
128
|
- });
|
|
|
129
|
- // #endif
|
|
|
130
|
-};
|
|
|
131
|
-
|
|
|
132
|
-export function formatToDate(date = undefined, format = DATE_TIME_FORMAT) {
|
|
|
133
|
- return moment(date).format(format);
|
|
|
134
|
-} |
1
|
+import Vue from "vue";
|
|
|
2
|
+import moment from "moment";
|
|
|
3
|
+const DATE_TIME_FORMAT = "YYYY-MM-DD HH:mm:ss";
|
|
|
4
|
+
|
|
|
5
|
+/**
|
|
|
6
|
+ 登录密码正则验证
|
|
|
7
|
+ 最短8位,最长16位
|
|
|
8
|
+ 必须包含1个数字
|
|
|
9
|
+ 必须包含1个小写字母
|
|
|
10
|
+ 必须包含1个大写字母
|
|
|
11
|
+ 必须包含1个特殊字符
|
|
|
12
|
+ */
|
|
|
13
|
+export const loginPasswordReg =/^.*(?=.{6,16})(?=.*\d)(?=.*[A-Z]{1,})(?=.*[a-z]{1,})(?=.*[_!@#$%^&*?\(\)]).*$/;
|
|
|
14
|
+
|
|
|
15
|
+//手机号中间4位为*
|
|
|
16
|
+Vue.filter("phone", function (val) {
|
|
|
17
|
+ var tel = val;
|
|
|
18
|
+ tel = "" + tel;
|
|
|
19
|
+ var telShort = tel.replace(tel.substring(3, 7), "****");
|
|
|
20
|
+ return telShort;
|
|
|
21
|
+});
|
|
|
22
|
+//获取系统信息、判断ipX安全距离
|
|
|
23
|
+export const getTabbarHeight = function () {
|
|
|
24
|
+ var systemInfo = uni.getSystemInfoSync();
|
|
|
25
|
+ var data = {
|
|
|
26
|
+ ...systemInfo,
|
|
|
27
|
+ tabbarH: 50, //tabbar高度--单位px
|
|
|
28
|
+ tabbarPaddingB: 0, //tabbar底部安全距离高度--单位px
|
|
|
29
|
+ device: systemInfo.system.indexOf("iOS") != -1 ? "iOS" : "Android", //苹果或者安卓设备
|
|
|
30
|
+ };
|
|
|
31
|
+ let modelArr = [
|
|
|
32
|
+ "10,3",
|
|
|
33
|
+ "10,6",
|
|
|
34
|
+ "X",
|
|
|
35
|
+ "XR",
|
|
|
36
|
+ "XS",
|
|
|
37
|
+ "11",
|
|
|
38
|
+ "12",
|
|
|
39
|
+ "13",
|
|
|
40
|
+ "14",
|
|
|
41
|
+ "15",
|
|
|
42
|
+ "16",
|
|
|
43
|
+ ];
|
|
|
44
|
+ let model = systemInfo.model;
|
|
|
45
|
+ model &&
|
|
|
46
|
+ modelArr.forEach((item) => {
|
|
|
47
|
+ //适配iphoneX以上的底部,给tabbar一定高度的padding-bottom
|
|
|
48
|
+ if (
|
|
|
49
|
+ model.indexOf(item) != -1 &&
|
|
|
50
|
+ (model.indexOf("iPhone") != -1 || model.indexOf("iphone") != -1)
|
|
|
51
|
+ ) {
|
|
|
52
|
+ data.tabbarH = 70;
|
|
|
53
|
+ data.tabbarPaddingB = 20;
|
|
|
54
|
+ }
|
|
|
55
|
+ });
|
|
|
56
|
+ return data;
|
|
|
57
|
+};
|
|
|
58
|
+
|
|
|
59
|
+// px转upx
|
|
|
60
|
+export const px2upx = function (n) {
|
|
|
61
|
+ return n / (uni.upx2px(n) / n);
|
|
|
62
|
+};
|
|
|
63
|
+
|
|
|
64
|
+// 小程序获取定位权限判断
|
|
|
65
|
+// isOpenSetting 默认false:不检验授权,true:检验授权后获取地址
|
|
|
66
|
+function getMpLocation(successCallback, errCallback, isOpenSetting) {
|
|
|
67
|
+ uni.getSetting({
|
|
|
68
|
+ success: (res) => {
|
|
|
69
|
+ if (res.authSetting["scope.userLocation"] || !isOpenSetting) {
|
|
|
70
|
+ uni.getLocation({
|
|
|
71
|
+ // #ifndef MP-ALIPAY
|
|
|
72
|
+ type: "gcj02",
|
|
|
73
|
+ // #endif
|
|
|
74
|
+ success(res) {
|
|
|
75
|
+ console.log("successCallback");
|
|
|
76
|
+ successCallback(res);
|
|
|
77
|
+ },
|
|
|
78
|
+ fail(err) {
|
|
|
79
|
+ console.log("位置信息错误", err);
|
|
|
80
|
+ errCallback("位置信息获取失败");
|
|
|
81
|
+ },
|
|
|
82
|
+ });
|
|
|
83
|
+ } else {
|
|
|
84
|
+ errCallback("“位置信息”未授权");
|
|
|
85
|
+ isOpenSetting &&
|
|
|
86
|
+ uni.showModal({
|
|
|
87
|
+ title: "提示",
|
|
|
88
|
+ content: "请先在设置页面打开“位置信息”使用权限",
|
|
|
89
|
+ confirmText: "去设置",
|
|
|
90
|
+ cancelText: "再逛会",
|
|
|
91
|
+ success: (res) => {
|
|
|
92
|
+ if (res.confirm) {
|
|
|
93
|
+ uni.openSetting();
|
|
|
94
|
+ }
|
|
|
95
|
+ },
|
|
|
96
|
+ });
|
|
|
97
|
+ }
|
|
|
98
|
+ },
|
|
|
99
|
+ });
|
|
|
100
|
+}
|
|
|
101
|
+// 获取地址信息
|
|
|
102
|
+let locationAuthorize = true;
|
|
|
103
|
+export const getAppLatLon = function (
|
|
|
104
|
+ successCallback,
|
|
|
105
|
+ errCallback,
|
|
|
106
|
+ isOpenSetting
|
|
|
107
|
+) {
|
|
|
108
|
+ const _this = this;
|
|
|
109
|
+ // #ifdef MP-WEIXIN
|
|
|
110
|
+ if (locationAuthorize && isOpenSetting) {
|
|
|
111
|
+ uni.authorize({
|
|
|
112
|
+ scope: "scope.userLocation",
|
|
|
113
|
+ success: () => {
|
|
|
114
|
+ getMpLocation(successCallback, errCallback, isOpenSetting);
|
|
|
115
|
+ locationAuthorize = false;
|
|
|
116
|
+ },
|
|
|
117
|
+ fail: () => {
|
|
|
118
|
+ locationAuthorize = false;
|
|
|
119
|
+ },
|
|
|
120
|
+ });
|
|
|
121
|
+ } else {
|
|
|
122
|
+ getMpLocation(successCallback, errCallback, isOpenSetting);
|
|
|
123
|
+ }
|
|
|
124
|
+ // #endif
|
|
|
125
|
+ // #ifdef MP-ALIPAY
|
|
|
126
|
+ getMpLocation(successCallback, errCallback, false);
|
|
|
127
|
+ // #endif
|
|
|
128
|
+ // #ifdef H5
|
|
|
129
|
+ uni.getLocation({
|
|
|
130
|
+ type: "gcj02",
|
|
|
131
|
+ success(res) {
|
|
|
132
|
+ console.log("successCallback");
|
|
|
133
|
+ successCallback(res);
|
|
|
134
|
+ },
|
|
|
135
|
+ fail(err) {
|
|
|
136
|
+ console.log("位置信息错误", err);
|
|
|
137
|
+ errCallback("位置信息获取失败");
|
|
|
138
|
+ },
|
|
|
139
|
+ });
|
|
|
140
|
+ // #endif
|
|
|
141
|
+};
|
|
|
142
|
+
|
|
|
143
|
+export function formatToDate(date = undefined, format = DATE_TIME_FORMAT) {
|
|
|
144
|
+ return moment(date).format(format);
|
|
|
145
|
+} |