@10yun/cv-mobile-ui 0.4.6 → 0.4.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@10yun/cv-mobile-ui",
3
- "version": "0.4.6",
3
+ "version": "0.4.8",
4
4
  "description": "十云cvjs移动端ui,适用uniapp",
5
5
  "author": "",
6
6
  "license": "Apache-2.0",
@@ -0,0 +1,87 @@
1
+ const MessageBox = function (options) {};
2
+
3
+ /**
4
+ * alert 消息提示
5
+ * @author cvjs
6
+ * @param {string} content 内容,默认为空
7
+ * @param {string} title 标题,默认为空
8
+ * @param {string} confirmText 确认按钮,默认确定
9
+ * */
10
+ MessageBox['alert'] = (content, title, confirmText) => {
11
+ return new Promise((res, rej) => {
12
+ uni.showModal({
13
+ title: title || '',
14
+ content: String(content || '') || '',
15
+ confirmText: confirmText || '确定',
16
+ showCancel: false,
17
+ success: function (modalRes) {
18
+ if (modalRes.confirm) {
19
+ res(modalRes);
20
+ } else if (modalRes.cancel) {
21
+ console.log('用户点击了取消');
22
+ }
23
+ },
24
+ fail: function (err) {
25
+ rej(err);
26
+ }
27
+ });
28
+ });
29
+ };
30
+ /**
31
+ * confirm 确认消息
32
+ * @author cvjs
33
+ * @param {string} title 确认标题, 默认提示
34
+ * @param {string} content 确认内容, 默认??
35
+ * */
36
+ MessageBox['confirm'] = (content, title) => {
37
+ return new Promise((res, rej) => {
38
+ uni.showModal({
39
+ title: title || '提示',
40
+ content: String(content || '') || '??',
41
+ confirmText: '确定',
42
+ showCancel: showCancel || true,
43
+ cancelText: cancelText || '取消',
44
+ success: function (modalRes) {
45
+ if (modalRes.confirm) {
46
+ res(modalRes);
47
+ } else if (modalRes.cancel) {
48
+ console.log('用户点击了取消');
49
+ }
50
+ },
51
+ fail: function (err) {
52
+ rej(err);
53
+ }
54
+ });
55
+ });
56
+ };
57
+
58
+ /**
59
+ * prompt 提交内容
60
+ * @author cvjs
61
+ * @param {string} title 标题,默认请输入
62
+ * @param {string} content 输入内容,默认为空
63
+ * */
64
+ MessageBox['prompt'] = (content, title) => {
65
+ return new Promise((res, rej) => {
66
+ uni.showModal({
67
+ title: title || '请输入',
68
+ content: String(content || '') || '',
69
+ confirmText: '确定',
70
+ showCancel: true,
71
+ cancelText: '取消',
72
+ editable: true,
73
+ success: function (modalRes) {
74
+ if (modalRes.confirm) {
75
+ res(modalRes);
76
+ } else if (modalRes.cancel) {
77
+ console.log('用户点击了取消');
78
+ }
79
+ },
80
+ fail: function (err) {
81
+ rej(err);
82
+ }
83
+ });
84
+ });
85
+ };
86
+
87
+ export default MessageBox;
@@ -0,0 +1,56 @@
1
+ const MessageTip = function (options) {
2
+ if (Object.prototype.toString.call(options) === '[object Object]') {
3
+ let typeIcon =
4
+ options.type == 'success'
5
+ ? 'none'
6
+ : options.type == 'warning'
7
+ ? 'none'
8
+ : options.type == 'error'
9
+ ? 'none'
10
+ : options.type == 'info'
11
+ ? 'none'
12
+ : 'none';
13
+
14
+ let setting = {
15
+ title: options.message || '提示',
16
+ duration: options.duration || 1500,
17
+ icon: typeIcon || 'none',
18
+ mask: true
19
+ };
20
+ uni.showToast(setting);
21
+ } else if (Object.prototype.toString.call(options) === '[object String]') {
22
+ MessageTip['info'](options);
23
+ }
24
+ };
25
+ /**
26
+ * 显示提示框,2s消失的提示框
27
+ * @author xiesuhang
28
+ * @param {string} title 标题
29
+ * @param {string} duration 显示时间
30
+ * @param {string} icon 弹框类型 icon 值说明 success loading none
31
+ *
32
+ **/
33
+ MessageTip['info'] = (title, duration, icon) => {
34
+ uni.showToast({
35
+ title: title || '提示',
36
+ duration: duration || 3500,
37
+ icon: icon || 'none',
38
+ mask: true
39
+ });
40
+ };
41
+ // 成功提示
42
+ MessageTip['success'] = (title, duration) => {
43
+ // MessageTip['info'](title, duration, 'success');
44
+ MessageTip['info'](title, duration, 'none');
45
+ };
46
+ // 警告提示
47
+ MessageTip['warning'] = (title, duration) => {
48
+ MessageTip['info'](title, duration, 'none');
49
+ };
50
+ // 错误提示
51
+ MessageTip['error'] = (title, duration) => {
52
+ // MessageTip['info'](title, duration, 'error');
53
+ MessageTip['info'](title, duration, 'none');
54
+ };
55
+
56
+ export default MessageTip;
package/plugins/jumps.js CHANGED
@@ -104,13 +104,6 @@ class JumpsClass {
104
104
  jumpsHome(time) {
105
105
  this.jumpsPage(this.page_home, time);
106
106
  }
107
- //刷新页面
108
- jumpsReload(url) {
109
- url = url || '';
110
- if (url != '') {
111
- uni.redirectTo({ url: url });
112
- }
113
- }
114
107
  // 上一个页面
115
108
  jumpsPre() {
116
109
  let pages = getCurrentPages();
@@ -300,15 +300,16 @@ class RequestClass {
300
300
  apiResData = JSON.parse(apiResData, true);
301
301
  }
302
302
  return _this.setResponse(apiResData);
303
+ } else if (uniRes[1].statusCode == 502) {
304
+ uni.hideNavigationBarLoading();
305
+ uni.hideToast();
306
+ uni.hideLoading();
303
307
  } else {
304
308
  uni.hideNavigationBarLoading();
305
309
  uni.hideToast();
306
310
  uni.hideLoading();
307
- //
308
- // uni.request({
309
- // url: '',
310
- // })
311
- if (type == 'POST')
311
+
312
+ if (type == 'POST') {
312
313
  uni.showModal({
313
314
  content: '加载错误!请稍后重试',
314
315
  showCancel: false,
@@ -320,6 +321,7 @@ class RequestClass {
320
321
  }
321
322
  }
322
323
  });
324
+ }
323
325
  }
