@10yun/cv-pc-ui 0.2.34 → 0.2.37

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.
@@ -0,0 +1,344 @@
1
+ import Vue from 'vue';
2
+ import AxiosClassBase from 'axios';
3
+ // import { Message } from "element-ui";
4
+ import StorageClass from './storage';
5
+ import ApiFlagCommon from '@10yun/shiyun-api';
6
+ import ApiFlagDiy from '@/api/index.js';
7
+ var ApiFlagAll = Object.assign({}, ApiFlagCommon, ApiFlagDiy);
8
+ import showStatus from './_httpStatus';
9
+
10
+ // console.log(process.env.baseUrl2);
11
+ // console.log(process.env.npm_package_name);
12
+ // console.log(process.env.npm_package_description);
13
+
14
+ function getConsoleData() {
15
+ let consoleLoginData = StorageClass.localGet('consoleLoginData');
16
+ consoleLoginData = Object.assign(
17
+ {
18
+ business_id: 0,
19
+ staff_id: 0,
20
+ tokenAccess: '',
21
+ token_access: '',
22
+ token_jwt: ''
23
+ },
24
+ consoleLoginData
25
+ );
26
+ if (consoleLoginData.token_jwt != '') {
27
+ consoleLoginData.token_jwt = 'Bearer ' + consoleLoginData.token_jwt;
28
+ }
29
+ return consoleLoginData;
30
+ }
31
+ const BUSTDATA = getConsoleData();
32
+
33
+ /**
34
+ * 【初始化绑定】 request
35
+ */
36
+ /* 新创建 axios 实例配置 */
37
+ var AxiosObj = AxiosClassBase.create({
38
+ timeout: 10000, // request timeout
39
+ // 表示跨域请求时是否需要使用凭证;
40
+ // 开启withCredentials后,服务器才能拿到你的cookie
41
+ // 当然后端服务器也要设置允许你获取你开启了才有用
42
+ // withCredentials: true, // 开启跨域身份凭证
43
+ retry: 2,
44
+ baseURL: process.env._URL_API_XCX_,
45
+ baseURL: process.env.VUE_APP_SETT_APIURL || '',
46
+ headers: {
47
+ syOpenAppProject: process.env.VUE_APP_SY_OPEN_APPPRO,
48
+ syOpenAppId: process.env.VUE_APP_SY_OPEN_APPID,
49
+ syOpenAppKey: process.env.VUE_APP_SY_OPEN_APPKEY,
50
+ syOpenAppToken: BUSTDATA.token_access || '', //windows.localStorage.getItem('token-access'),
51
+ syOpenAppClientPlatform: 'pc',
52
+ Authorization: BUSTDATA.token_jwt || '' //windows.localStorage.getItem('token_jwt') || '',
53
+ // 'currPage':location.pathname,
54
+ // 'syOpenAppCsrfToken': '',
55
+ // 'syOpenAppSessionId': Lockr.get("sessionId"),
56
+ // 'X-Requested-With': 'XMLHttpRequest',
57
+ // 'Access-Control-Allow-Origin': '*',
58
+ // 'Content-Type': 'application/x-www-form-urlencoded',
59
+ // "Content-Type": "application/json; charset=UTF-8"
60
+ // get: {
61
+ // 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8'
62
+ // // 在开发中,一般还需要单点登录或者其他功能的通用请求头,可以一并配置进来
63
+ // },
64
+ // post: {
65
+ // 'Content-Type': 'application/json;charset=utf-8'
66
+ // // 在开发中,一般还需要单点登录或者其他功能的通用请求头,可以一并配置进来
67
+ // }
68
+ },
69
+ requests: {}
70
+ // transformRequest: [(data) => {
71
+ // data = JSON.stringify(data)
72
+ // return data
73
+ // }],
74
+ // validateStatus() {
75
+ // // 使用async-await,处理reject情况较为繁琐,所以全部返回resolve,在业务代码中处理异常
76
+ // return true
77
+ // },
78
+ // transformResponse: [(data) => {
79
+ // if (typeof data === 'string' && data.startsWith('{')) {
80
+ // data = JSON.parse(data)
81
+ // }
82
+ // return data
83
+ // }]
84
+ });
85
+ // AxiosObj.defaults.withCredentials = true;
86
+ // 设置全局的请求次数,请求的间隙,用于自动再次请求
87
+ AxiosObj.defaults.retry = 2;
88
+ AxiosObj.defaults.retryDelay = 1000;
89
+ /**
90
+ * 请求拦截器:request拦截器==>对请求参数做处理
91
+ */
92
+ AxiosObj.interceptors.request.use(
93
+ (config) => {
94
+ // 每次发送请求之前判断是否存在token,如果存在,则统一在http请求的header都加上token,不用每次请求都手动添加了
95
+ // 即使本地存在token,也有可能token是过期的,所以在响应拦截器中要对返回状态进行判断
96
+ // const token = store.state.token;
97
+ // token && (config.headers.Authorization = token);
98
+ // let token = localGet('token');
99
+ // if (token) config.headers.Authorization = token;
100
+ return config;
101
+ },
102
+ (error) => {
103
+ // 错误抛到业务代码
104
+ error.data = {};
105
+ error.data.message = '服务器异常,请联系管理员!';
106
+ return axiosError(error);
107
+ }
108
+ );
109
+ /**
110
+ * 响应拦截器:respone拦截器==>对响应做处理
111
+ */
112
+ AxiosObj.interceptors.response.use(
113
+ (response) => {
114
+ const responseStatus = response.status;
115
+ // let msg = ''
116
+ // if (responseStatus < 200 || responseStatus >= 300) {
117
+ // // 处理http错误,抛到业务代码
118
+ // msg = showStatus[responseStatus] || `连接出错(${responseStatus})!`;
119
+ // msg = `${msg},请检查网络或联系管理员!`
120
+ // if (typeof response.data === 'string') {
121
+ // response.data = { msg }
122
+ // } else {
123
+ // response.data.msg = msg
124
+ // }
125
+ // }
126
+ // 成功请求到数据
127
+ if (responseStatus !== 100200 && responseStatus !== 200) {
128
+ axiosError(response);
129
+ }
130
+
131
+ var apiResData = response.data;
132
+ var apiResStatus = apiResData.status || 0;
133
+ // 这里根据后端提供的数据进行对应的处理
134
+ switch (apiResStatus) {
135
+ case 10001:
136
+ case '10001': // 未登录
137
+ localStorage.removeItem('consoleLoginData');
138
+ Message({ type: 'error', message: apiResData.msg });
139
+ // window.location.href ='/';
140
+ break;
141
+ case 10002: // token过期
142
+ case '10002':
143
+ Message({ type: 'error', message: apiResData.msg });
144
+ localStorage.removeItem('consoleLoginData');
145
+ break;
146
+ case 10009: // 退出登录
147
+ case '10009':
148
+ localStorage.removeItem('consoleLoginData');
149
+ window.location.href = '/';
150
+ break;
151
+ case 100102: // 无效凭证,请重新登录
152
+ case '100102':
153
+ localStorage.removeItem('consoleLoginData');
154
+ window.location.href = '/';
155
+ break;
156
+ case 100404:
157
+ case 404:
158
+ case '404':
159
+ Message({ showClose: true, type: 'error', message: apiResData.msg || '操作失败' });
160
+ return Promise.reject(apiResData);
161
+ return;
162
+ break;
163
+ case 200:
164
+ case '200':
165
+ default:
166
+ return apiResData;
167
+ break;
168
+ }
169
+ // return response;
170
+ },
171
+ (error) => {
172
+ // 错误抛到业务代码
173
+ error.data = {};
174
+ error.data.message = '请求超时或服务器异常,请检查网络或联系管理员!';
175
+ // 响应错误处理
176
+ return axiosError(error);
177
+ }
178
+ );
179
+
180
+ function showPromiError(err) {
181
+ // console.log('=======showPromiError', err);
182
+ var errorMsg = '';
183
+ var errorStatus = '';
184
+ if (err.response) {
185
+ // The request was made and the server responded with a status code
186
+ // that falls out of the range of 2xx
187
+ // console.log(err.response);
188
+ var responseObj = err.response;
189
+ errorMsg = responseObj.data.message;
190
+ errorStatus = responseObj.status;
191
+ } else if (err.request) {
192
+ // The request was made but no response was received
193
+ // `err.request` is an instance of XMLHttpRequest in the browser and an instance of
194
+ // http.ClientRequest in node.js
195
+ // console.log(err.request);
196
+ } else {
197
+ // Something happened in setting up the request that triggered an Error
198
+ // console.log('Error', );
199
+ errorMsg = err.message;
200
+ }
201
+ let errorConf = err.config;
202
+ var errorUrl = errorConf.url;
203
+ var errorMethod = errorConf.method;
204
+ var errHtml = '';
205
+ errHtml += '<div style="color:#333;">请求异常,请重试';
206
+ errHtml += '<br><span>Error:</span> ' + '请求异常,请重试';
207
+ errHtml +=
208
+ '<br><div><span style="float:left;">url:</span> <div style="min-height:50px;width:300px;word-wrap: break-word;">' +
209
+ errorUrl +
210
+ '</div></div>';
211
+ errHtml += '<br><span>method:</span> ' + errorMethod;
212
+ errHtml += '<br><span>状态码:</span> ' + errorStatus;
213
+ errHtml +=
214
+ '<br><div><span style="float:left;">错误信息:</span> <div style="min-height:50px;width:300px;word-wrap: break-word;">' +
215
+ errorMsg +
216
+ '</div></div>';
217
+ errHtml += '</div>';
218
+
219
+ // 非401错误直接返回错误
220
+ if (err.response && errorStatus != 401) {
221
+ }
222
+ Message({
223
+ type: 'error',
224
+ showClose: true,
225
+ duration: 5000,
226
+ dangerouslyUseHTMLString: true,
227
+ message: errHtml
228
+ });
229
+ return Promise.reject(err);
230
+ /**
231
+ * 以下是,是否重新请求
232
+ */
233
+ MessageBox.confirm('超出重新请求次数~', '提示', {
234
+ confirmButtonText: '确定',
235
+ showCancelButton: false,
236
+ showClose: false,
237
+ closeOnClickModal: false,
238
+ closeOnPressEscape: false,
239
+ customClass: 'auth401box'
240
+ })
241
+ .then(() => {})
242
+ .catch(() => {});
243
+ if (!errorConf || !errorConf.retry) return Promise.reject(err);
244
+ errorConf.__retryCount = errorConf.__retryCount || 0;
245
+ if (errorConf.__retryCount >= errorConf.retry) {
246
+ // Reject with the error
247
+ return Promise.reject(err);
248
+ }
249
+ // Increase the retry count
250
+ errorConf.__retryCount += 1;
251
+ // Create new promise to handle exponential backoff
252
+ let backoff = new Promise(function (resolve) {
253
+ setTimeout(function () {
254
+ resolve();
255
+ }, errorConf.retryDelay || 1);
256
+ });
257
+ // Return the promise in which recalls axios to retry the request
258
+ return backoff.then(function () {
259
+ return http(errorConf);
260
+ });
261
+ }
262
+ // err.message = "网络波动,请重试";
263
+ var RequestClass = {
264
+ baseURL: process.env.VUE_APP_SETT_APIBASE,
265
+ /* 设置参数 */
266
+ setHeaders(options) {
267
+ this.headers = Object.assign({}, this.headers, options || {});
268
+ },
269
+ flagGet() {
270
+ let argumentsArr = arguments;
271
+ return RequestClass.flagApi('GET', argumentsArr);
272
+ },
273
+ flagPost() {
274
+ let argumentsArr = arguments;
275
+ return RequestClass.flagApi('POST', argumentsArr);
276
+ },
277
+ flagDel() {
278
+ let argumentsArr = arguments;
279
+ return RequestClass.flagApi('DELETE', argumentsArr);
280
+ },
281
+ flagPut() {
282
+ let argumentsArr = arguments;
283
+ return RequestClass.flagApi('PUT', argumentsArr);
284
+ },
285
+ /* 图片上传通用 */
286
+ flagUpImg() {
287
+ let argumentsArr = arguments;
288
+ return RequestClass.flagApi('UPLOAD', argumentsArr);
289
+ },
290
+ flagApi(methodType, argumentsArr) {
291
+ // let _this = this;
292
+ let argNum = argumentsArr.length || 0;
293
+ if (argNum <= 0 || argNum > 2) {
294
+ console.error('-- flag' + methodType + ': 参数为(1-2)个---');
295
+ return false;
296
+ }
297
+
298
+ let apiFlag = argumentsArr[0];
299
+ let apiUrl = '';
300
+ if (typeof apiFlag === 'string') {
301
+ apiFlag = apiFlag || '';
302
+ if (apiFlag == '') {
303
+ apiUrl = '';
304
+ } else {
305
+ apiUrl = ApiFlagAll[apiFlag] || '';
306
+ }
307
+ }
308
+ if (apiUrl == '') {
309
+ return new Promise((resolve, reject) => {
310
+ return reject({
311
+ msg: ' flag' + methodType + ':传入的标示 { ' + `${apiFlag}` + ' },未匹配到 apiUrl '
312
+ });
313
+ });
314
+ }
315
+ // 如果传回一个
316
+ if (argNum == 1) {
317
+ return function (reqData) {
318
+ return RequestClass.apiAll(methodType, apiUrl, reqData);
319
+ };
320
+ } else if (argNum == 2 && typeof argumentsArr[1] === 'object') {
321
+ let reqData = argumentsArr[1] || {};
322
+ return RequestClass.apiAll(methodType, apiUrl, reqData);
323
+ }
324
+ },
325
+ apiAll(type, apiUrl, reqData) {
326
+ if (type == 'POST') {
327
+ return AxiosObj.post(apiUrl, reqData, {
328
+ // headers: {
329
+ // 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
330
+ // 'Accept': 'application/json, text/javascript, */*; q=0.01',
331
+ // }
332
+ });
333
+ } else if (type == 'GET') {
334
+ return AxiosObj.get(apiUrl, {
335
+ params: {
336
+ ...reqData
337
+ }
338
+ });
339
+ }
340
+ }
341
+ };
342
+
343
+ Vue.prototype.$consoleData = BUSTDATA;
344
+ Vue.prototype.$request = RequestClass;
@@ -0,0 +1,58 @@
1
+ class RequestCacheClass {
2
+ // 默认的数据 - 存到缓存
3
+ _initFormData(initData) {
4
+ let pathOldStr = this.$route.path || this.$route.name;
5
+ let pathNewStr = pathOldStr.replace(/\//g, '_');
6
+ // let pathNewStr = pathOldStr.replaceAll('/', "_")
7
+ console.log(pathOldStr, pathNewStr);
8
+ sessionStorage.setItem(pathNewStr, JSON.stringify(initData));
9
+ }
10
+ // 验证存储 - 缓存数据
11
+ _checkFormData(checkData) {
12
+ let pathOldStr = this.$route.path || this.$route.name;
13
+ let pathNewStr = pathOldStr.replace(/\//g, '_');
14
+ let cacheData = sessionStorage.getItem(pathNewStr) || '';
15
+ if (cacheData == '') {
16
+ return true;
17
+ }
18
+ if (JSON.stringify(checkData) == cacheData) {
19
+ console.log('表单没变化,允许离开');
20
+ return false;
21
+ } else {
22
+ console.log('表单变化,询问是否保存');
23
+ return true;
24
+ }
25
+ }
26
+
27
+ // 表单数据处理 - 获取2个表单修改的字段
28
+ _getFormChangeData(changeData) {
29
+ let pathOldStr = this.$route.path || this.$route.name;
30
+ let pathNewStr = pathOldStr.replace(/\//g, '_');
31
+ let cacheData = sessionStorage.getItem(pathNewStr) || '';
32
+ if (cacheData == '') {
33
+ return changeData;
34
+ }
35
+ let oldData = JSON.parse(cacheData);
36
+
37
+ let lastData = {};
38
+
39
+ let aProps = Object.getOwnPropertyNames(oldData);
40
+ let bProps = Object.getOwnPropertyNames(changeData);
41
+
42
+ // console.log(aProps, bProps);
43
+ //先判断两个数据length
44
+ // if (aProps.length == bProps.length) {
45
+ //循环拿到数值进行对比
46
+ aProps.forEach((e) => {
47
+ if (oldData[e] !== changeData[e]) {
48
+ // console.log('数据改变')
49
+ lastData[e] = changeData[e];
50
+ } else {
51
+ // console.log('数据不变')
52
+ // return false;
53
+ }
54
+ });
55
+ // } else { return false }
56
+ return lastData;
57
+ }
58
+ }
@@ -14,7 +14,7 @@ function sessionSet(key, value) {
14
14
  function sessionGet(key) {
15
15
  let _data = sessionStorage.getItem(key);
16
16
  try {
17
- return JSON.parse(_data)
17
+ return JSON.parse(_data);
18
18
  } catch (e) {
19
19
  return _data;
20
20
  }
@@ -25,7 +25,7 @@ function sessionGet(key) {
25
25
  * @param {*} key 键名
26
26
  */
27
27
  function sessionDel(key) {
28
- sessionStorage.removeItem(key)
28
+ sessionStorage.removeItem(key);
29
29
  }
30
30
 
31
31
  /**
@@ -47,7 +47,7 @@ function sessionClear() {
47
47
  */
48
48
  function localSet(key, value) {
49
49
  if (!window.localStorage) {
50
- console.warn("浏览器不支持localStorage")
50
+ console.warn('浏览器不支持localStorage');
51
51
  return;
52
52
  }
53
53
  window.localStorage.setItem(key, JSON.stringify(value));
@@ -59,7 +59,7 @@ function localSet(key, value) {
59
59
  */
60
60
  function localGet(key) {
61
61
  if (!window.localStorage) {
62
- console.warn("浏览器不支持localStorage")
62
+ console.warn('浏览器不支持localStorage');
63
63
  return;
64
64
  }
65
65
  let _data = window.localStorage.getItem(key);
@@ -83,7 +83,7 @@ function localGet(key) {
83
83
  */
84
84
  function localDel(key) {
85
85
  if (!window.localStorage) return;
86
- window.localStorage.removeItem(key)
86
+ window.localStorage.removeItem(key);
87
87
  }
88
88
 
89
89
  export default {
@@ -94,4 +94,4 @@ export default {
94
94
  localSet,
95
95
  localGet,
96
96
  localDel
97
- }
97
+ };
@@ -610,5 +610,5 @@ export default {
610
610
  987600: '瓦利斯和富图纳',
611
611
  988200: '萨摩亚',
612
612
  988700: '也门',
613
- 989400: '赞比亚',
613
+ 989400: '赞比亚'
614
614
  };
@@ -609,5 +609,5 @@ export default {
609
609
  987600: '瓦利斯和富图纳',
610
610
  988200: '萨摩亚',
611
611
  988700: '也门',
612
- 989400: '赞比亚',
612
+ 989400: '赞比亚'
613
613
  };
@@ -3390,5 +3390,5 @@ export default {
3390
3390
  820106: '风顺堂区',
3391
3391
  820202: '嘉模堂区',
3392
3392
  820203: '路氹填海区',
3393
- 820204: '圣方济各堂区',
3393
+ 820204: '圣方济各堂区'
3394
3394
  };
@@ -33,5 +33,5 @@ export default {
33
33
  710000: '台湾省',
34
34
  810000: '香港特别行政区',
35
35
  820000: '澳门特别行政区',
36
- 900000: '海外',
36
+ 900000: '海外'
37
37
  };