mtxt-ui3 0.0.2
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/README.md +23 -0
- package/dist/components/index.cjs +9809 -0
- package/dist/components/index.d.ts +677 -0
- package/dist/components/index.js +9784 -0
- package/dist/components/style.css +1 -0
- package/dist/directives/index.cjs +89 -0
- package/dist/directives/index.d.ts +15 -0
- package/dist/directives/index.js +84 -0
- package/dist/hooks/index.cjs +6216 -0
- package/dist/hooks/index.d.ts +127 -0
- package/dist/hooks/index.js +6199 -0
- package/dist/index.cjs +10297 -0
- package/dist/index.d.ts +1084 -0
- package/dist/index.js +10280 -0
- package/dist/style.css +2 -0
- package/dist/utils/index.cjs +515 -0
- package/dist/utils/index.d.ts +162 -0
- package/dist/utils/index.js +493 -0
- package/dist/video/index.cjs +6305 -0
- package/dist/video/index.d.ts +79 -0
- package/dist/video/index.js +6296 -0
- package/dist/video/style.css +1 -0
- package/package.json +75 -0
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @param opt
|
|
6
|
+
* @param opt.fontSize 基础字体大小
|
|
7
|
+
* @param opt.designSize 设计稿基数
|
|
8
|
+
*/
|
|
9
|
+
declare const setRem: (opt: {
|
|
10
|
+
fontSize?: number;
|
|
11
|
+
designSize?: number;
|
|
12
|
+
}) => void;
|
|
13
|
+
|
|
14
|
+
interface IApiInstanceConfig extends AxiosRequestConfig {
|
|
15
|
+
onTokenExpired?: (res: AxiosResponse) => void;
|
|
16
|
+
}
|
|
17
|
+
declare class ApiInstance {
|
|
18
|
+
instance: AxiosInstance;
|
|
19
|
+
config: IApiInstanceConfig;
|
|
20
|
+
constructor(config?: IApiInstanceConfig);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* base64加密字符串
|
|
25
|
+
* @param str 要加密的字符串
|
|
26
|
+
* @returns 加密后的字符串
|
|
27
|
+
*/
|
|
28
|
+
declare function encodeStr(str: string): string;
|
|
29
|
+
/**
|
|
30
|
+
* 解密base64
|
|
31
|
+
* @param str 要解密的字符串
|
|
32
|
+
* @returns 解密后的字符串
|
|
33
|
+
*/
|
|
34
|
+
declare function decodeStr(str: string): string;
|
|
35
|
+
declare const _default$2: {
|
|
36
|
+
encodeStr: typeof encodeStr;
|
|
37
|
+
decodeStr: typeof decodeStr;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
declare class Login {
|
|
41
|
+
constructor();
|
|
42
|
+
protected checkSystemInfo(): void;
|
|
43
|
+
systemServerInfo: string;
|
|
44
|
+
protected config: {
|
|
45
|
+
axios: AxiosInstance;
|
|
46
|
+
queryInfo: Record<string, string>;
|
|
47
|
+
api: string;
|
|
48
|
+
env: string;
|
|
49
|
+
};
|
|
50
|
+
saveInfo(key: string, val: string): void;
|
|
51
|
+
protected getQueryInfo(): {} | null;
|
|
52
|
+
refreshToken(): Promise<void>;
|
|
53
|
+
getTokenByCode(e?: {
|
|
54
|
+
username: string;
|
|
55
|
+
password: string;
|
|
56
|
+
} | string): Promise<any>;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* 随机数字
|
|
61
|
+
* @param min 开始
|
|
62
|
+
* @param max 结束
|
|
63
|
+
*/
|
|
64
|
+
declare function randomNumber(min: any, max: any): any;
|
|
65
|
+
/**
|
|
66
|
+
* 返回随机字符串
|
|
67
|
+
* @param length 长度
|
|
68
|
+
*/
|
|
69
|
+
declare function randomString(length: number): string;
|
|
70
|
+
declare const _default$1: {
|
|
71
|
+
randomNumber: typeof randomNumber;
|
|
72
|
+
randomString: typeof randomString;
|
|
73
|
+
UUID: (n?: number | undefined) => string;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
declare const upload: (options: any, callback: any) => Promise<any>;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* fetchApi
|
|
80
|
+
* @param url 请求地址
|
|
81
|
+
* @param method 请求方法
|
|
82
|
+
* @param parameter 请求参数
|
|
83
|
+
* @param dataType 返回数据类型 默认json
|
|
84
|
+
* @returns
|
|
85
|
+
*/
|
|
86
|
+
declare function fetchApi(url: string, method: "GET" | "POST", parameter: any, dataType?: "json" | "blob", headers?: {}): Promise<unknown>;
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* 手机号正则
|
|
90
|
+
*/
|
|
91
|
+
declare const phoneNumber: RegExp;
|
|
92
|
+
/**
|
|
93
|
+
* 全屏
|
|
94
|
+
*/
|
|
95
|
+
declare const screen: {
|
|
96
|
+
exitFullscreen(id: string): void;
|
|
97
|
+
requestFullscreen(id: string): void;
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* 数字转千分符
|
|
101
|
+
* @param number 数字
|
|
102
|
+
* @param decimals 小数位数
|
|
103
|
+
* @param decPoint 小数点
|
|
104
|
+
* @param thousandsSep 千分符
|
|
105
|
+
* @returns
|
|
106
|
+
*/
|
|
107
|
+
declare const formatMoney: (number: any, decimals?: number, decPoint?: string, thousandsSep?: string) => any;
|
|
108
|
+
declare const toChinese: (val: any) => string | undefined;
|
|
109
|
+
/**
|
|
110
|
+
* 保留小数(string转number)
|
|
111
|
+
* @param num 数字
|
|
112
|
+
* @param digit 位数
|
|
113
|
+
* @returns
|
|
114
|
+
*/
|
|
115
|
+
declare const limitDecimal: (num: any, digit?: number) => number;
|
|
116
|
+
/**
|
|
117
|
+
* 强制保留小数不足补0
|
|
118
|
+
* @param num 数字
|
|
119
|
+
* @param digit 位数
|
|
120
|
+
* @returns
|
|
121
|
+
*/
|
|
122
|
+
declare const forcedDecimals: (num: any, digit?: number) => any;
|
|
123
|
+
/**
|
|
124
|
+
*
|
|
125
|
+
* @param time 时间戳
|
|
126
|
+
* @param type day/hour/minute/second 默认为day
|
|
127
|
+
* @param unit 1:传入参数为秒 1000:传入参数为毫秒 默认为1
|
|
128
|
+
* @returns
|
|
129
|
+
*/
|
|
130
|
+
declare const formatDuring: (time?: number, type?: string, unit?: number, isComplement?: boolean) => {
|
|
131
|
+
days: number;
|
|
132
|
+
hours: string | number;
|
|
133
|
+
minutes: string | number;
|
|
134
|
+
seconds: string | number;
|
|
135
|
+
} | {
|
|
136
|
+
hours: string | number;
|
|
137
|
+
minutes: string | number;
|
|
138
|
+
seconds: string | number;
|
|
139
|
+
days?: undefined;
|
|
140
|
+
} | {
|
|
141
|
+
minutes: string | number;
|
|
142
|
+
seconds: string | number;
|
|
143
|
+
days?: undefined;
|
|
144
|
+
hours?: undefined;
|
|
145
|
+
} | {
|
|
146
|
+
seconds: string | number;
|
|
147
|
+
days?: undefined;
|
|
148
|
+
hours?: undefined;
|
|
149
|
+
minutes?: undefined;
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* 下载服务器返回的文件
|
|
154
|
+
* @param data 服务器返回数据
|
|
155
|
+
* @param fileName 下载的文件名
|
|
156
|
+
*/
|
|
157
|
+
declare function downloadFile(data: Blob, fileName: string): void;
|
|
158
|
+
declare const _default: {
|
|
159
|
+
downloadFile: typeof downloadFile;
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
export { ApiInstance, Login, _default$2 as base64, fetchApi, _default as file, forcedDecimals, formatDuring, formatMoney, limitDecimal, phoneNumber, _default$1 as random, screen, setRem, toChinese, upload };
|
|
@@ -0,0 +1,493 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import { message } from 'ant-design-vue';
|
|
3
|
+
import { isPlainObject, omit } from 'lodash';
|
|
4
|
+
import { ref, reactive, computed } from 'vue';
|
|
5
|
+
|
|
6
|
+
const setRem = opt => {
|
|
7
|
+
const fontSize = opt.fontSize || 14;
|
|
8
|
+
const designSize = opt.designSize || 1920;
|
|
9
|
+
const scale = document.documentElement.clientWidth / designSize;
|
|
10
|
+
document.documentElement.style.fontSize = `${fontSize * Math.min(scale, 2)}px`;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const config = {
|
|
14
|
+
prefix: "mtxt",
|
|
15
|
+
// 调接口时 需要去掉data中的一些属性
|
|
16
|
+
requestOmitParams: ["createDt", "createUser", "updateDt", "updateUser"]
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const getToken = () => sessionStorage.getItem("token");
|
|
20
|
+
const getUserId = () => sessionStorage.getItem("userId");
|
|
21
|
+
const getCorpId = () => sessionStorage.getItem("corpId") || getUserinfo()?.corpId;
|
|
22
|
+
const getUserinfo = () => {
|
|
23
|
+
const jsonString = sessionStorage.getItem("userinfo");
|
|
24
|
+
if (jsonString) {
|
|
25
|
+
return JSON.parse(jsonString);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
const getCommonHeaders = () => {
|
|
29
|
+
const userInfo = getUserinfo();
|
|
30
|
+
const userId = getUserId();
|
|
31
|
+
const token = getToken();
|
|
32
|
+
const corpId = getCorpId();
|
|
33
|
+
const Authorization = `Bearer ${token}`;
|
|
34
|
+
return {
|
|
35
|
+
userName: userInfo?.userName,
|
|
36
|
+
userId: userInfo?.userId || userId,
|
|
37
|
+
employeeName: encodeURIComponent(userInfo?.employeeName ?? ""),
|
|
38
|
+
employeeId: userInfo?.employeeId,
|
|
39
|
+
token,
|
|
40
|
+
corpId,
|
|
41
|
+
Authorization,
|
|
42
|
+
"Content-Type": "application/json;charset=utf-8"
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
const defaultConfig = {
|
|
46
|
+
timeout: 1e3 * 10,
|
|
47
|
+
baseURL: "/api/"
|
|
48
|
+
};
|
|
49
|
+
class ApiInstance {
|
|
50
|
+
instance;
|
|
51
|
+
config;
|
|
52
|
+
constructor(config$1 = {}) {
|
|
53
|
+
this.config = config$1;
|
|
54
|
+
this.instance = axios.create({
|
|
55
|
+
...defaultConfig,
|
|
56
|
+
...config$1
|
|
57
|
+
});
|
|
58
|
+
this.instance.interceptors.request.use(config2 => {
|
|
59
|
+
getUserinfo();
|
|
60
|
+
getToken();
|
|
61
|
+
getCorpId();
|
|
62
|
+
if (isPlainObject(config2.data)) {
|
|
63
|
+
for (const key in config2.data) {
|
|
64
|
+
if (config2.data[key] === void 0) {
|
|
65
|
+
config2.data[key] = null;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (!config2.headers.keepProperty) {
|
|
69
|
+
config2.data = omit(config2.data, ...config.requestOmitParams);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (!config2.headers) config2.headers = {};
|
|
73
|
+
const commonHeaders = getCommonHeaders();
|
|
74
|
+
for (const key in commonHeaders) {
|
|
75
|
+
if (key !== "Content-Type") {
|
|
76
|
+
config2.headers[key] = commonHeaders[key];
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return config2;
|
|
80
|
+
}, err => {
|
|
81
|
+
return Promise.reject(err);
|
|
82
|
+
});
|
|
83
|
+
this.instance.interceptors.response.use(res => {
|
|
84
|
+
return new Promise((resolve, reject) => {
|
|
85
|
+
if (res.config.responseType === "blob") {
|
|
86
|
+
resolve(res.data);
|
|
87
|
+
} else if (res.data.code === "M0000") {
|
|
88
|
+
resolve(res.data);
|
|
89
|
+
} else if (res.data.code === "M4003") {
|
|
90
|
+
this.config.onTokenExpired?.(res);
|
|
91
|
+
reject(res);
|
|
92
|
+
} else {
|
|
93
|
+
const alertMessage = res.data.message ?? "\u7F51\u7EDC\u5F02\u5E38\uFF0C\u8BF7\u8054\u7CFB\u7BA1\u7406\u5458";
|
|
94
|
+
if (!res.config.headers?.noAlert) {
|
|
95
|
+
message.error(alertMessage, alertMessage.length > 10 ? 5 : 3);
|
|
96
|
+
}
|
|
97
|
+
reject(res.data);
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
}, err => {
|
|
101
|
+
return Promise.reject(err);
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function encodeStr(str) {
|
|
107
|
+
return window.btoa(str);
|
|
108
|
+
}
|
|
109
|
+
function decodeStr(str) {
|
|
110
|
+
return window.atob(str);
|
|
111
|
+
}
|
|
112
|
+
var base64 = {
|
|
113
|
+
encodeStr,
|
|
114
|
+
decodeStr
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
class Login {
|
|
118
|
+
constructor() {
|
|
119
|
+
this.getQueryInfo();
|
|
120
|
+
this.config.axios = new ApiInstance({
|
|
121
|
+
baseURL: "/api/common/v1/"
|
|
122
|
+
}).instance;
|
|
123
|
+
}
|
|
124
|
+
checkSystemInfo() {
|
|
125
|
+
const {
|
|
126
|
+
userCode,
|
|
127
|
+
token
|
|
128
|
+
} = this.config.queryInfo;
|
|
129
|
+
if (userCode) {
|
|
130
|
+
this.config.env = "zx-env";
|
|
131
|
+
}
|
|
132
|
+
if (token) {
|
|
133
|
+
this.config.env = "mtip-app-env";
|
|
134
|
+
}
|
|
135
|
+
this.systemServerInfo = this.config.env;
|
|
136
|
+
}
|
|
137
|
+
systemServerInfo = "";
|
|
138
|
+
config = {
|
|
139
|
+
axios: {},
|
|
140
|
+
queryInfo: {},
|
|
141
|
+
api: "auth/login",
|
|
142
|
+
env: "mtip-env"
|
|
143
|
+
};
|
|
144
|
+
saveInfo(key, val) {
|
|
145
|
+
window.localStorage.setItem(key, val);
|
|
146
|
+
window.sessionStorage.setItem(key, val);
|
|
147
|
+
}
|
|
148
|
+
getQueryInfo() {
|
|
149
|
+
const url = window.location.hash;
|
|
150
|
+
if (url.indexOf("?") != -1) {
|
|
151
|
+
let obj = {};
|
|
152
|
+
let arr = url.slice(url.indexOf("?") + 1).split("&");
|
|
153
|
+
arr.forEach(item => {
|
|
154
|
+
let param = item.split("=");
|
|
155
|
+
obj[param[0]] = param[1];
|
|
156
|
+
});
|
|
157
|
+
this.config.queryInfo = obj;
|
|
158
|
+
return obj;
|
|
159
|
+
} else {
|
|
160
|
+
return null;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
async refreshToken() {
|
|
164
|
+
const res = await this.config.axios.post(`auth/refreshToken`);
|
|
165
|
+
const {
|
|
166
|
+
sysUser,
|
|
167
|
+
token
|
|
168
|
+
} = res.data;
|
|
169
|
+
this.saveInfo("token", token);
|
|
170
|
+
this.saveInfo("userinfo", JSON.stringify(sysUser));
|
|
171
|
+
}
|
|
172
|
+
async getTokenByCode(e = "mtip-factory") {
|
|
173
|
+
const {
|
|
174
|
+
userCode,
|
|
175
|
+
token,
|
|
176
|
+
userId
|
|
177
|
+
} = this.config.queryInfo;
|
|
178
|
+
if (token) {
|
|
179
|
+
this.saveInfo("token", token);
|
|
180
|
+
this.saveInfo("userId", userId);
|
|
181
|
+
}
|
|
182
|
+
const data = {};
|
|
183
|
+
const headers = {
|
|
184
|
+
appType: ""
|
|
185
|
+
};
|
|
186
|
+
if (userCode) {
|
|
187
|
+
data.userCode = userCode;
|
|
188
|
+
}
|
|
189
|
+
if (typeof e === "object" && e.username && e.password) {
|
|
190
|
+
data.passWord = encodeStr(e.password.replace(/^\s+|\s+$/g, ""));
|
|
191
|
+
data.userName = e.username;
|
|
192
|
+
} else if (typeof e === "string") {
|
|
193
|
+
headers.appType = e;
|
|
194
|
+
}
|
|
195
|
+
const res = await this.config.axios.post(this.config.api, data, {
|
|
196
|
+
headers
|
|
197
|
+
});
|
|
198
|
+
this.saveInfo("token", res.data.token);
|
|
199
|
+
this.saveInfo("userinfo", JSON.stringify(res.data.sysUser));
|
|
200
|
+
return Promise.resolve(res);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function randomNumber(min, max) {
|
|
205
|
+
return Math.floor(Math.random() * (max - min)) + min;
|
|
206
|
+
}
|
|
207
|
+
function randomString(length) {
|
|
208
|
+
const letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
209
|
+
let res = "";
|
|
210
|
+
for (let i = 0; i < length; i++) {
|
|
211
|
+
res += letters.charAt(randomNumber(0, letters.length));
|
|
212
|
+
}
|
|
213
|
+
return res;
|
|
214
|
+
}
|
|
215
|
+
const UUID = (n = 16) => {
|
|
216
|
+
return "xxxx-xx-4x-yx-xx".replace(/[xy]/g, c => {
|
|
217
|
+
const r = Math.random() * 16 | 0,
|
|
218
|
+
v = c == "x" ? r : r & 3 | 8;
|
|
219
|
+
return v.toString(n);
|
|
220
|
+
});
|
|
221
|
+
};
|
|
222
|
+
var ramdom = {
|
|
223
|
+
randomNumber,
|
|
224
|
+
randomString,
|
|
225
|
+
UUID
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
const headers = {
|
|
229
|
+
"Content-Type": "multipart/form-data"
|
|
230
|
+
};
|
|
231
|
+
const upload = async (options, callback) => {
|
|
232
|
+
const {
|
|
233
|
+
file,
|
|
234
|
+
onSuccess,
|
|
235
|
+
onError
|
|
236
|
+
} = options;
|
|
237
|
+
const fileData = new FormData();
|
|
238
|
+
fileData.append("file", file);
|
|
239
|
+
message.info("\u6B63\u5728\u4E0A\u4F20\uFF0C\u8BF7\u7A0D\u540E");
|
|
240
|
+
const res = await callback(fileData, headers);
|
|
241
|
+
if (res.code === "M0000") {
|
|
242
|
+
message.success("\u4E0A\u4F20\u6210\u529F");
|
|
243
|
+
onSuccess("response", file);
|
|
244
|
+
return res;
|
|
245
|
+
} else {
|
|
246
|
+
message.error("\u4E0A\u4F20\u5931\u8D25");
|
|
247
|
+
onError("error", file);
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
async function fetchApi(url, method, parameter, dataType = "json", headers = {}) {
|
|
252
|
+
const newUrl = ref(url);
|
|
253
|
+
const options = reactive({});
|
|
254
|
+
const isWithOrigin = computed(() => newUrl.value.startsWith("http"));
|
|
255
|
+
const fullUrl = computed(() => {
|
|
256
|
+
const res = isWithOrigin.value ? newUrl.value : `${location.origin}${newUrl.value.startsWith("/") ? "" : "/"}${newUrl.value}`;
|
|
257
|
+
return res;
|
|
258
|
+
});
|
|
259
|
+
const modifyParam = ({
|
|
260
|
+
key,
|
|
261
|
+
value
|
|
262
|
+
}, isRemove = false) => {
|
|
263
|
+
try {
|
|
264
|
+
const url2 = new URL(fullUrl.value);
|
|
265
|
+
if (url2.hash) {
|
|
266
|
+
const converceUrl = new URL(url2.hash.replace("#", location.origin));
|
|
267
|
+
if (isRemove) {
|
|
268
|
+
converceUrl.searchParams.delete(key);
|
|
269
|
+
} else {
|
|
270
|
+
converceUrl.searchParams.set(key, value);
|
|
271
|
+
}
|
|
272
|
+
url2.hash = converceUrl.href.replace(location.origin, "#");
|
|
273
|
+
} else {
|
|
274
|
+
if (isRemove) {
|
|
275
|
+
url2.searchParams.delete(key);
|
|
276
|
+
} else {
|
|
277
|
+
url2.searchParams.set(key, value);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
newUrl.value = isWithOrigin.value ? url2.href : url2.href.replace(location.origin, "");
|
|
281
|
+
} catch (e) {}
|
|
282
|
+
};
|
|
283
|
+
if (method === "GET") {
|
|
284
|
+
if (parameter) {
|
|
285
|
+
for (const key in parameter) {
|
|
286
|
+
modifyParam({
|
|
287
|
+
key,
|
|
288
|
+
value: parameter[key]
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
options["method"] = method;
|
|
293
|
+
options["headers"] = {
|
|
294
|
+
...getCommonHeaders(),
|
|
295
|
+
...headers
|
|
296
|
+
};
|
|
297
|
+
} else {
|
|
298
|
+
options["method"] = method;
|
|
299
|
+
options["headers"] = {
|
|
300
|
+
...getCommonHeaders(),
|
|
301
|
+
...headers
|
|
302
|
+
};
|
|
303
|
+
options["body"] = JSON.stringify(parameter);
|
|
304
|
+
}
|
|
305
|
+
const response = await fetch(newUrl.value, options);
|
|
306
|
+
return new Promise((resolve, reject) => {
|
|
307
|
+
if (response.status === 200) {
|
|
308
|
+
if (dataType === "blob") {
|
|
309
|
+
return resolve(response.blob());
|
|
310
|
+
} else {
|
|
311
|
+
const res = response.json();
|
|
312
|
+
return resolve(res);
|
|
313
|
+
}
|
|
314
|
+
} else {
|
|
315
|
+
reject(response);
|
|
316
|
+
}
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
const phoneNumber = /^[1][3,4,5,7,8][0-9]{9}$/;
|
|
321
|
+
const screen = {
|
|
322
|
+
// 退出全屏
|
|
323
|
+
exitFullscreen(id) {
|
|
324
|
+
const dom = document.getElementById(id);
|
|
325
|
+
dom.addEventListener("click", event => {
|
|
326
|
+
if (document.fullscreenElement === dom) {
|
|
327
|
+
document.exitFullscreen();
|
|
328
|
+
}
|
|
329
|
+
event.preventDefault();
|
|
330
|
+
});
|
|
331
|
+
},
|
|
332
|
+
// 进入全屏
|
|
333
|
+
requestFullscreen(id) {
|
|
334
|
+
const dom = document.getElementById(id);
|
|
335
|
+
dom.requestFullscreen();
|
|
336
|
+
}
|
|
337
|
+
};
|
|
338
|
+
const formatMoney = (number, decimals = 0, decPoint = ".", thousandsSep = ",") => {
|
|
339
|
+
number = (number + "").replace(/[^0-9+-Ee.]/g, "");
|
|
340
|
+
let n = !isFinite(+number) ? 0 : +number;
|
|
341
|
+
let prec = !isFinite(+decimals) ? 0 : Math.abs(decimals);
|
|
342
|
+
let sep = typeof thousandsSep === "undefined" ? "," : thousandsSep;
|
|
343
|
+
let dec = typeof decPoint === "undefined" ? "." : decPoint;
|
|
344
|
+
let s;
|
|
345
|
+
let toFixedFix = function (n2, prec2) {
|
|
346
|
+
let k = Math.pow(10, prec2);
|
|
347
|
+
return "" + Math.ceil(n2 * k) / k;
|
|
348
|
+
};
|
|
349
|
+
s = (prec ? toFixedFix(n, prec) : "" + Math.round(n)).split(".");
|
|
350
|
+
let re = /(-?\d+)(\d{3})/;
|
|
351
|
+
while (re.test(s[0])) {
|
|
352
|
+
s[0] = s[0].replace(re, "$1" + sep + "$2");
|
|
353
|
+
}
|
|
354
|
+
if ((s[1] || "").length < prec) {
|
|
355
|
+
s[1] = s[1] || "";
|
|
356
|
+
s[1] += new Array(prec - s[1].length + 1).join("0");
|
|
357
|
+
}
|
|
358
|
+
return s.join(dec);
|
|
359
|
+
};
|
|
360
|
+
const toChinese = val => {
|
|
361
|
+
let chin = ["\u4E00", "\u4E8C", "\u4E09", "\u56DB", "\u4E94", "\u516D", "\u4E03", "\u516B", "\u4E5D", "\u5341"];
|
|
362
|
+
if (val <= 10) {
|
|
363
|
+
return chin[val - 1];
|
|
364
|
+
} else if (val <= 100) {
|
|
365
|
+
if (val < 20) {
|
|
366
|
+
return "\u5341" + chin[val % 10 - 1];
|
|
367
|
+
} else if (val % 10 === 0) {
|
|
368
|
+
return chin[Math.floor(val / 10) - 1] + "\u5341";
|
|
369
|
+
} else {
|
|
370
|
+
return chin[Math.floor(val / 10) - 1] + "\u5341" + chin[val % 10 - 1];
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
};
|
|
374
|
+
const limitDecimal = (num, digit = 2) => {
|
|
375
|
+
if (!num) return 0;
|
|
376
|
+
if (typeof num === "string") {
|
|
377
|
+
return parseFloat(parseFloat(num).toFixed(digit));
|
|
378
|
+
} else if (typeof num === "number") {
|
|
379
|
+
return parseFloat(num.toFixed(digit));
|
|
380
|
+
} else {
|
|
381
|
+
return 0;
|
|
382
|
+
}
|
|
383
|
+
};
|
|
384
|
+
const forcedDecimals = (num, digit = 2) => {
|
|
385
|
+
if (typeof num === "string" && num !== "") {
|
|
386
|
+
let s = parseFloat(num).toFixed(digit);
|
|
387
|
+
let rs = s.indexOf(".");
|
|
388
|
+
if (rs < 0 && digit > 0) {
|
|
389
|
+
rs = s.length;
|
|
390
|
+
s += ".";
|
|
391
|
+
}
|
|
392
|
+
while (s.length <= rs + digit) {
|
|
393
|
+
s += "0";
|
|
394
|
+
}
|
|
395
|
+
return s;
|
|
396
|
+
} else if (typeof num === "number") {
|
|
397
|
+
let s = num.toFixed(digit);
|
|
398
|
+
let rs = s.indexOf(".");
|
|
399
|
+
if (rs < 0 && digit > 0) {
|
|
400
|
+
rs = s.length;
|
|
401
|
+
s += ".";
|
|
402
|
+
}
|
|
403
|
+
while (s.length <= rs + digit) {
|
|
404
|
+
s += "0";
|
|
405
|
+
}
|
|
406
|
+
return s;
|
|
407
|
+
} else {
|
|
408
|
+
num = 0;
|
|
409
|
+
let s = num.toFixed(digit);
|
|
410
|
+
let rs = s.indexOf(".");
|
|
411
|
+
if (rs < 0 && digit > 0) {
|
|
412
|
+
rs = s.length;
|
|
413
|
+
s += ".";
|
|
414
|
+
}
|
|
415
|
+
while (s.length <= rs + digit) {
|
|
416
|
+
s += "0";
|
|
417
|
+
}
|
|
418
|
+
return s;
|
|
419
|
+
}
|
|
420
|
+
};
|
|
421
|
+
const formatDuring = (time = 0, type = "day", unit = 1, isComplement = true) => {
|
|
422
|
+
const getString = val => {
|
|
423
|
+
if (val < 10) {
|
|
424
|
+
return `0${val}`;
|
|
425
|
+
} else {
|
|
426
|
+
return `${val}`;
|
|
427
|
+
}
|
|
428
|
+
};
|
|
429
|
+
const days = parseInt(`${time / (unit * 60 * 60 * 24)}`, 10);
|
|
430
|
+
const hours = parseInt(`${time % (unit * 60 * 60 * 24) / (unit * 60 * 60)}`, 10);
|
|
431
|
+
const minutes = parseInt(`${time % (unit * 60 * 60) / (unit * 60)}`, 10);
|
|
432
|
+
const seconds = parseInt(`${time % (unit * 60) / unit}`, 10);
|
|
433
|
+
if (type === "day") {
|
|
434
|
+
return {
|
|
435
|
+
days,
|
|
436
|
+
hours: isComplement ? getString(hours) : hours,
|
|
437
|
+
minutes: isComplement ? getString(minutes) : minutes,
|
|
438
|
+
seconds: isComplement ? getString(seconds) : seconds
|
|
439
|
+
};
|
|
440
|
+
} else if (type === "hour") {
|
|
441
|
+
return {
|
|
442
|
+
hours: isComplement ? getString(days * 60 + hours) : days * 60 + hours,
|
|
443
|
+
minutes: isComplement ? getString(minutes) : minutes,
|
|
444
|
+
seconds: isComplement ? getString(seconds) : seconds
|
|
445
|
+
};
|
|
446
|
+
} else if (type === "minute") {
|
|
447
|
+
return {
|
|
448
|
+
minutes: isComplement ? getString((days * 60 + hours) * 60 + minutes) : (days * 60 + hours) * 60 + minutes,
|
|
449
|
+
seconds: isComplement ? getString(seconds) : seconds
|
|
450
|
+
};
|
|
451
|
+
} else if (type === "second") {
|
|
452
|
+
return {
|
|
453
|
+
seconds: isComplement ? getString(((days * 60 + hours) * 60 + minutes) * 60 + seconds) : ((days * 60 + hours) * 60 + minutes) * 60 + seconds
|
|
454
|
+
};
|
|
455
|
+
}
|
|
456
|
+
return {
|
|
457
|
+
days,
|
|
458
|
+
hours: isComplement ? getString(hours) : hours,
|
|
459
|
+
minutes: isComplement ? getString(minutes) : minutes,
|
|
460
|
+
seconds: isComplement ? getString(seconds) : seconds
|
|
461
|
+
};
|
|
462
|
+
};
|
|
463
|
+
|
|
464
|
+
function downloadFile(data, fileName) {
|
|
465
|
+
if (data.type === "application/json") {
|
|
466
|
+
const fileReader = new FileReader();
|
|
467
|
+
fileReader.readAsText(data, "utf-8");
|
|
468
|
+
let isError = false;
|
|
469
|
+
fileReader.onload = function () {
|
|
470
|
+
try {
|
|
471
|
+
const res = JSON.parse(fileReader.result);
|
|
472
|
+
if (res.code !== "M0000") {
|
|
473
|
+
isError = true;
|
|
474
|
+
const msg = JSON.parse(fileReader.result).message || "\u5BFC\u51FA\u5931\u8D25";
|
|
475
|
+
message.error(msg);
|
|
476
|
+
}
|
|
477
|
+
} catch (e) {}
|
|
478
|
+
};
|
|
479
|
+
if (isError) {
|
|
480
|
+
return;
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
const blob = URL.createObjectURL(data);
|
|
484
|
+
const aEl = document.createElement("a");
|
|
485
|
+
aEl.href = blob;
|
|
486
|
+
aEl.download = fileName;
|
|
487
|
+
aEl.click();
|
|
488
|
+
}
|
|
489
|
+
var file = {
|
|
490
|
+
downloadFile
|
|
491
|
+
};
|
|
492
|
+
|
|
493
|
+
export { ApiInstance, Login, base64, fetchApi, file, forcedDecimals, formatDuring, formatMoney, limitDecimal, phoneNumber, ramdom as random, screen, setRem, toChinese, upload };
|