@ajaxjs/ui 1.1.8 → 1.2.0
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/dist/index.d.ts +0 -1
- package/dist/index.js +1 -2
- package/dist/index.js.map +1 -1
- package/dist/util/utils.d.ts +7 -0
- package/dist/util/utils.js +35 -1
- package/dist/util/utils.js.map +1 -1
- package/package.json +3 -3
- package/src/App.vue +14 -0
- package/src/index.ts +50 -0
- package/src/main.ts +12 -0
- package/src/pages/calendar.vue +33 -0
- package/src/pages/form.vue +68 -0
- package/src/pages/html-editor.vue +44 -0
- package/src/pages/index.vue +150 -0
- package/src/pages/play-ground.vue +14 -0
- package/src/pages/widgets.vue +183 -0
- package/src/router/index.ts +19 -0
- package/src/shims-vue.d.ts +4 -0
- package/src/style/common-functions.less +294 -0
- package/src/style/reset.less +19 -0
- package/src/util/cookies.ts +43 -0
- package/src/util/dom.ts +47 -0
- package/src/util/utils.ts +184 -0
- package/src/util/xhr-config.ts +25 -0
- package/src/util/xhr.ts +296 -0
- package/src/widget/AccordionMenu.vue +140 -0
- package/src/widget/AdjustFontSize.vue +65 -0
- package/src/widget/Article.vue +59 -0
- package/src/widget/EmptyContent.js +4 -0
- package/src/widget/Expander.vue +65 -0
- package/src/widget/FileUploader/FileUploader.less +68 -0
- package/src/widget/FileUploader/FileUploader.ts +156 -0
- package/src/widget/FileUploader/FileUploader.vue +43 -0
- package/src/widget/HtmlEditor/HtmlEditor.less +345 -0
- package/src/widget/HtmlEditor/HtmlEditor.ts +339 -0
- package/src/widget/HtmlEditor/HtmlEditor.vue +70 -0
- package/src/widget/HtmlEditor/html-editor-HtmlSanitizer.js +103 -0
- package/src/widget/ImageEnlarger.vue +105 -0
- package/src/widget/OpacityBanner.vue +125 -0
- package/src/widget/ProcessLine.vue +133 -0
- package/src/widget/Resize.ts +152 -0
- package/src/widget/Resize.vue +104 -0
- package/src/widget/TreeSelector.vue +4 -0
- package/src/widget/calendar/BetweenDate.vue +63 -0
- package/src/widget/calendar/Calendar.less +210 -0
- package/src/widget/calendar/Calendar.ts +167 -0
- package/src/widget/calendar/Calendar.vue +52 -0
- package/src/widget/calendar/CalendarInput.vue +71 -0
- package/src/widget/form/validator.ts +289 -0
- package/src/widget/play-ground/sku.vue +93 -0
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 通用工具类
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
const env = process.env.NODE_ENV;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 是否调试模式中
|
|
9
|
+
*
|
|
10
|
+
* 打包成组件之后不能用
|
|
11
|
+
*
|
|
12
|
+
* @returns
|
|
13
|
+
*/
|
|
14
|
+
export function isDebug(): boolean {
|
|
15
|
+
return env === 'development';
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function isDev(): boolean {
|
|
19
|
+
let currentHostname: string = window.location.hostname;
|
|
20
|
+
|
|
21
|
+
// 判断主机名是否是内网地址
|
|
22
|
+
return (currentHostname.startsWith('192.168.') || currentHostname.startsWith('10.') || currentHostname === 'localhost');
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* 日期格式化。详见博客文章:http://blog.csdn.net/zhangxin09/archive/2011/01/01/6111294.aspx
|
|
27
|
+
* e.g: new Date().format("yyyy-MM-dd hh:mm:ss")
|
|
28
|
+
*
|
|
29
|
+
* @param {String} format
|
|
30
|
+
* @return {String}
|
|
31
|
+
*/
|
|
32
|
+
export function dateFormat(this: Date, format: string): string {
|
|
33
|
+
let $1, o: any = {
|
|
34
|
+
"M+": this.getMonth() + 1, // 月份,从0开始算
|
|
35
|
+
"d+": this.getDate(), // 日期
|
|
36
|
+
"h+": this.getHours(), // 小时
|
|
37
|
+
"m+": this.getMinutes(), // 分钟
|
|
38
|
+
"s+": this.getSeconds(), // 秒钟
|
|
39
|
+
// 季度 quarter
|
|
40
|
+
"q+": Math.floor((this.getMonth() + 3) / 3),
|
|
41
|
+
"S": this.getMilliseconds() // 千秒
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
if (/(y+)/.test(format)) {
|
|
45
|
+
$1 = RegExp.$1, format = format.replace($1, String(this.getFullYear()).substr(4 - $1));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
let key: string, value: string;
|
|
49
|
+
for (key in o) { // 如果没有指定该参数,则子字符串将延续到 stringvar 的最后。
|
|
50
|
+
if (new RegExp("(" + key + ")").test(format)) {
|
|
51
|
+
$1 = RegExp.$1,
|
|
52
|
+
value = String(o[key]),
|
|
53
|
+
value = $1.length == 1 ? value : ("00" + value).substr(value.length),
|
|
54
|
+
format = format.replace($1, value);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return format;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* 日期格式化
|
|
63
|
+
* @author meizz
|
|
64
|
+
* @param date 日期,必须为 Date 类型
|
|
65
|
+
* @param fmt 格式模板
|
|
66
|
+
* @returns 格式化后的字符串
|
|
67
|
+
*/
|
|
68
|
+
export function dateFormat2(date: Date, fmt: string): string {
|
|
69
|
+
let o: { [key: string]: number } = {
|
|
70
|
+
"M+": date.getMonth() + 1, // 月份
|
|
71
|
+
"d+": date.getDate(), // 日
|
|
72
|
+
"h+": date.getHours(), // 小时
|
|
73
|
+
"m+": date.getMinutes(), // 分
|
|
74
|
+
"s+": date.getSeconds(), // 秒
|
|
75
|
+
"q+": Math.floor((date.getMonth() + 3) / 3),// 季度
|
|
76
|
+
"S": date.getMilliseconds() // 毫秒
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
if (/(y+)/.test(fmt))
|
|
80
|
+
fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
|
|
81
|
+
|
|
82
|
+
for (var k in o)
|
|
83
|
+
if (new RegExp("(" + k + ")").test(fmt)) {
|
|
84
|
+
let obj = (RegExp.$1.length == 1) ? o[k] : ("00" + o[k]).substr(("" + o[k]).length);
|
|
85
|
+
// @ts-ignore
|
|
86
|
+
fmt = fmt.replace(RegExp.$1, obj);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return fmt;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* 并行和串行任务
|
|
94
|
+
*
|
|
95
|
+
* @author https://segmentfault.com/a/1190000013265925
|
|
96
|
+
* @param arr
|
|
97
|
+
* @param finnaly
|
|
98
|
+
*/
|
|
99
|
+
export function parallel(arr: [], _finally: Function) {
|
|
100
|
+
let fn: Function, index: number = 0;
|
|
101
|
+
// @ts-ignore
|
|
102
|
+
let statusArr = Array(arr.length).fill().map(() => ({ isActive: false, data: null }));
|
|
103
|
+
|
|
104
|
+
let isFinished = function () {
|
|
105
|
+
return statusArr.every((item: any) => item.isActive === true);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
let resolve = function (index: number): Function {
|
|
109
|
+
return function (data: any) {
|
|
110
|
+
statusArr[index].data = data;
|
|
111
|
+
statusArr[index].isActive = true;
|
|
112
|
+
let isFinish = isFinished();
|
|
113
|
+
|
|
114
|
+
if (isFinish) {
|
|
115
|
+
let datas = statusArr.map((item: any) => item.data);
|
|
116
|
+
|
|
117
|
+
_finally(datas);
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
// @ts-ignore
|
|
123
|
+
while ((fn = arr.shift())) {
|
|
124
|
+
fn(resolve(index));// 给 resolve 函数追加参数,可以使用 bind 函数实现,这里使用了柯里化
|
|
125
|
+
index++;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* 函数节流
|
|
131
|
+
*
|
|
132
|
+
* @author https://www.cnblogs.com/moqiutao/p/6875955.html
|
|
133
|
+
* @param fn
|
|
134
|
+
* @param delay
|
|
135
|
+
* @param mustRunDelay
|
|
136
|
+
*/
|
|
137
|
+
export function throttle(fn: Function, delay: number, mustRunDelay: number): Function {
|
|
138
|
+
var timer: number, t_start: number;
|
|
139
|
+
|
|
140
|
+
return function () {
|
|
141
|
+
var t_curr = +new Date();
|
|
142
|
+
window.clearTimeout(timer);
|
|
143
|
+
|
|
144
|
+
if (!t_start)
|
|
145
|
+
t_start = t_curr;
|
|
146
|
+
|
|
147
|
+
if (t_curr - t_start >= mustRunDelay) {
|
|
148
|
+
// @ts-ignore
|
|
149
|
+
fn.apply(this, arguments);
|
|
150
|
+
t_start = t_curr;
|
|
151
|
+
} else {
|
|
152
|
+
var args = arguments;
|
|
153
|
+
// @ts-ignore
|
|
154
|
+
timer = window.setTimeout(() => fn.apply(this, args), delay);
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* 复制文字到剪切板
|
|
161
|
+
*
|
|
162
|
+
* @param {*} text
|
|
163
|
+
*/
|
|
164
|
+
export function copyToClipboard(text) {
|
|
165
|
+
if (navigator.clipboard) {
|
|
166
|
+
// clipboard api 复制
|
|
167
|
+
navigator.clipboard.writeText(text);
|
|
168
|
+
} else {
|
|
169
|
+
let textarea = document.createElement('textarea');
|
|
170
|
+
document.body.appendChild(textarea);
|
|
171
|
+
// 隐藏此输入框
|
|
172
|
+
textarea.style.position = 'fixed';
|
|
173
|
+
textarea.style.clip = 'rect(0 0 0 0)';
|
|
174
|
+
textarea.style.top = '10px';
|
|
175
|
+
// 赋值
|
|
176
|
+
textarea.value = text;
|
|
177
|
+
// 选中
|
|
178
|
+
textarea.select();
|
|
179
|
+
// 复制
|
|
180
|
+
document.execCommand('copy', true);
|
|
181
|
+
// 移除输入框
|
|
182
|
+
document.body.removeChild(textarea);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* XHR 请求配置
|
|
3
|
+
*/
|
|
4
|
+
export interface XhrConfig {
|
|
5
|
+
/**
|
|
6
|
+
* 请求头里面的 Content-Type 字段
|
|
7
|
+
*/
|
|
8
|
+
contentType?: string;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* XHR 响应结果的类型
|
|
12
|
+
*/
|
|
13
|
+
parseContentType?: 'text' | 'xml' | 'json';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* 超时时间,单位是毫秒
|
|
17
|
+
* 设为 0 适合不控制超时
|
|
18
|
+
*/
|
|
19
|
+
timeout?: number;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* 是否跨域
|
|
23
|
+
*/
|
|
24
|
+
withCredentials?: boolean;
|
|
25
|
+
}
|
package/src/util/xhr.ts
ADDED
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
import { XhrConfig } from './xhr-config';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 默认的请求配置
|
|
5
|
+
*/
|
|
6
|
+
const DEFAULT_XHR_CFG: XhrConfig = {
|
|
7
|
+
timeout: 5000,
|
|
8
|
+
withCredentials: false,
|
|
9
|
+
parseContentType: 'json'
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* 处理响应的回调函数
|
|
14
|
+
*/
|
|
15
|
+
type XhrCallback = (json: {}, text: string) => void;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* 全局请求的 head 参数
|
|
19
|
+
*/
|
|
20
|
+
let BASE_HEAD_PARAMS = null;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* 设置全局请求的 head 参数
|
|
24
|
+
*
|
|
25
|
+
* @param param
|
|
26
|
+
*/
|
|
27
|
+
export function setBaseHeadParams(params: any): void {
|
|
28
|
+
if (BASE_HEAD_PARAMS === null)
|
|
29
|
+
BASE_HEAD_PARAMS = {};
|
|
30
|
+
|
|
31
|
+
Object.assign(BASE_HEAD_PARAMS, params);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
*
|
|
36
|
+
* @param getOrDel
|
|
37
|
+
* @param url
|
|
38
|
+
* @param cb
|
|
39
|
+
* @param params
|
|
40
|
+
* @param cfg
|
|
41
|
+
*/
|
|
42
|
+
function getOrDel(getOrDel: 'get' | 'delete', url: string, cb: XhrCallback, params?: {}, cfg: XhrConfig = DEFAULT_XHR_CFG): void {
|
|
43
|
+
let xhr: XMLHttpRequest = initXhr(cfg);
|
|
44
|
+
|
|
45
|
+
if (params != null) {
|
|
46
|
+
if (url.indexOf('?') != -1)
|
|
47
|
+
url += '&' + toParams(params);
|
|
48
|
+
else
|
|
49
|
+
url += '?' + toParams(params);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
xhr.open(getOrDel.toUpperCase(), url, true);
|
|
53
|
+
xhr.onreadystatechange = function () {
|
|
54
|
+
responseHandle(this, cb, cfg);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (BASE_HEAD_PARAMS)// 设置自定义请求头
|
|
58
|
+
for (let key in BASE_HEAD_PARAMS)
|
|
59
|
+
xhr.setRequestHeader(key, BASE_HEAD_PARAMS[key]);
|
|
60
|
+
|
|
61
|
+
xhr.send();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
*
|
|
66
|
+
* @param method
|
|
67
|
+
* @param url
|
|
68
|
+
* @param cb
|
|
69
|
+
* @param params
|
|
70
|
+
* @param cfg
|
|
71
|
+
*/
|
|
72
|
+
function postOrPut(method: 'post' | 'put', url: string, cb: XhrCallback, params: string | {}, cfg: XhrConfig = DEFAULT_XHR_CFG): void {
|
|
73
|
+
let xhr: XMLHttpRequest = initXhr(cfg);
|
|
74
|
+
xhr.open(method, url, true);
|
|
75
|
+
xhr.onreadystatechange = function () {
|
|
76
|
+
responseHandle(this, cb, cfg);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (BASE_HEAD_PARAMS) // 设置自定义请求头
|
|
80
|
+
for (let key in BASE_HEAD_PARAMS)
|
|
81
|
+
xhr.setRequestHeader(key, BASE_HEAD_PARAMS[key]);
|
|
82
|
+
|
|
83
|
+
// 此方法必须在 open() 方法和 send() 之间调用
|
|
84
|
+
|
|
85
|
+
if (!cfg.contentType) // 如未设置,默认为表单请求
|
|
86
|
+
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
|
87
|
+
else
|
|
88
|
+
xhr.setRequestHeader("Content-Type", cfg.contentType);
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
let _params: string = typeof params != 'string' ? toParams(params) : <string>params;
|
|
92
|
+
|
|
93
|
+
if (_params)
|
|
94
|
+
xhr.send(_params);
|
|
95
|
+
else
|
|
96
|
+
xhr.send();
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
*
|
|
101
|
+
* @param url
|
|
102
|
+
* @param cb
|
|
103
|
+
* @param params
|
|
104
|
+
* @param cfg
|
|
105
|
+
*/
|
|
106
|
+
export function xhr_post_upload(url: string, cb: XhrCallback, params: Document | XMLHttpRequestBodyInit, cfg: XhrConfig = DEFAULT_XHR_CFG): void {
|
|
107
|
+
let xhr: XMLHttpRequest = initXhr(cfg);
|
|
108
|
+
xhr.open('post', url, true);
|
|
109
|
+
xhr.onreadystatechange = function () {
|
|
110
|
+
responseHandle(this, cb, cfg);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (BASE_HEAD_PARAMS) // 设置自定义请求头
|
|
114
|
+
for (let key in BASE_HEAD_PARAMS)
|
|
115
|
+
xhr.setRequestHeader(key, BASE_HEAD_PARAMS[key]);
|
|
116
|
+
|
|
117
|
+
// 什么 Content-Type 都不设置
|
|
118
|
+
|
|
119
|
+
xhr.send(params);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* XHR GET 请求
|
|
124
|
+
*
|
|
125
|
+
* @param url 请求地址
|
|
126
|
+
* @param cb 回调函数 @example (json: {}, text: string) => void;
|
|
127
|
+
* @param params 参数,必填,如无填空字符串 "";参数类型是json;参数值会进行 URL 编码,最后附加到 QueryString 中
|
|
128
|
+
* @param cfg 配置,可选的
|
|
129
|
+
*/
|
|
130
|
+
export function xhr_get(url: string, cb: XhrCallback, params?: {}, cfg: XhrConfig = DEFAULT_XHR_CFG): void {
|
|
131
|
+
getOrDel('get', url, cb, params, cfg);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* XHR DELETE 请求
|
|
136
|
+
*
|
|
137
|
+
* @param url 请求地址
|
|
138
|
+
* @param cb 回调函数 @example (json: {}, text: string) => void;
|
|
139
|
+
* @param params 参数,必填,如无填空字符串 "";参数类型是json;参数值会进行 URL 编码,最后附加到 QueryString 中
|
|
140
|
+
* @param cfg 配置,可选的
|
|
141
|
+
*/
|
|
142
|
+
export function xhr_del(url: string, cb: XhrCallback, params?: {}, cfg: XhrConfig = DEFAULT_XHR_CFG): void {
|
|
143
|
+
getOrDel('delete', url, cb, params, cfg);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* XHR POST 请求
|
|
148
|
+
*
|
|
149
|
+
* @param url 请求地址
|
|
150
|
+
* @param cb 回调函数 @example (json: {}, text: string) => void;
|
|
151
|
+
* @param params 参数,必填,如无填空字符串 "";参数类型可以是字符串或 json;参数值会进行 URL 编码
|
|
152
|
+
* @param cfg 配置,可选的
|
|
153
|
+
*/
|
|
154
|
+
export function xhr_post(url: string, cb: XhrCallback, params: string | {}, cfg: XhrConfig = DEFAULT_XHR_CFG): void {
|
|
155
|
+
postOrPut('post', url, cb, params, cfg);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* XHR PUT 请求
|
|
160
|
+
*
|
|
161
|
+
* @param url 请求地址
|
|
162
|
+
* @param cb 回调函数 @example (json: {}, text: string) => void;
|
|
163
|
+
* @param params 参数,必填,如无填空字符串 "";参数类型可以是字符串或 json;参数值会进行 URL 编码
|
|
164
|
+
* @param cfg 配置,可选的
|
|
165
|
+
*/
|
|
166
|
+
export function xhr_put(url: string, cb: XhrCallback, params: string | {}, cfg: XhrConfig = DEFAULT_XHR_CFG): void {
|
|
167
|
+
postOrPut('put', url, cb, params, cfg);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* 初始化 XHR
|
|
172
|
+
*
|
|
173
|
+
* @param cfg
|
|
174
|
+
* @returns
|
|
175
|
+
*/
|
|
176
|
+
function initXhr(cfg: XhrConfig): XMLHttpRequest {
|
|
177
|
+
let xhr: XMLHttpRequest = new XMLHttpRequest();
|
|
178
|
+
|
|
179
|
+
if (cfg && cfg.timeout) {
|
|
180
|
+
xhr.timeout = cfg.timeout;
|
|
181
|
+
xhr.ontimeout = (e: ProgressEvent<EventTarget>) => console.error('系统异常,XHR 连接服务超时');
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
if (cfg && cfg.withCredentials)
|
|
185
|
+
xhr.withCredentials = true;
|
|
186
|
+
|
|
187
|
+
return xhr;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* 错误处理
|
|
192
|
+
*
|
|
193
|
+
* @param xhr
|
|
194
|
+
*/
|
|
195
|
+
function errHandle(xhr: XMLHttpRequest): void {
|
|
196
|
+
let msg: string;
|
|
197
|
+
|
|
198
|
+
if (xhr.status <= 400)
|
|
199
|
+
msg = '请求参数错误或者权限不足。';
|
|
200
|
+
else if (xhr.status <= 500)
|
|
201
|
+
msg = '服务端异常。';
|
|
202
|
+
else
|
|
203
|
+
msg = `未知异常,HTTP code:${xhr.status}。`;
|
|
204
|
+
|
|
205
|
+
if (!xhr.responseText)
|
|
206
|
+
msg += " 服务端返回空的字符串!";
|
|
207
|
+
|
|
208
|
+
console.error(msg, xhr.responseText);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* 响应处理
|
|
213
|
+
*
|
|
214
|
+
* @param xhr
|
|
215
|
+
* @param cb
|
|
216
|
+
* @param cfg
|
|
217
|
+
*/
|
|
218
|
+
function responseHandle(xhr: XMLHttpRequest, cb: XhrCallback, cfg: XhrConfig): void {
|
|
219
|
+
if (xhr.readyState == 4) {
|
|
220
|
+
if ((xhr.status >= 200 && xhr.status < 300) || xhr.status == 304) {
|
|
221
|
+
let text: string = xhr.responseText;
|
|
222
|
+
let json: any;
|
|
223
|
+
|
|
224
|
+
if (!text)
|
|
225
|
+
console.warn('服务端没有返回任何字符串');
|
|
226
|
+
|
|
227
|
+
switch (cfg.parseContentType) {
|
|
228
|
+
case 'text':
|
|
229
|
+
break;
|
|
230
|
+
case 'xml':
|
|
231
|
+
json = xhr.responseXML;
|
|
232
|
+
break;
|
|
233
|
+
case 'json':
|
|
234
|
+
default:
|
|
235
|
+
try {
|
|
236
|
+
json = JSON.parse(text);
|
|
237
|
+
} catch (e) {
|
|
238
|
+
console.error('解析 JSON 时候发生错误,非法 JSON');
|
|
239
|
+
console.warn(e);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
cb && cb(json, text);
|
|
244
|
+
} else errHandle(xhr);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* 对象转换为 URL 参数列表,用 & 分隔
|
|
250
|
+
*
|
|
251
|
+
* @param {Object} param JSON 对象
|
|
252
|
+
* @returns URL 参数列表
|
|
253
|
+
*/
|
|
254
|
+
export function toParams(param: any): string {
|
|
255
|
+
let result: string = "";
|
|
256
|
+
|
|
257
|
+
for (let name in param) {
|
|
258
|
+
if (typeof param[name] != "function")
|
|
259
|
+
result += "&" + name + "=" + encodeURIComponent(param[name]);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
return result.substring(1);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* 获取 QueryString 的某个参数
|
|
267
|
+
*
|
|
268
|
+
* @param val
|
|
269
|
+
* @returns
|
|
270
|
+
*/
|
|
271
|
+
export function getQuery(val: string): string {
|
|
272
|
+
const w: number = location.hash.indexOf('?');
|
|
273
|
+
const query: string = location.hash.substring(w + 1);
|
|
274
|
+
let vars: string[] = query.split('&');
|
|
275
|
+
|
|
276
|
+
for (let i = 0; i < vars.length; i++) {
|
|
277
|
+
const pair = vars[i].split('=');
|
|
278
|
+
|
|
279
|
+
if (pair[0] == val)
|
|
280
|
+
return pair[1];
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
return '';
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
export function getPageList(self: any, listArray: any, callback?: Function): XhrCallback {
|
|
287
|
+
return (j: any) => {
|
|
288
|
+
if (j.status) {
|
|
289
|
+
listArray.total = j.total;
|
|
290
|
+
listArray.data = j.data;
|
|
291
|
+
|
|
292
|
+
callback && callback();
|
|
293
|
+
} else
|
|
294
|
+
self.$Message.warning(j.message || '获取数据失败');
|
|
295
|
+
}
|
|
296
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<ul class="aj-accordion-menu" @click="onClk">
|
|
3
|
+
<slot></slot>
|
|
4
|
+
</ul>
|
|
5
|
+
</template>
|
|
6
|
+
|
|
7
|
+
<script lang="ts">
|
|
8
|
+
/**
|
|
9
|
+
* 内部子菜单的高亮
|
|
10
|
+
*
|
|
11
|
+
* @param ev
|
|
12
|
+
*/
|
|
13
|
+
function highlightSubItem(ev: Event) {
|
|
14
|
+
let li: Element,
|
|
15
|
+
el: Element = ev.target as Element;
|
|
16
|
+
|
|
17
|
+
if (el.tagName == "A" && el.getAttribute("target")) {
|
|
18
|
+
li = el.parentNode as Element;
|
|
19
|
+
li.querySelectorAll("li").forEach((_el: Element) => {
|
|
20
|
+
if (_el == li) _el.classList.add("selected");
|
|
21
|
+
else _el.classList.remove("selected");
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export default {
|
|
27
|
+
methods: {
|
|
28
|
+
onClk(ev: Event): void {
|
|
29
|
+
let children: HTMLCollection = this.$el.children;
|
|
30
|
+
highlightSubItem(ev);
|
|
31
|
+
let _btn: Element = ev.target as Element;
|
|
32
|
+
|
|
33
|
+
if (
|
|
34
|
+
_btn &&
|
|
35
|
+
_btn.tagName == "H3" &&
|
|
36
|
+
(_btn.parentNode as Element).tagName == "LI"
|
|
37
|
+
) {
|
|
38
|
+
_btn = _btn.parentNode as Element;
|
|
39
|
+
|
|
40
|
+
for (let btn: Element, i: number = 0, j = children.length; i < j; i++) {
|
|
41
|
+
btn = children[i];
|
|
42
|
+
let ul = btn.querySelector("ul");
|
|
43
|
+
|
|
44
|
+
if (btn == _btn) {
|
|
45
|
+
if (btn.className.indexOf("pressed") != -1) {
|
|
46
|
+
btn.classList.remove("pressed"); // 再次点击,隐藏!
|
|
47
|
+
if (ul) ul.style.height = "0px";
|
|
48
|
+
} else {
|
|
49
|
+
if (ul) ul.style.height = ul.scrollHeight + "px";
|
|
50
|
+
btn.classList.add("pressed");
|
|
51
|
+
}
|
|
52
|
+
} else {
|
|
53
|
+
btn.classList.remove("pressed");
|
|
54
|
+
if (ul) ul.style.height = "0px";
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
} else return;
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
</script>
|
|
62
|
+
|
|
63
|
+
<style lang="less" scoped>
|
|
64
|
+
@import "../style/common-functions.less";
|
|
65
|
+
|
|
66
|
+
// 折叠菜单 Accordion Menu
|
|
67
|
+
.aj-accordion {
|
|
68
|
+
& > li h3 {
|
|
69
|
+
cursor: pointer;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
.pressed {
|
|
73
|
+
& h3 {
|
|
74
|
+
color: black;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
& > li > ul {
|
|
79
|
+
.transition (height .5s cubic-bezier(0, 1, 0.5, 1));;
|
|
80
|
+
overflow: hidden;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
ul {
|
|
84
|
+
height: 0;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
.aj-accordion-menu {
|
|
89
|
+
.aj-accordion ();
|
|
90
|
+
overflow: hidden;
|
|
91
|
+
|
|
92
|
+
& > li {
|
|
93
|
+
border-top: 1px solid white;
|
|
94
|
+
border-bottom: 1px solid lightgray;
|
|
95
|
+
|
|
96
|
+
&.pressed {
|
|
97
|
+
border-top: 0;
|
|
98
|
+
border-bottom: 1px solid lightgray;
|
|
99
|
+
box-shadow: inset 0px 10px 15px -15px gray;
|
|
100
|
+
|
|
101
|
+
h3 {
|
|
102
|
+
font-weight: bold;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
ul {
|
|
107
|
+
li {
|
|
108
|
+
// list-style-type: disc;
|
|
109
|
+
padding-left: 15%;
|
|
110
|
+
|
|
111
|
+
a {
|
|
112
|
+
width: 100%;
|
|
113
|
+
display: block;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
&.selected {
|
|
117
|
+
a {
|
|
118
|
+
color: black;
|
|
119
|
+
font-weight: bold;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
h3,
|
|
126
|
+
li {
|
|
127
|
+
padding: 5px 0 5px 15px;
|
|
128
|
+
letter-spacing: 2px;
|
|
129
|
+
line-height: 20px;
|
|
130
|
+
color: #939da8;
|
|
131
|
+
font-size: 12px;
|
|
132
|
+
|
|
133
|
+
&:hover,
|
|
134
|
+
a:hover {
|
|
135
|
+
color: black;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
</style>
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="aj-adjust-font-size">
|
|
3
|
+
<span>字体大小</span>
|
|
4
|
+
<ul @click="onClk">
|
|
5
|
+
<li><label><input type="radio" name="fontSize" /> 小</label></li>
|
|
6
|
+
<li><label><input type="radio" name="fontSize" /> 中</label></li>
|
|
7
|
+
<li><label><input type="radio" name="fontSize" /> 大</label></li>
|
|
8
|
+
</ul>
|
|
9
|
+
</div>
|
|
10
|
+
</template>
|
|
11
|
+
|
|
12
|
+
<script lang="ts">
|
|
13
|
+
/**
|
|
14
|
+
* 调整正文字体大小
|
|
15
|
+
*/
|
|
16
|
+
export default {
|
|
17
|
+
props: {
|
|
18
|
+
articleTarget: { type: String, default: "article p" }, // 正文所在的位置,通过 CSS Selector 定位
|
|
19
|
+
},
|
|
20
|
+
methods: {
|
|
21
|
+
onClk(ev: Event): void {
|
|
22
|
+
let el: Element = ev.target as Element;
|
|
23
|
+
let setFontSize = (fontSize: string): void => {
|
|
24
|
+
document.body
|
|
25
|
+
.querySelectorAll(this.$props.articleTarget)
|
|
26
|
+
.forEach((p: HTMLParagraphElement) => (p.style.fontSize = fontSize));
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
if (el.tagName == "LABEL" || el.tagName == "INPUT") {
|
|
30
|
+
if (el.tagName != "LABEL") el = el.parentNode as Element;
|
|
31
|
+
|
|
32
|
+
if (el.innerHTML.indexOf("大") != -1) setFontSize("12pt");
|
|
33
|
+
else if (el.innerHTML.indexOf("中") != -1) setFontSize("10.5pt");
|
|
34
|
+
else if (el.innerHTML.indexOf("小") != -1) setFontSize("9pt");
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
</script>
|
|
40
|
+
|
|
41
|
+
<style lang="less" scoped>
|
|
42
|
+
.aj-adjust-font-size {
|
|
43
|
+
width: 210px;
|
|
44
|
+
font-size: 0.8rem;
|
|
45
|
+
padding: 2px 0;
|
|
46
|
+
|
|
47
|
+
span {
|
|
48
|
+
float: left;
|
|
49
|
+
width: 35%;
|
|
50
|
+
display: block;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
ul {
|
|
54
|
+
width: 65%;
|
|
55
|
+
float: right;
|
|
56
|
+
cursor: pointer;
|
|
57
|
+
|
|
58
|
+
li {
|
|
59
|
+
display: block;
|
|
60
|
+
float: right;
|
|
61
|
+
width: 33%;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
</style>
|