324
326
  })
325
327
  .catch(function (uniRes) {
@@ -5,10 +5,57 @@
5
5
  * 使用方法 【
6
6
  *
7
7
  */
8
+
9
+ function get_data1(key, def) {
10
+ uni.getStorage({
11
+ key: key,
12
+ success: function (res) {
13
+ param.success(res.data || def);
14
+ }
15
+ });
16
+ }
17
+ function get_data2(key, def) {
18
+ const value = uni.getStorageSync(key);
19
+ return value || def;
20
+ }
8
21
  class StorageClass {
9
22
  //实例化类时默认会执行构造函数
10
23
  constructor(options = {}) {
11
- this.config = options;
24
+ this.config = Object.assign(
25
+ {
26
+ prefix: '',
27
+ suffix: ''
28
+ },
29
+ options
30
+ );
31
+ }
32
+ _getAllCache() {
33
+ let fullKey = this._getFullKey('___') || {};
34
+ let fullCache = uni.getStorageSync(fullKey);
35
+ return fullCache;
36
+ }
37
+ _setAllCache(appendKey) {
38
+ let fullKey = this._getFullKey('___');
39
+ let fullCache = uni.getStorageSync(fullKey) || {};
40
+ fullCache[appendKey] = 1;
41
+ uni.setStorageSync(fullKey, fullCache);
42
+ }
43
+ _removeAllCache(removeKey) {
44
+ let fullKey = this._getFullKey('___');
45
+ let fullCache = uni.getStorageSync(fullKey) || {};
46
+ delete fullCache[removeKey];
47
+ uni.setStorageSync(fullKey, fullCache);
48
+ }
49
+ _getFullKey(key) {
50
+ key = key || '';
51
+ const config = this.config;
52
+ if (config.prefix) {
53
+ key = config.prefix + key;
54
+ }
55
+ if (config.suffix) {
56
+ key += config.suffix;
57
+ }
58
+ return key;
12
59
  }
13
60
  /**
14
61
  * 设置缓存 - 异步
@@ -22,16 +69,10 @@ class StorageClass {
22
69
  * boolean cache.put('k', true);
23
70
  */
24
71
 
25
- set(key = '', data = '', t = 0) {
26
- const config = this.config;
27
- if (config.prefix) {
28
- key = config.prefix + key;
29
- }
30
- if (config.suffix) {
31
- key += config.prefix;
32
- }
72
+ setAsync(key = '', data = '', t = 0) {
73
+ let fullKey = this._getFullKey(key);
33
74
  uni.setStorage({
34
- key: key,
75
+ key: fullKey,
35
76
  data: data,
36
77
  success: () => {}
37
78
  });
@@ -39,34 +80,30 @@ class StorageClass {
39
80
  if (t) {
40
81
  let timestamp = parseInt(new Date().getTime());
41
82
  uni.setStorage({
42
- key: key + '_time',
83
+ key: fullKey + '_time',
43
84
  data: timestamp + t * 1000,
44
85
  success: () => {}
45
86
  });
46
87
  }
88
+ this._setAllCache(fullKey);
47
89
  }
48
90
  setSync(key = '', data = null, t = 0) {
91
+ let fullKey = this._getFullKey(key);
49
92
  try {
50
- const config = this.config;
51
- if (config.prefix) {
52
- key = config.prefix + key;
53
- }
54
- if (config.suffix) {
55
- key += config.prefix;
56
- }
57
- uni.setStorageSync(key, data);
93
+ uni.setStorageSync(fullKey, data);
58
94
  /* 设置过期时间 */
59
95
  if (t) {
60
96
  let timestamp = parseInt(new Date().getTime());
61
- uni.setStorageSync(key + '_time', timestamp + t * 1000);
97
+ uni.setStorageSync(fullKey + '_time', timestamp + t * 1000);
62
98
  }
99
+ this._setAllCache(fullKey);
63
100
  } catch (e) {
64
101
  console.error(e);
65
102
  }
66
103
  }
67
104
  /**
68
105
  * 获取缓存
69
- * @param {[type]} k [键名]
106
+ * @param {[type]} key [键名]
70
107
  * @param {[type]} def [获取为空时默认]
71
108
  *
72
109
  * @使用方式 ==== 【读取缓存】
@@ -78,22 +115,18 @@ class StorageClass {
78
115
  * 根据key获取数据缓存 - 异步
79
116
  * @param {String} key
80
117
  */
81
- get(param) {
118
+ getAsync(param) {
82
119
  param = Object.assign({ def: '' }, param);
83
- const config = this.config;
84
- if (config.prefix) {
85
- param.key = config.prefix + '_' + param.key;
86
- }
87
- if (config.suffix) {
88
- param.key += '_' + config.prefix;
89
- }
120
+
121
+ let fullKey = this._getFullKey(param.key);
122
+
90
123
  //先获取时间
91
124
  var deadtime = 0;
92
125
  uni.getStorage({
93
- key: param.key + '_time',
126
+ key: fullKey + '_time',
94
127
  success: function (res) {
95
128
  if (!res.data) {
96
- get_data(param.key, param.success);
129
+ get_data1(fullKey, param.success);
97
130
  } else {
98
131
  deadtime = parseInt(res.data);
99
132
  let timestamp = parseInt(new Date().getTime());
@@ -101,37 +134,21 @@ class StorageClass {
101
134
  //过期了
102
135
  param.success(def);
103
136
  }
104
- get_data(param.key);
137
+ get_data1(fullKey, def);
105
138
  }
106
139
  }
107
140
  });
108
- function get_data(key) {
109
- uni.getStorage({
110
- key: key,
111
- success: function (res) {
112
- param.success(res.data || def);
113
- }
114
- });
115
- }
116
141
  }
117
142
  /**
118
143
  * 根据key获取数据缓存 - 同步
119
144
  * @param {String} key
120
145
  */
121
146
  getSync(key, def = '') {
147
+ let fullKey = this._getFullKey(key);
122
148
  try {
123
- const config = this.config;
124
- if (config.prefix) {
125
- key = config.prefix + key;
126
- }
127
- if (config.suffix) {
128
- key += config.prefix;
129
- }
130
-
131
- let deadtime = uni.getStorageSync(key + '_time');
132
-
149
+ let deadtime = uni.getStorageSync(fullKey + '_time');
133
150
  if (!deadtime) {
134
- return get_data(key);
151
+ return get_data2(fullKey, def);
135
152
  } else {
136
153
  deadtime = parseInt(deadtime);
137
154
  let timestamp = parseInt(new Date().getTime());
@@ -139,34 +156,32 @@ class StorageClass {
139
156
  //过期了
140
157
  return def;
141
158
  }
142
- return get_data(key);
159
+ return get_data2(fullKey, def);
143
160
  }
144
161
  } catch (e) {
145
162
  console.error(e);
146
163
  }
147
- function get_data(key) {
148
- const value = uni.getStorageSync(key);
149
- return value || def;
150
- }
151
164
  }
152
165
  /**
153
166
  * 根据key删除一条缓存 - 异步
154
- * @param {String} key
167
+ * @param {String|Object} pararm 支持传入字符串、对象
155
168
  */
156
- remove(key) {
157
- const config = this.config;
158
- if (config.prefix) {
159
- key = config.prefix + key;
160
- }
161
- if (config.suffix) {
162
- key += config.prefix;
169
+ removeAsync(param) {
170
+ let fullKey = '';
171
+ if (Object.prototype.toString.call(param) === '[object Object]') {
172
+ fullKey = this._getFullKey(param.key);
173
+ param.key = fullKey;
174
+ uni.removeStorage(param);
175
+ } else if (Object.prototype.toString.call(param) === '[object String]') {
176
+ fullKey = this._getFullKey(param);
177
+ uni.removeStorage({
178
+ key: fullKey
179
+ });
163
180
  }
181
+ this._removeAllCache(fullKey);
182
+
164
183
  uni.removeStorage({
165
- key: key,
166
- success: (res) => {}
167
- });
168
- uni.removeStorage({
169
- key: key + '_time',
184
+ key: fullKey + '_time',
170
185
  success: (res) => {}
171
186
  });
172
187
  }
@@ -175,16 +190,11 @@ class StorageClass {
175
190
  * @param {String} key
176
191
  */
177
192
  removeSync(key) {
193
+ let fullKey = this._getFullKey(key);
178
194
  try {
179
- const config = this.config;
180
- if (config.prefix) {
181
- key = config.prefix + key;
182
- }
183
- if (config.suffix) {
184
- key += config.prefix;
185
- }
186
- uni.removeStorageSync(key);
187
- uni.removeStorageSync(key + '_time');
195
+ uni.removeStorageSync(fullKey);
196
+ uni.removeStorageSync(fullKey + '_time');
197
+ this._removeAllCache(fullKey);
188
198
  } catch (e) {
189
199
  console.error(e);
190
200
  }
@@ -192,7 +202,7 @@ class StorageClass {
192
202
  /**
193
203
  * 清除用户端所用缓存
194
204
  */
195
- clear() {
205
+ clearAsync() {
196
206
  uni.clearStorage();
197
207
  }
198
208
  /**
@@ -205,7 +215,6 @@ class StorageClass {
205
215
  console.error(e);
206
216
  }
207
217
  }
208
-
209
218
  /**
210
219
  * 同步获取当前 storage 的相关信息。 - 异步
211
220
  */
@@ -0,0 +1,181 @@
1
+ /***
2
+ * title: storage.js
3
+ * Author: Gaby
4
+ * Email: xxx@126.com
5
+ * Time: 2022/6/1 17:30
6
+ * last: 2022/6/2 17:30
7
+ * Desc: 对存储的简单封装
8
+ */
9
+
10
+ import CryptoJS from 'crypto-js';
11
+
12
+ // 十六位十六进制数作为密钥
13
+ const SECRET_KEY = CryptoJS.enc.Utf8.parse('3333e6e143439161');
14
+ // 十六位十六进制数作为密钥偏移量
15
+ const SECRET_IV = CryptoJS.enc.Utf8.parse('e3bbe7e3ba84431a');
16
+
17
+ // 类型 window.localStorage,window.sessionStorage,
18
+ const config = {
19
+ type: 'localStorage', // 本地存储类型 sessionStorage
20
+ prefix: 'SDF_0.0.1', // 名称前缀 建议:项目名 + 项目版本
21
+ expire: 1, //过期时间 单位:秒
22
+ isEncrypt: true // 默认加密 为了调试方便, 开发过程中可以不加密
23
+ };
24
+
25
+ // 判断是否支持 Storage
26
+ export const isSupportStorage = () => {
27
+ return typeof Storage !== 'undefined' ? true : false;
28
+ };
29
+
30
+ // 设置 setStorage
31
+ export const setStorage = (key, value, expire = 0) => {
32
+ if (value === '' || value === null || value === undefined) {
33
+ value = null;
34
+ }
35
+
36
+ if (isNaN(expire) || expire < 0) throw new Error('Expire must be a number');
37
+
38
+ expire = (expire ? expire : config.expire) * 1000;
39
+ let data = {
40
+ value: value, // 存储值
41
+ time: Date.now(), //存值时间戳
42
+ expire: expire // 过期时间
43
+ };
44
+
45
+ const encryptString = config.isEncrypt ? encrypt(JSON.stringify(data)) : JSON.stringify(data);
46
+
47
+ window[config.type].setItem(autoAddPrefix(key), encryptString);
48
+ };
49
+
50
+ // 获取 getStorage
51
+ export const getStorage = (key) => {
52
+ key = autoAddPrefix(key);
53
+ // key 不存在判断
54
+ if (!window[config.type].getItem(key) || JSON.stringify(window[config.type].getItem(key)) === 'null') {
55
+ return null;
56
+ }
57
+
58
+ // 优化 持续使用中续期
59
+ const storage = config.isEncrypt
60
+ ? JSON.parse(decrypt(window[config.type].getItem(key)))
61
+ : JSON.parse(window[config.type].getItem(key));
62
+
63
+ let nowTime = Date.now();
64
+
65
+ // 过期删除
66
+ if (storage.expire && config.expire * 6000 < nowTime - storage.time) {
67
+ removeStorage(key);
68
+ return null;
69
+ } else {
70
+ // 未过期期间被调用 则自动续期 进行保活
71
+ setStorage(autoRemovePrefix(key), storage.value);
72
+ return storage.value;
73
+ }
74
+ };
75
+
76
+ // 是否存在 hasStorage
77
+ export const hasStorage = (key) => {
78
+ key = autoAddPrefix(key);
79
+ let arr = getStorageAll().filter((item) => {
80
+ return item.key === key;
81
+ });
82
+ return arr.length ? true : false;
83
+ };
84
+
85
+ // 获取所有key
86
+ export const getStorageKeys = () => {
87
+ let items = getStorageAll();
88
+ let keys = [];
89
+ for (let index = 0; index < items.length; index++) {
90
+ keys.push(items[index].key);
91
+ }
92
+ return keys;
93
+ };
94
+
95
+ // 根据索引获取key
96
+ export const getStorageForIndex = (index) => {
97
+ return window[config.type].key(index);
98
+ };
99
+
100
+ // 获取localStorage长度
101
+ export const getStorageLength = () => {
102
+ return window[config.type].length;
103
+ };
104
+
105
+ // 获取全部 getAllStorage
106
+ export const getStorageAll = () => {
107
+ let len = window[config.type].length; // 获取长度
108
+ let arr = new Array(); // 定义数据集
109
+ for (let i = 0; i < len; i++) {
110
+ // 获取key 索引从0开始
111
+ let getKey = window[config.type].key(i);
112
+ // 获取key对应的值
113
+ let getVal = window[config.type].getItem(getKey);
114
+ // 放进数组
115
+ arr[i] = { key: getKey, val: getVal };
116
+ }
117
+ return arr;
118
+ };
119
+
120
+ // 删除 removeStorage
121
+ export const removeStorage = (key) => {
122
+ window[config.type].removeItem(autoAddPrefix(key));
123
+ };
124
+
125
+ // 清空 clearStorage
126
+ export const clearStorage = () => {
127
+ window[config.type].clear();
128
+ };
129
+
130
+ // 名称前自动添加前缀
131
+ const autoAddPrefix = (key) => {
132
+ const prefix = config.prefix ? config.prefix + '_' : '';
133
+ return prefix + key;
134
+ };
135
+
136
+ // 移除已添加的前缀
137
+ const autoRemovePrefix = (key) => {
138
+ const len = config.prefix ? config.prefix.length + 1 : '';
139
+ return key.substr(len);
140
+ // const prefix = config.prefix ? config.prefix + '_' : '';
141
+ // return prefix + key;
142
+ };
143
+
144
+ /**
145
+ * 加密方法
146
+ * @param data
147
+ * @returns {string}
148
+ */
149
+ const encrypt = (data) => {
150
+ if (typeof data === 'object') {
151
+ try {
152
+ data = JSON.stringify(data);
153
+ } catch (error) {
154
+ console.log('encrypt error:', error);
155
+ }
156
+ }
157
+ const dataHex = CryptoJS.enc.Utf8.parse(data);
158
+ const encrypted = CryptoJS.AES.encrypt(dataHex, SECRET_KEY, {
159
+ iv: SECRET_IV,
160
+ mode: CryptoJS.mode.CBC,
161
+ padding: CryptoJS.pad.Pkcs7
162
+ });
163
+ return encrypted.ciphertext.toString();
164
+ };
165
+
166
+ /**
167
+ * 解密方法
168
+ * @param data
169
+ * @returns {string}
170
+ */
171
+ const decrypt = (data) => {
172
+ const encryptedHexStr = CryptoJS.enc.Hex.parse(data);
173
+ const str = CryptoJS.enc.Base64.stringify(encryptedHexStr);
174
+ const decrypt = CryptoJS.AES.decrypt(str, SECRET_KEY, {
175
+ iv: SECRET_IV,
176
+ mode: CryptoJS.mode.CBC,
177
+ padding: CryptoJS.pad.Pkcs7
178
+ });
179
+ const decryptedStr = decrypt.toString(CryptoJS.enc.Utf8);
180
+ return decryptedStr.toString();
181
+ };