ui-ddy-pc 0.0.1-beta
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/.env.development +4 -0
- package/.env.prod +1 -0
- package/.env.stage +3 -0
- package/.vscode/extensions.json +3 -0
- package/README.md +7 -0
- package/build/configure/package.json +11 -0
- package/index.html +13 -0
- package/index.js +4 -0
- package/package.json +33 -0
- package/src/App.vue +20 -0
- package/src/assets/table/empty-data.png +0 -0
- package/src/assets/table/magnifier.svg +7 -0
- package/src/assets/vue.svg +1 -0
- package/src/components/tableTest.vue +101 -0
- package/src/components/topSearch/search.vue +302 -0
- package/src/components/topSearch/searchItem.vue +80 -0
- package/src/components/topSign/topSign.vue +170 -0
- package/src/components/topTable/topTable.vue +854 -0
- package/src/docs/.vitepress/cache/deps/@theme_index.js +258 -0
- package/src/docs/.vitepress/cache/deps/@theme_index.js.map +7 -0
- package/src/docs/.vitepress/cache/deps/_metadata.json +40 -0
- package/src/docs/.vitepress/cache/deps/chunk-KGHB62SH.js +11434 -0
- package/src/docs/.vitepress/cache/deps/chunk-KGHB62SH.js.map +7 -0
- package/src/docs/.vitepress/cache/deps/chunk-TBELKJNH.js +9088 -0
- package/src/docs/.vitepress/cache/deps/chunk-TBELKJNH.js.map +7 -0
- package/src/docs/.vitepress/cache/deps/package.json +3 -0
- package/src/docs/.vitepress/cache/deps/vitepress___@vue_devtools-api.js +2588 -0
- package/src/docs/.vitepress/cache/deps/vitepress___@vue_devtools-api.js.map +7 -0
- package/src/docs/.vitepress/cache/deps/vitepress___@vueuse_core.js +567 -0
- package/src/docs/.vitepress/cache/deps/vitepress___@vueuse_core.js.map +7 -0
- package/src/docs/.vitepress/cache/deps/vue.js +323 -0
- package/src/docs/.vitepress/cache/deps/vue.js.map +7 -0
- package/src/docs/.vitepress/config.js +28 -0
- package/src/docs/api-examples.md +49 -0
- package/src/docs/combinedTable.md +158 -0
- package/src/docs/index.md +25 -0
- package/src/docs/markdown-examples.md +98 -0
- package/src/docs/unitTests/searchTest.vue +109 -0
- package/src/main.js +16 -0
- package/src/packages/index.js +3 -0
- package/src/router/index.js +24 -0
- package/src/store/index.js +35 -0
- package/src/style.css +73 -0
- package/src/utils/common.js +254 -0
- package/src/utils/currency.js +256 -0
- package/src/utils/errorCode.js +6 -0
- package/src/utils/request.js +220 -0
- package/src/utils/top.js +233 -0
- package/ui-ddy-pc/package.json +11 -0
- package/ui-ddy-pc/style.css +1 -0
- package/ui-ddy-pc/ui-ddy-pc.js +26436 -0
- package/ui-ddy-pc/ui-ddy-pc.umd.cjs +83 -0
- package/vite.config.js +54 -0
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* currency.js - v2.0.4
|
|
3
|
+
* http://scurker.github.io/currency.js
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) 2021 Jason Wilson
|
|
6
|
+
* Released under MIT license
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
'use strict';
|
|
10
|
+
|
|
11
|
+
var defaults = {
|
|
12
|
+
symbol: '$',
|
|
13
|
+
separator: ',',
|
|
14
|
+
decimal: '.',
|
|
15
|
+
errorOnInvalid: false,
|
|
16
|
+
precision: 2,
|
|
17
|
+
pattern: '!#',
|
|
18
|
+
negativePattern: '-!#',
|
|
19
|
+
format: format,
|
|
20
|
+
fromCents: false
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
var round = function round(v) {
|
|
24
|
+
return Math.round(v);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
var pow = function pow(p) {
|
|
28
|
+
return Math.pow(10, p);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
var rounding = function rounding(value, increment) {
|
|
32
|
+
return round(value / increment) * increment;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
var groupRegex = /(\d)(?=(\d{3})+\b)/g;
|
|
36
|
+
var vedicRegex = /(\d)(?=(\d\d)+\d\b)/g;
|
|
37
|
+
/**
|
|
38
|
+
* Create a new instance of currency.js
|
|
39
|
+
* @param {number|string|currency} value
|
|
40
|
+
* @param {object} [opts]
|
|
41
|
+
*/
|
|
42
|
+
|
|
43
|
+
function currency(value, opts) {
|
|
44
|
+
var that = this;
|
|
45
|
+
|
|
46
|
+
if (!(that instanceof currency)) {
|
|
47
|
+
return new currency(value, opts);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
var settings = Object.assign({}, defaults, opts),
|
|
51
|
+
precision = pow(settings.precision),
|
|
52
|
+
v = parse(value, settings);
|
|
53
|
+
that.intValue = v;
|
|
54
|
+
that.value = v / precision; // Set default incremental value
|
|
55
|
+
|
|
56
|
+
settings.increment = settings.increment || 1 / precision; // Support vedic numbering systems
|
|
57
|
+
// see: https://en.wikipedia.org/wiki/Indian_numbering_system
|
|
58
|
+
|
|
59
|
+
if (settings.useVedic) {
|
|
60
|
+
settings.groups = vedicRegex;
|
|
61
|
+
} else {
|
|
62
|
+
settings.groups = groupRegex;
|
|
63
|
+
} // Intended for internal usage only - subject to change
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
this.s = settings;
|
|
67
|
+
this.p = precision;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function parse(value, opts) {
|
|
71
|
+
var useRounding = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
72
|
+
var v = 0,
|
|
73
|
+
decimal = opts.decimal,
|
|
74
|
+
errorOnInvalid = opts.errorOnInvalid,
|
|
75
|
+
decimals = opts.precision,
|
|
76
|
+
fromCents = opts.fromCents,
|
|
77
|
+
precision = pow(decimals),
|
|
78
|
+
isNumber = typeof value === 'number',
|
|
79
|
+
isCurrency = value instanceof currency;
|
|
80
|
+
|
|
81
|
+
if (isCurrency && fromCents) {
|
|
82
|
+
return value.intValue;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (isNumber || isCurrency) {
|
|
86
|
+
v = isCurrency ? value.value : value;
|
|
87
|
+
} else if (typeof value === 'string') {
|
|
88
|
+
var regex = new RegExp('[^-\\d' + decimal + ']', 'g'),
|
|
89
|
+
decimalString = new RegExp('\\' + decimal, 'g');
|
|
90
|
+
v = value.replace(/\((.*)\)/, '-$1') // allow negative e.g. (1.99)
|
|
91
|
+
.replace(regex, '') // replace any non numeric values
|
|
92
|
+
.replace(decimalString, '.'); // convert any decimal values
|
|
93
|
+
|
|
94
|
+
v = v || 0;
|
|
95
|
+
} else {
|
|
96
|
+
if (errorOnInvalid) {
|
|
97
|
+
throw Error('Invalid Input');
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
v = 0;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (!fromCents) {
|
|
104
|
+
v *= precision; // scale number to integer value
|
|
105
|
+
|
|
106
|
+
v = v.toFixed(6); // Handle additional decimal for proper rounding.
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return useRounding ? round(v) : v;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Formats a currency object
|
|
113
|
+
* @param currency
|
|
114
|
+
* @param {object} [opts]
|
|
115
|
+
*/
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
function format(currency, settings) {
|
|
119
|
+
var pattern = settings.pattern,
|
|
120
|
+
negativePattern = settings.negativePattern,
|
|
121
|
+
symbol = settings.symbol,
|
|
122
|
+
separator = settings.separator,
|
|
123
|
+
decimal = settings.decimal,
|
|
124
|
+
groups = settings.groups,
|
|
125
|
+
split = ('' + currency).replace(/^-/, '').split('.'),
|
|
126
|
+
dollars = split[0],
|
|
127
|
+
cents = split[1];
|
|
128
|
+
return (currency.value >= 0 ? pattern : negativePattern).replace('!', symbol).replace('#', dollars.replace(groups, '$1' + separator) + (cents ? decimal + cents : ''));
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
currency.prototype = {
|
|
132
|
+
/**
|
|
133
|
+
* Adds values together.
|
|
134
|
+
* @param {number} number
|
|
135
|
+
* @returns {currency}
|
|
136
|
+
*/
|
|
137
|
+
add: function add(number) {
|
|
138
|
+
var intValue = this.intValue,
|
|
139
|
+
_settings = this.s,
|
|
140
|
+
_precision = this.p;
|
|
141
|
+
return currency((intValue += parse(number, _settings)) / (_settings.fromCents ? 1 : _precision), _settings);
|
|
142
|
+
},
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Subtracts value.
|
|
146
|
+
* @param {number} number
|
|
147
|
+
* @returns {currency}
|
|
148
|
+
*/
|
|
149
|
+
subtract: function subtract(number) {
|
|
150
|
+
var intValue = this.intValue,
|
|
151
|
+
_settings = this.s,
|
|
152
|
+
_precision = this.p;
|
|
153
|
+
return currency((intValue -= parse(number, _settings)) / (_settings.fromCents ? 1 : _precision), _settings);
|
|
154
|
+
},
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Multiplies values.
|
|
158
|
+
* @param {number} number
|
|
159
|
+
* @returns {currency}
|
|
160
|
+
*/
|
|
161
|
+
multiply: function multiply(number) {
|
|
162
|
+
var intValue = this.intValue,
|
|
163
|
+
_settings = this.s;
|
|
164
|
+
return currency((intValue *= number) / (_settings.fromCents ? 1 : pow(_settings.precision)), _settings);
|
|
165
|
+
},
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Divides value.
|
|
169
|
+
* @param {number} number
|
|
170
|
+
* @returns {currency}
|
|
171
|
+
*/
|
|
172
|
+
divide: function divide(number) {
|
|
173
|
+
var intValue = this.intValue,
|
|
174
|
+
_settings = this.s;
|
|
175
|
+
return currency(intValue /= parse(number, _settings, false), _settings);
|
|
176
|
+
},
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Takes the currency amount and distributes the values evenly. Any extra pennies
|
|
180
|
+
* left over from the distribution will be stacked onto the first set of entries.
|
|
181
|
+
* @param {number} count
|
|
182
|
+
* @returns {array}
|
|
183
|
+
*/
|
|
184
|
+
distribute: function distribute(count) {
|
|
185
|
+
var intValue = this.intValue,
|
|
186
|
+
_precision = this.p,
|
|
187
|
+
_settings = this.s,
|
|
188
|
+
distribution = [],
|
|
189
|
+
split = Math[intValue >= 0 ? 'floor' : 'ceil'](intValue / count),
|
|
190
|
+
pennies = Math.abs(intValue - split * count),
|
|
191
|
+
precision = _settings.fromCents ? 1 : _precision;
|
|
192
|
+
|
|
193
|
+
for (; count !== 0; count--) {
|
|
194
|
+
var item = currency(split / precision, _settings); // Add any left over pennies
|
|
195
|
+
|
|
196
|
+
pennies-- > 0 && (item = item[intValue >= 0 ? 'add' : 'subtract'](1 / precision));
|
|
197
|
+
distribution.push(item);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
return distribution;
|
|
201
|
+
},
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Returns the dollar value.
|
|
205
|
+
* @returns {number}
|
|
206
|
+
*/
|
|
207
|
+
dollars: function dollars() {
|
|
208
|
+
return ~~this.value;
|
|
209
|
+
},
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Returns the cent value.
|
|
213
|
+
* @returns {number}
|
|
214
|
+
*/
|
|
215
|
+
cents: function cents() {
|
|
216
|
+
var intValue = this.intValue,
|
|
217
|
+
_precision = this.p;
|
|
218
|
+
return ~~(intValue % _precision);
|
|
219
|
+
},
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Formats the value as a string according to the formatting settings.
|
|
223
|
+
* @param {boolean} useSymbol - format with currency symbol
|
|
224
|
+
* @returns {string}
|
|
225
|
+
*/
|
|
226
|
+
format: function format(options) {
|
|
227
|
+
var _settings = this.s;
|
|
228
|
+
|
|
229
|
+
if (typeof options === 'function') {
|
|
230
|
+
return options(this, _settings);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
return _settings.format(this, Object.assign({}, _settings, options));
|
|
234
|
+
},
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Formats the value as a string according to the formatting settings.
|
|
238
|
+
* @returns {string}
|
|
239
|
+
*/
|
|
240
|
+
toString: function toString() {
|
|
241
|
+
var intValue = this.intValue,
|
|
242
|
+
_precision = this.p,
|
|
243
|
+
_settings = this.s;
|
|
244
|
+
return rounding(intValue / _precision, _settings.increment).toFixed(_settings.precision);
|
|
245
|
+
},
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Value for JSON serialization.
|
|
249
|
+
* @returns {float}
|
|
250
|
+
*/
|
|
251
|
+
toJSON: function toJSON() {
|
|
252
|
+
return this.value;
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
export default currency;
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
import { ElMessage } from "element-plus";
|
|
3
|
+
import errorCode from "@/utils/errorCode";
|
|
4
|
+
import { tansParams } from "@/utils/top";
|
|
5
|
+
import { userStore } from "../store/index.js";
|
|
6
|
+
const store = userStore();
|
|
7
|
+
axios.defaults.headers["Content-Type"] = "application/json;charset=utf-8";
|
|
8
|
+
const env = import.meta.env;
|
|
9
|
+
|
|
10
|
+
const opts = {
|
|
11
|
+
baseURL: store.origin
|
|
12
|
+
? store.origin + "/" + env.VITE_BASE_API
|
|
13
|
+
: env.VITE_BASE_API,
|
|
14
|
+
timeout: 999999999,
|
|
15
|
+
errorTip: true,
|
|
16
|
+
};
|
|
17
|
+
// console.log(import.meta.env.VITE_NODE_ENV, 'import.meta.env.DEV')
|
|
18
|
+
// if(import.meta.env.VITE_NODE_ENV == 'uat') {
|
|
19
|
+
// opts.baseURL = 'http://59.53.91.231:2100/' + env.VITE_BASE_API
|
|
20
|
+
// }
|
|
21
|
+
console.log(opts.baseURL, "----------------", store.origin);
|
|
22
|
+
if (env.VITE_APP_TAG) {
|
|
23
|
+
let tag = sessionStorage.getItem("tag");
|
|
24
|
+
if (!tag) {
|
|
25
|
+
tag = env.VITE_APP_TAG;
|
|
26
|
+
sessionStorage.setItem("tag", tag);
|
|
27
|
+
}
|
|
28
|
+
opts.headers = {
|
|
29
|
+
"X-Tag": tag,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export const req = axios.create(opts);
|
|
34
|
+
|
|
35
|
+
req.interceptors.request.use(
|
|
36
|
+
(config) => {
|
|
37
|
+
const isToken = (config.headers || {}).isToken === false;
|
|
38
|
+
if (store.token && !isToken) {
|
|
39
|
+
config.headers["Authorization"] = "Bearer " + store.token; // 让每个请求携带自定义token 请根据实际情况自行修改
|
|
40
|
+
config.headers["advice"] = "1";
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (config.method === "get" && config.params) {
|
|
44
|
+
let url = config.url + "?" + tansParams(config.params);
|
|
45
|
+
url = url.slice(0, -1);
|
|
46
|
+
config.params = {};
|
|
47
|
+
config.url = url;
|
|
48
|
+
}
|
|
49
|
+
return config;
|
|
50
|
+
},
|
|
51
|
+
(error) => {
|
|
52
|
+
Promise.reject(error);
|
|
53
|
+
}
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
// 响应拦截器
|
|
57
|
+
req.interceptors.response.use(
|
|
58
|
+
(response) => {
|
|
59
|
+
if (Object.prototype.toString.call(response.data) === "[object Blob]") {
|
|
60
|
+
return response;
|
|
61
|
+
}
|
|
62
|
+
const { data, config } = response;
|
|
63
|
+
const { code, success, msg, status } = data;
|
|
64
|
+
const message =
|
|
65
|
+
response.data.msg ||
|
|
66
|
+
response.data.message ||
|
|
67
|
+
errorCode[code] ||
|
|
68
|
+
errorCode["default"];
|
|
69
|
+
// 增加失败判断
|
|
70
|
+
data.fail = code !== 200 && success !== true;
|
|
71
|
+
if (code === 401) {
|
|
72
|
+
ElMessage.error(msg);
|
|
73
|
+
return data;
|
|
74
|
+
} else if (status == 1) {
|
|
75
|
+
// 兼容地图Api接口返回值不报错
|
|
76
|
+
return data;
|
|
77
|
+
} else if (code !== 200 && code !== "0" && config.errorTip) {
|
|
78
|
+
ElMessage({
|
|
79
|
+
message,
|
|
80
|
+
dangerouslyUseHTMLString: true,
|
|
81
|
+
type: code == 499 ? "info" : "error",
|
|
82
|
+
});
|
|
83
|
+
return data;
|
|
84
|
+
}
|
|
85
|
+
return data;
|
|
86
|
+
},
|
|
87
|
+
(error) => {
|
|
88
|
+
let { message } = error;
|
|
89
|
+
if (message === "Network Error") {
|
|
90
|
+
message = "后端接口连接异常";
|
|
91
|
+
} else if (message.includes("timeout")) {
|
|
92
|
+
message = "系统接口请求超时";
|
|
93
|
+
} else if (message.includes("Request failed with status code")) {
|
|
94
|
+
message = "系统接口" + message.substr(message.length - 3) + "异常";
|
|
95
|
+
}
|
|
96
|
+
ElMessage({
|
|
97
|
+
message: message,
|
|
98
|
+
type: "error",
|
|
99
|
+
duration: 5 * 1000,
|
|
100
|
+
});
|
|
101
|
+
return Promise.reject(error);
|
|
102
|
+
}
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
// 通用下载方法
|
|
106
|
+
export function download(url, params, filename, methods = "post") {
|
|
107
|
+
const actions = methods === "post" ? req.post : req.get;
|
|
108
|
+
return actions(url, params, {
|
|
109
|
+
transformRequest: [
|
|
110
|
+
(params) => {
|
|
111
|
+
return tansParams(params);
|
|
112
|
+
},
|
|
113
|
+
],
|
|
114
|
+
headers: {
|
|
115
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
116
|
+
},
|
|
117
|
+
responseType: "blob",
|
|
118
|
+
})
|
|
119
|
+
.then((data) => {
|
|
120
|
+
const content = data.data;
|
|
121
|
+
const blob = new Blob([content]);
|
|
122
|
+
if ("download" in document.createElement("a")) {
|
|
123
|
+
const elink = document.createElement("a");
|
|
124
|
+
elink.download = filename;
|
|
125
|
+
elink.style.display = "none";
|
|
126
|
+
elink.href = URL.createObjectURL(blob);
|
|
127
|
+
document.body.appendChild(elink);
|
|
128
|
+
elink.click();
|
|
129
|
+
URL.revokeObjectURL(elink.href);
|
|
130
|
+
document.body.removeChild(elink);
|
|
131
|
+
} else {
|
|
132
|
+
navigator.msSaveBlob(blob, filename);
|
|
133
|
+
}
|
|
134
|
+
})
|
|
135
|
+
.catch((r) => {
|
|
136
|
+
console.error(r);
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export function downFile(url, parameter = {}) {
|
|
141
|
+
return axios({
|
|
142
|
+
// 链接带了参数(有问号)? 剩余参数用&拼接 : 参数用?拼接
|
|
143
|
+
url:
|
|
144
|
+
url.indexOf("http:") > -1 || url.indexOf("https:") > -1
|
|
145
|
+
? url
|
|
146
|
+
: env.VITE_BASE_API +
|
|
147
|
+
url +
|
|
148
|
+
(url.indexOf("?") > -1 ? "&" : "?") +
|
|
149
|
+
tansParams(parameter),
|
|
150
|
+
// params: parameter,
|
|
151
|
+
headers: {
|
|
152
|
+
Authorization: "Bearer " + store.token,
|
|
153
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
154
|
+
},
|
|
155
|
+
method: "get",
|
|
156
|
+
responseType: "blob",
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
export function downFilePost(url, parameter = {}, method) {
|
|
160
|
+
if (method == "get") url = url + "?" + tansParams(parameter);
|
|
161
|
+
|
|
162
|
+
return axios({
|
|
163
|
+
url: opts.baseURL + url,
|
|
164
|
+
data: parameter,
|
|
165
|
+
headers: {
|
|
166
|
+
Authorization: "Bearer " + store.token,
|
|
167
|
+
"Content-Type": "application/json",
|
|
168
|
+
},
|
|
169
|
+
method: method || "post",
|
|
170
|
+
responseType: "blob",
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
//下载文件
|
|
174
|
+
|
|
175
|
+
export function downloadFile(
|
|
176
|
+
url,
|
|
177
|
+
fileName = "XXX.xlsx",
|
|
178
|
+
parameter,
|
|
179
|
+
method,
|
|
180
|
+
callback
|
|
181
|
+
) {
|
|
182
|
+
return downFilePost(url, parameter, method)
|
|
183
|
+
.then((data) => {
|
|
184
|
+
if (!data) {
|
|
185
|
+
ElMessage.warning("文件下载失败");
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
if (typeof window.navigator.msSaveBlob !== "undefined") {
|
|
189
|
+
window.navigator.msSaveBlob(new Blob([data.data]), fileName);
|
|
190
|
+
} else {
|
|
191
|
+
let url = window.URL.createObjectURL(new Blob([data.data]));
|
|
192
|
+
let link = document.createElement("a");
|
|
193
|
+
link.style.display = "none";
|
|
194
|
+
link.href = url;
|
|
195
|
+
link.setAttribute("download", fileName);
|
|
196
|
+
document.body.appendChild(link);
|
|
197
|
+
link.click();
|
|
198
|
+
document.body.removeChild(link); //下载完成移除元素
|
|
199
|
+
window.URL.revokeObjectURL(url); //释放掉blob对象
|
|
200
|
+
}
|
|
201
|
+
})
|
|
202
|
+
.finally(() => callback && callback());
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
//下载修改文件名
|
|
206
|
+
export function downFileChangeName(url, name) {
|
|
207
|
+
const x = new XMLHttpRequest();
|
|
208
|
+
x.open("GET", url, true);
|
|
209
|
+
x.responseType = "blob";
|
|
210
|
+
x.onload = function () {
|
|
211
|
+
const url = window.URL.createObjectURL(x.response);
|
|
212
|
+
const a = document.createElement("a");
|
|
213
|
+
a.href = url;
|
|
214
|
+
a.download = name;
|
|
215
|
+
a.click();
|
|
216
|
+
};
|
|
217
|
+
x.send();
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
export default req;
|
package/src/utils/top.js
ADDED
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 通用js方法封装处理
|
|
3
|
+
* Copyright (c) 2019 top
|
|
4
|
+
*/
|
|
5
|
+
const env = import.meta.env
|
|
6
|
+
const baseURL = env.VITE_BASE_API
|
|
7
|
+
|
|
8
|
+
// 日期格式化
|
|
9
|
+
export function parseTime(time, pattern) {
|
|
10
|
+
if (arguments.length === 0 || !time) {
|
|
11
|
+
return null
|
|
12
|
+
}
|
|
13
|
+
const format = pattern || '{y}-{m}-{d} {h}:{i}:{s}'
|
|
14
|
+
let date
|
|
15
|
+
if (typeof time === 'object') {
|
|
16
|
+
date = time
|
|
17
|
+
} else {
|
|
18
|
+
if ((typeof time === 'string') && (/^[0-9]+$/.test(time))) {
|
|
19
|
+
time = parseInt(time)
|
|
20
|
+
} else if (typeof time === 'string') {
|
|
21
|
+
time = time.replace(new RegExp(/-/gm), '/');
|
|
22
|
+
}
|
|
23
|
+
if ((typeof time === 'number') && (time.toString().length === 10)) {
|
|
24
|
+
time = time * 1000
|
|
25
|
+
}
|
|
26
|
+
date = new Date(time)
|
|
27
|
+
}
|
|
28
|
+
const formatObj = {
|
|
29
|
+
y: date.getFullYear(),
|
|
30
|
+
m: date.getMonth() + 1,
|
|
31
|
+
d: date.getDate(),
|
|
32
|
+
h: date.getHours(),
|
|
33
|
+
i: date.getMinutes(),
|
|
34
|
+
s: date.getSeconds(),
|
|
35
|
+
a: date.getDay()
|
|
36
|
+
}
|
|
37
|
+
const time_str = format.replace(/{(y|m|d|h|i|s|a)+}/g, (result, key) => {
|
|
38
|
+
let value = formatObj[key]
|
|
39
|
+
// Note: getDay() returns 0 on Sunday
|
|
40
|
+
if (key === 'a') { return ['日', '一', '二', '三', '四', '五', '六'][value] }
|
|
41
|
+
if (result.length > 0 && value < 10) {
|
|
42
|
+
value = '0' + value
|
|
43
|
+
}
|
|
44
|
+
return value || 0
|
|
45
|
+
})
|
|
46
|
+
return time_str
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// 表单重置
|
|
50
|
+
export function resetForm(refName) {
|
|
51
|
+
if (this.$refs[refName]) {
|
|
52
|
+
this.$refs[refName].resetFields();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// 添加日期范围
|
|
57
|
+
export function addDateRange(params, dateRange, propName) {
|
|
58
|
+
var search = params;
|
|
59
|
+
search.params = {};
|
|
60
|
+
if (null != dateRange && '' != dateRange) {
|
|
61
|
+
if (typeof (propName) === "undefined") {
|
|
62
|
+
search.params["beginTime"] = dateRange[0];
|
|
63
|
+
search.params["endTime"] = dateRange[1];
|
|
64
|
+
} else {
|
|
65
|
+
search.params["begin" + propName] = dateRange[0];
|
|
66
|
+
search.params["end" + propName] = dateRange[1];
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return search;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// 回显数据字典
|
|
73
|
+
export function selectDictLabel(datas, value) {
|
|
74
|
+
var actions = [];
|
|
75
|
+
Object.keys(datas).some((key) => {
|
|
76
|
+
if (datas[key].dictValue == ('' + value)) {
|
|
77
|
+
actions.push(datas[key].dictLabel);
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
})
|
|
81
|
+
return actions.join('');
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// 回显数据字典(字符串数组)
|
|
85
|
+
export function selectDictLabels(datas, value, separator) {
|
|
86
|
+
var actions = [];
|
|
87
|
+
var currentSeparator = undefined === separator ? "," : separator;
|
|
88
|
+
var temp = value.split(currentSeparator);
|
|
89
|
+
Object.keys(value.split(currentSeparator)).some((val) => {
|
|
90
|
+
Object.keys(datas).some((key) => {
|
|
91
|
+
if (datas[key].dictValue == ('' + temp[val])) {
|
|
92
|
+
actions.push(datas[key].dictLabel + currentSeparator);
|
|
93
|
+
}
|
|
94
|
+
})
|
|
95
|
+
})
|
|
96
|
+
return actions.join('').substring(0, actions.join('').length - 1);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// 通用下载方法
|
|
100
|
+
export function download(fileName) {
|
|
101
|
+
window.location.href = baseURL + "/common/download?fileName=" + encodeURI(fileName) + "&delete=" + true;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// 字符串格式化(%s )
|
|
105
|
+
export function sprintf(str) {
|
|
106
|
+
var args = arguments, flag = true, i = 1;
|
|
107
|
+
str = str.replace(/%s/g, function () {
|
|
108
|
+
var arg = args[i++];
|
|
109
|
+
if (typeof arg === 'undefined') {
|
|
110
|
+
flag = false;
|
|
111
|
+
return '';
|
|
112
|
+
}
|
|
113
|
+
return arg;
|
|
114
|
+
});
|
|
115
|
+
return flag ? str : '';
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// 转换字符串,undefined,null等转化为""
|
|
119
|
+
export function praseStrEmpty(str) {
|
|
120
|
+
if (!str || str == "undefined" || str == "null") {
|
|
121
|
+
return "";
|
|
122
|
+
}
|
|
123
|
+
return str;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* 构造树型结构数据
|
|
128
|
+
* @param {*} data 数据源
|
|
129
|
+
* @param {*} id id字段 默认 'id'
|
|
130
|
+
* @param {*} parentId 父节点字段 默认 'parentId'
|
|
131
|
+
* @param {*} children 孩子节点字段 默认 'children'
|
|
132
|
+
*/
|
|
133
|
+
export function handleTree(data, id, parentId, children) {
|
|
134
|
+
let config = {
|
|
135
|
+
id: id || 'id',
|
|
136
|
+
parentId: parentId || 'parentId',
|
|
137
|
+
childrenList: children || 'children'
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
var childrenListMap = {};
|
|
141
|
+
var nodeIds = {};
|
|
142
|
+
var tree = [];
|
|
143
|
+
|
|
144
|
+
for (let d of data) {
|
|
145
|
+
let parentId = d[config.parentId];
|
|
146
|
+
if (childrenListMap[parentId] == null) {
|
|
147
|
+
childrenListMap[parentId] = [];
|
|
148
|
+
}
|
|
149
|
+
nodeIds[d[config.id]] = d;
|
|
150
|
+
childrenListMap[parentId].push(d);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
for (let d of data) {
|
|
154
|
+
let parentId = d[config.parentId];
|
|
155
|
+
if (nodeIds[parentId] == null) {
|
|
156
|
+
tree.push(d);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
for (let t of tree) {
|
|
161
|
+
adaptToChildrenList(t);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function adaptToChildrenList(o) {
|
|
165
|
+
if (childrenListMap[o[config.id]] !== null) {
|
|
166
|
+
o[config.childrenList] = childrenListMap[o[config.id]];
|
|
167
|
+
}
|
|
168
|
+
if (o[config.childrenList]) {
|
|
169
|
+
for (let c of o[config.childrenList]) {
|
|
170
|
+
adaptToChildrenList(c);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return tree;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* 参数处理
|
|
179
|
+
* @param {*} params 参数
|
|
180
|
+
*/
|
|
181
|
+
export function tansParams(params) {
|
|
182
|
+
let result = ''
|
|
183
|
+
for (const propName of Object.keys(params)) {
|
|
184
|
+
const value = params[propName];
|
|
185
|
+
var part = encodeURIComponent(propName) + "=";
|
|
186
|
+
if (value !== null && typeof (value) !== "undefined") {
|
|
187
|
+
if (typeof value === 'object') {
|
|
188
|
+
for (const key of Object.keys(value)) {
|
|
189
|
+
if (value[key] !== null && typeof (value[key]) !== 'undefined') {
|
|
190
|
+
let params = propName + '[' + key + ']';
|
|
191
|
+
var subPart = encodeURIComponent(params) + "=";
|
|
192
|
+
result += subPart + encodeURIComponent(value[key]) + "&";
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
} else {
|
|
196
|
+
result += part + encodeURIComponent(value) + "&";
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
return result
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
export function digitUppercase(n) {
|
|
205
|
+
let fraction = ['角', '分'];
|
|
206
|
+
let digit = [
|
|
207
|
+
'零', '壹', '贰', '叁', '肆',
|
|
208
|
+
'伍', '陆', '柒', '捌', '玖'
|
|
209
|
+
];
|
|
210
|
+
let unit = [
|
|
211
|
+
['元', '万', '亿'],
|
|
212
|
+
['', '拾', '佰', '仟']
|
|
213
|
+
];
|
|
214
|
+
let head = n < 0 ? '欠' : '';
|
|
215
|
+
n = Math.abs(n);
|
|
216
|
+
let s = '';
|
|
217
|
+
for (let i = 0; i < fraction.length; i++) {
|
|
218
|
+
s += (digit[Math.floor(n * 10 * Math.pow(10, i)) % 10] + fraction[i]).replace(/零./, '');
|
|
219
|
+
}
|
|
220
|
+
s = s || '整';
|
|
221
|
+
n = Math.floor(n);
|
|
222
|
+
for (let i = 0; i < unit[0].length && n > 0; i++) {
|
|
223
|
+
var p = '';
|
|
224
|
+
for (let j = 0; j < unit[1].length && n > 0; j++) {
|
|
225
|
+
p = digit[n % 10] + unit[1][j] + p;
|
|
226
|
+
n = Math.floor(n / 10);
|
|
227
|
+
}
|
|
228
|
+
s = p.replace(/(零.)*零$/, '').replace(/^$/, '零') + unit[0][i] + s;
|
|
229
|
+
}
|
|
230
|
+
return head + s.replace(/(零.)*零元/, '元')
|
|
231
|
+
.replace(/(零.)+/g, '零')
|
|
232
|
+
.replace(/^整$/, '零元整');
|
|
233
|
+
}
|