正在显示
20 个修改的文件
包含
1412 行增加
和
0 行删除
ant-design-pro/Monitor/.gitignore
0 → 100644
ant-design-pro/Monitor/.umirc.js
0 → 100644
1 | +import React, { Component } from 'react'; | |
2 | +import { MiniArea } from 'ant-design-pro/lib/Charts'; | |
3 | +import NumberInfo from 'ant-design-pro/lib/NumberInfo'; | |
4 | + | |
5 | +import styles from './index.less'; | |
6 | + | |
7 | +function fixedZero(val) { | |
8 | + return val * 1 < 10 ? `0${val}` : val; | |
9 | +} | |
10 | + | |
11 | +function getActiveData() { | |
12 | + const activeData = []; | |
13 | + for (let i = 0; i < 24; i += 1) { | |
14 | + activeData.push({ | |
15 | + x: `${fixedZero(i)}:00`, | |
16 | + y: Math.floor(Math.random() * 200) + i * 50, | |
17 | + }); | |
18 | + } | |
19 | + return activeData; | |
20 | +} | |
21 | + | |
22 | +export default class ActiveChart extends Component { | |
23 | + state = { | |
24 | + activeData: getActiveData(), | |
25 | + }; | |
26 | + | |
27 | + componentDidMount() { | |
28 | + this.loopData(); | |
29 | + } | |
30 | + | |
31 | + componentWillUnmount() { | |
32 | + clearTimeout(this.timer); | |
33 | + cancelAnimationFrame(this.requestRef); | |
34 | + } | |
35 | + | |
36 | + loopData = () => { | |
37 | + this.requestRef = requestAnimationFrame(() => { | |
38 | + this.timer = setTimeout(() => { | |
39 | + this.setState( | |
40 | + { | |
41 | + activeData: getActiveData(), | |
42 | + }, | |
43 | + () => { | |
44 | + this.loopData(); | |
45 | + } | |
46 | + ); | |
47 | + }, 1000); | |
48 | + }); | |
49 | + }; | |
50 | + | |
51 | + render() { | |
52 | + const { activeData = [] } = this.state; | |
53 | + | |
54 | + return ( | |
55 | + <div className={styles.activeChart}> | |
56 | + <NumberInfo subTitle="目标评估" total="有望达到预期" /> | |
57 | + <div style={{ marginTop: 32 }}> | |
58 | + <MiniArea | |
59 | + animate={false} | |
60 | + line | |
61 | + borderWidth={2} | |
62 | + height={84} | |
63 | + scale={{ | |
64 | + y: { | |
65 | + tickCount: 3, | |
66 | + }, | |
67 | + }} | |
68 | + yAxis={{ | |
69 | + tickLine: false, | |
70 | + label: false, | |
71 | + title: false, | |
72 | + line: false, | |
73 | + }} | |
74 | + data={activeData} | |
75 | + /> | |
76 | + </div> | |
77 | + {activeData && ( | |
78 | + <div> | |
79 | + <div className={styles.activeChartGrid}> | |
80 | + <p>{[...activeData].sort()[activeData.length - 1].y + 200} 亿元</p> | |
81 | + <p>{[...activeData].sort()[Math.floor(activeData.length / 2)].y} 亿元</p> | |
82 | + </div> | |
83 | + <div className={styles.dashedLine}> | |
84 | + <div className={styles.line} /> | |
85 | + </div> | |
86 | + <div className={styles.dashedLine}> | |
87 | + <div className={styles.line} /> | |
88 | + </div> | |
89 | + </div> | |
90 | + )} | |
91 | + {activeData && ( | |
92 | + <div className={styles.activeChartLegend}> | |
93 | + <span>00:00</span> | |
94 | + <span>{activeData[Math.floor(activeData.length / 2)].x}</span> | |
95 | + <span>{activeData[activeData.length - 1].x}</span> | |
96 | + </div> | |
97 | + )} | |
98 | + </div> | |
99 | + ); | |
100 | + } | |
101 | +} | ... | ... |
1 | +.activeChart { | |
2 | + position: relative; | |
3 | +} | |
4 | +.activeChartGrid { | |
5 | + p { | |
6 | + position: absolute; | |
7 | + top: 80px; | |
8 | + } | |
9 | + p:last-child { | |
10 | + top: 115px; | |
11 | + } | |
12 | +} | |
13 | +.activeChartLegend { | |
14 | + position: relative; | |
15 | + font-size: 0; | |
16 | + margin-top: 8px; | |
17 | + height: 20px; | |
18 | + line-height: 20px; | |
19 | + span { | |
20 | + display: inline-block; | |
21 | + font-size: 12px; | |
22 | + text-align: center; | |
23 | + width: 33.33%; | |
24 | + } | |
25 | + span:first-child { | |
26 | + text-align: left; | |
27 | + } | |
28 | + span:last-child { | |
29 | + text-align: right; | |
30 | + } | |
31 | +} | |
32 | +.dashedLine { | |
33 | + position: relative; | |
34 | + height: 1px; | |
35 | + top: -70px; | |
36 | + left: -3px; | |
37 | + | |
38 | + .line { | |
39 | + position: absolute; | |
40 | + top: 0; | |
41 | + left: 0; | |
42 | + width: 100%; | |
43 | + height: 100%; | |
44 | + background-image: linear-gradient(to right, transparent 50%, #e9e9e9 50%); | |
45 | + background-size: 6px; | |
46 | + } | |
47 | +} | |
48 | + | |
49 | +.dashedLine:last-child { | |
50 | + top: -36px; | |
51 | +} | ... | ... |
1 | +import React, { PureComponent } from 'react'; | |
2 | +import { connect } from 'dva'; | |
3 | +import styles from './GridContent.less'; | |
4 | + | |
5 | +class GridContent extends PureComponent { | |
6 | + render() { | |
7 | + const { contentWidth, children } = this.props; | |
8 | + let className = `${styles.main}`; | |
9 | + if (contentWidth === 'Fixed') { | |
10 | + className = `${styles.main} ${styles.wide}`; | |
11 | + } | |
12 | + return <div className={className}>{children}</div>; | |
13 | + } | |
14 | +} | |
15 | + | |
16 | +export default connect(({ setting }) => ({ | |
17 | + contentWidth: setting.contentWidth, | |
18 | +}))(GridContent); | ... | ... |
ant-design-pro/Monitor/@/services/api.js
0 → 100644
1 | +import { stringify } from 'qs'; | |
2 | +import request from '@/utils/request'; | |
3 | + | |
4 | +export async function queryProjectNotice() { | |
5 | + return request('/api/project/notice'); | |
6 | +} | |
7 | + | |
8 | +export async function queryActivities() { | |
9 | + return request('/api/activities'); | |
10 | +} | |
11 | + | |
12 | +export async function queryRule(params) { | |
13 | + return request(`/api/rule?${stringify(params)}`); | |
14 | +} | |
15 | + | |
16 | +export async function removeRule(params) { | |
17 | + return request('/api/rule', { | |
18 | + method: 'POST', | |
19 | + body: { | |
20 | + ...params, | |
21 | + method: 'delete', | |
22 | + }, | |
23 | + }); | |
24 | +} | |
25 | + | |
26 | +export async function addRule(params) { | |
27 | + return request('/api/rule', { | |
28 | + method: 'POST', | |
29 | + body: { | |
30 | + ...params, | |
31 | + method: 'post', | |
32 | + }, | |
33 | + }); | |
34 | +} | |
35 | + | |
36 | +export async function updateRule(params) { | |
37 | + return request('/api/rule', { | |
38 | + method: 'POST', | |
39 | + body: { | |
40 | + ...params, | |
41 | + method: 'update', | |
42 | + }, | |
43 | + }); | |
44 | +} | |
45 | + | |
46 | +export async function fakeSubmitForm(params) { | |
47 | + return request('/api/forms', { | |
48 | + method: 'POST', | |
49 | + body: params, | |
50 | + }); | |
51 | +} | |
52 | + | |
53 | +export async function fakeChartData() { | |
54 | + return request('/api/fake_chart_data'); | |
55 | +} | |
56 | + | |
57 | +export async function queryTags() { | |
58 | + return request('/api/tags'); | |
59 | +} | |
60 | + | |
61 | +export async function queryBasicProfile() { | |
62 | + return request('/api/profile/basic'); | |
63 | +} | |
64 | + | |
65 | +export async function queryAdvancedProfile() { | |
66 | + return request('/api/profile/advanced'); | |
67 | +} | |
68 | + | |
69 | +export async function queryFakeList(params) { | |
70 | + return request(`/api/fake_list?${stringify(params)}`); | |
71 | +} | |
72 | + | |
73 | +export async function removeFakeList(params) { | |
74 | + const { count = 5, ...restParams } = params; | |
75 | + return request(`/api/fake_list?count=${count}`, { | |
76 | + method: 'POST', | |
77 | + body: { | |
78 | + ...restParams, | |
79 | + method: 'delete', | |
80 | + }, | |
81 | + }); | |
82 | +} | |
83 | + | |
84 | +export async function addFakeList(params) { | |
85 | + const { count = 5, ...restParams } = params; | |
86 | + return request(`/api/fake_list?count=${count}`, { | |
87 | + method: 'POST', | |
88 | + body: { | |
89 | + ...restParams, | |
90 | + method: 'post', | |
91 | + }, | |
92 | + }); | |
93 | +} | |
94 | + | |
95 | +export async function updateFakeList(params) { | |
96 | + const { count = 5, ...restParams } = params; | |
97 | + return request(`/api/fake_list?count=${count}`, { | |
98 | + method: 'POST', | |
99 | + body: { | |
100 | + ...restParams, | |
101 | + method: 'update', | |
102 | + }, | |
103 | + }); | |
104 | +} | |
105 | + | |
106 | +export async function fakeAccountLogin(params) { | |
107 | + return request('/api/login/account', { | |
108 | + method: 'POST', | |
109 | + body: params, | |
110 | + }); | |
111 | +} | |
112 | + | |
113 | +export async function fakeRegister(params) { | |
114 | + return request('/api/register', { | |
115 | + method: 'POST', | |
116 | + body: params, | |
117 | + }); | |
118 | +} | |
119 | + | |
120 | +export async function queryNotices() { | |
121 | + return request('/api/notices'); | |
122 | +} | |
123 | + | |
124 | +export async function getFakeCaptcha(mobile) { | |
125 | + return request(`/api/captcha?mobile=${mobile}`); | |
126 | +} | ... | ... |
ant-design-pro/Monitor/@/utils/Authorized.js
0 → 100644
1 | +import RenderAuthorized from 'ant-design-pro/lib/Authorized'; | |
2 | +import { getAuthority } from './authority'; | |
3 | + | |
4 | +let Authorized = RenderAuthorized(getAuthority()); // eslint-disable-line | |
5 | + | |
6 | +// Reload the rights component | |
7 | +const reloadAuthorized = () => { | |
8 | + Authorized = RenderAuthorized(getAuthority()); | |
9 | +}; | |
10 | + | |
11 | +export { reloadAuthorized }; | |
12 | +export default Authorized; | ... | ... |
ant-design-pro/Monitor/@/utils/authority.js
0 → 100644
1 | +// use localStorage to store the authority info, which might be sent from server in actual project. | |
2 | +export function getAuthority(str) { | |
3 | + // return localStorage.getItem('antd-pro-authority') || ['admin', 'user']; | |
4 | + const authorityString = | |
5 | + typeof str === 'undefined' ? localStorage.getItem('antd-pro-authority') : str; | |
6 | + // authorityString could be admin, "admin", ["admin"] | |
7 | + let authority; | |
8 | + try { | |
9 | + authority = JSON.parse(authorityString); | |
10 | + } catch (e) { | |
11 | + authority = authorityString; | |
12 | + } | |
13 | + if (typeof authority === 'string') { | |
14 | + return [authority]; | |
15 | + } | |
16 | + return authority || ['admin']; | |
17 | +} | |
18 | + | |
19 | +export function setAuthority(authority) { | |
20 | + const proAuthority = typeof authority === 'string' ? [authority] : authority; | |
21 | + return localStorage.setItem('antd-pro-authority', JSON.stringify(proAuthority)); | |
22 | +} | ... | ... |
ant-design-pro/Monitor/@/utils/request.js
0 → 100644
1 | +import fetch from 'dva/fetch'; | |
2 | +import { notification } from 'antd'; | |
3 | +import router from 'umi/router'; | |
4 | +import hash from 'hash.js'; | |
5 | +import { isAntdPro } from './utils'; | |
6 | + | |
7 | +const codeMessage = { | |
8 | + 200: '服务器成功返回请求的数据。', | |
9 | + 201: '新建或修改数据成功。', | |
10 | + 202: '一个请求已经进入后台排队(异步任务)。', | |
11 | + 204: '删除数据成功。', | |
12 | + 400: '发出的请求有错误,服务器没有进行新建或修改数据的操作。', | |
13 | + 401: '用户没有权限(令牌、用户名、密码错误)。', | |
14 | + 403: '用户得到授权,但是访问是被禁止的。', | |
15 | + 404: '发出的请求针对的是不存在的记录,服务器没有进行操作。', | |
16 | + 406: '请求的格式不可得。', | |
17 | + 410: '请求的资源被永久删除,且不会再得到的。', | |
18 | + 422: '当创建一个对象时,发生一个验证错误。', | |
19 | + 500: '服务器发生错误,请检查服务器。', | |
20 | + 502: '网关错误。', | |
21 | + 503: '服务不可用,服务器暂时过载或维护。', | |
22 | + 504: '网关超时。', | |
23 | +}; | |
24 | + | |
25 | +const checkStatus = response => { | |
26 | + if (response.status >= 200 && response.status < 300) { | |
27 | + return response; | |
28 | + } | |
29 | + const errortext = codeMessage[response.status] || response.statusText; | |
30 | + notification.error({ | |
31 | + message: `请求错误 ${response.status}: ${response.url}`, | |
32 | + description: errortext, | |
33 | + }); | |
34 | + const error = new Error(errortext); | |
35 | + error.name = response.status; | |
36 | + error.response = response; | |
37 | + throw error; | |
38 | +}; | |
39 | + | |
40 | +const cachedSave = (response, hashcode) => { | |
41 | + /** | |
42 | + * Clone a response data and store it in sessionStorage | |
43 | + * Does not support data other than json, Cache only json | |
44 | + */ | |
45 | + const contentType = response.headers.get('Content-Type'); | |
46 | + if (contentType && contentType.match(/application\/json/i)) { | |
47 | + // All data is saved as text | |
48 | + response | |
49 | + .clone() | |
50 | + .text() | |
51 | + .then(content => { | |
52 | + sessionStorage.setItem(hashcode, content); | |
53 | + sessionStorage.setItem(`${hashcode}:timestamp`, Date.now()); | |
54 | + }); | |
55 | + } | |
56 | + return response; | |
57 | +}; | |
58 | + | |
59 | +/** | |
60 | + * Requests a URL, returning a promise. | |
61 | + * | |
62 | + * @param {string} url The URL we want to request | |
63 | + * @param {object} [option] The options we want to pass to "fetch" | |
64 | + * @return {object} An object containing either "data" or "err" | |
65 | + */ | |
66 | +export default function request(url, option) { | |
67 | + const options = { | |
68 | + expirys: isAntdPro(), | |
69 | + ...option, | |
70 | + }; | |
71 | + /** | |
72 | + * Produce fingerprints based on url and parameters | |
73 | + * Maybe url has the same parameters | |
74 | + */ | |
75 | + const fingerprint = url + (options.body ? JSON.stringify(options.body) : ''); | |
76 | + const hashcode = hash | |
77 | + .sha256() | |
78 | + .update(fingerprint) | |
79 | + .digest('hex'); | |
80 | + | |
81 | + const defaultOptions = { | |
82 | + credentials: 'include', | |
83 | + }; | |
84 | + const newOptions = { ...defaultOptions, ...options }; | |
85 | + if ( | |
86 | + newOptions.method === 'POST' || | |
87 | + newOptions.method === 'PUT' || | |
88 | + newOptions.method === 'DELETE' | |
89 | + ) { | |
90 | + if (!(newOptions.body instanceof FormData)) { | |
91 | + newOptions.headers = { | |
92 | + Accept: 'application/json', | |
93 | + 'Content-Type': 'application/json; charset=utf-8', | |
94 | + ...newOptions.headers, | |
95 | + }; | |
96 | + newOptions.body = JSON.stringify(newOptions.body); | |
97 | + } else { | |
98 | + // newOptions.body is FormData | |
99 | + newOptions.headers = { | |
100 | + Accept: 'application/json', | |
101 | + ...newOptions.headers, | |
102 | + }; | |
103 | + } | |
104 | + } | |
105 | + | |
106 | + const expirys = options.expirys && 60; | |
107 | + // options.expirys !== false, return the cache, | |
108 | + if (options.expirys !== false) { | |
109 | + const cached = sessionStorage.getItem(hashcode); | |
110 | + const whenCached = sessionStorage.getItem(`${hashcode}:timestamp`); | |
111 | + if (cached !== null && whenCached !== null) { | |
112 | + const age = (Date.now() - whenCached) / 1000; | |
113 | + if (age < expirys) { | |
114 | + const response = new Response(new Blob([cached])); | |
115 | + return response.json(); | |
116 | + } | |
117 | + sessionStorage.removeItem(hashcode); | |
118 | + sessionStorage.removeItem(`${hashcode}:timestamp`); | |
119 | + } | |
120 | + } | |
121 | + return fetch(url, newOptions) | |
122 | + .then(checkStatus) | |
123 | + .then(response => cachedSave(response, hashcode)) | |
124 | + .then(response => { | |
125 | + // DELETE and 204 do not return data by default | |
126 | + // using .json will report an error. | |
127 | + if (newOptions.method === 'DELETE' || response.status === 204) { | |
128 | + return response.text(); | |
129 | + } | |
130 | + return response.json(); | |
131 | + }) | |
132 | + .catch(e => { | |
133 | + const status = e.name; | |
134 | + if (status === 401) { | |
135 | + // @HACK | |
136 | + /* eslint-disable no-underscore-dangle */ | |
137 | + window.g_app._store.dispatch({ | |
138 | + type: 'login/logout', | |
139 | + }); | |
140 | + return; | |
141 | + } | |
142 | + // environment should not be used | |
143 | + if (status === 403) { | |
144 | + router.push('/exception/403'); | |
145 | + return; | |
146 | + } | |
147 | + if (status <= 504 && status >= 500) { | |
148 | + router.push('/exception/500'); | |
149 | + return; | |
150 | + } | |
151 | + if (status >= 404 && status < 422) { | |
152 | + router.push('/exception/404'); | |
153 | + } | |
154 | + }); | |
155 | +} | ... | ... |
ant-design-pro/Monitor/@/utils/utils.js
0 → 100644
1 | +import moment from 'moment'; | |
2 | +import React from 'react'; | |
3 | +import nzh from 'nzh/cn'; | |
4 | +import { parse, stringify } from 'qs'; | |
5 | + | |
6 | +export function fixedZero(val) { | |
7 | + return val * 1 < 10 ? `0${val}` : val; | |
8 | +} | |
9 | + | |
10 | +export function getTimeDistance(type) { | |
11 | + const now = new Date(); | |
12 | + const oneDay = 1000 * 60 * 60 * 24; | |
13 | + | |
14 | + if (type === 'today') { | |
15 | + now.setHours(0); | |
16 | + now.setMinutes(0); | |
17 | + now.setSeconds(0); | |
18 | + return [moment(now), moment(now.getTime() + (oneDay - 1000))]; | |
19 | + } | |
20 | + | |
21 | + if (type === 'week') { | |
22 | + let day = now.getDay(); | |
23 | + now.setHours(0); | |
24 | + now.setMinutes(0); | |
25 | + now.setSeconds(0); | |
26 | + | |
27 | + if (day === 0) { | |
28 | + day = 6; | |
29 | + } else { | |
30 | + day -= 1; | |
31 | + } | |
32 | + | |
33 | + const beginTime = now.getTime() - day * oneDay; | |
34 | + | |
35 | + return [moment(beginTime), moment(beginTime + (7 * oneDay - 1000))]; | |
36 | + } | |
37 | + | |
38 | + if (type === 'month') { | |
39 | + const year = now.getFullYear(); | |
40 | + const month = now.getMonth(); | |
41 | + const nextDate = moment(now).add(1, 'months'); | |
42 | + const nextYear = nextDate.year(); | |
43 | + const nextMonth = nextDate.month(); | |
44 | + | |
45 | + return [ | |
46 | + moment(`${year}-${fixedZero(month + 1)}-01 00:00:00`), | |
47 | + moment(moment(`${nextYear}-${fixedZero(nextMonth + 1)}-01 00:00:00`).valueOf() - 1000), | |
48 | + ]; | |
49 | + } | |
50 | + | |
51 | + const year = now.getFullYear(); | |
52 | + return [moment(`${year}-01-01 00:00:00`), moment(`${year}-12-31 23:59:59`)]; | |
53 | +} | |
54 | + | |
55 | +export function getPlainNode(nodeList, parentPath = '') { | |
56 | + const arr = []; | |
57 | + nodeList.forEach(node => { | |
58 | + const item = node; | |
59 | + item.path = `${parentPath}/${item.path || ''}`.replace(/\/+/g, '/'); | |
60 | + item.exact = true; | |
61 | + if (item.children && !item.component) { | |
62 | + arr.push(...getPlainNode(item.children, item.path)); | |
63 | + } else { | |
64 | + if (item.children && item.component) { | |
65 | + item.exact = false; | |
66 | + } | |
67 | + arr.push(item); | |
68 | + } | |
69 | + }); | |
70 | + return arr; | |
71 | +} | |
72 | + | |
73 | +export function digitUppercase(n) { | |
74 | + return nzh.toMoney(n); | |
75 | +} | |
76 | + | |
77 | +function getRelation(str1, str2) { | |
78 | + if (str1 === str2) { | |
79 | + console.warn('Two path are equal!'); // eslint-disable-line | |
80 | + } | |
81 | + const arr1 = str1.split('/'); | |
82 | + const arr2 = str2.split('/'); | |
83 | + if (arr2.every((item, index) => item === arr1[index])) { | |
84 | + return 1; | |
85 | + } | |
86 | + if (arr1.every((item, index) => item === arr2[index])) { | |
87 | + return 2; | |
88 | + } | |
89 | + return 3; | |
90 | +} | |
91 | + | |
92 | +function getRenderArr(routes) { | |
93 | + let renderArr = []; | |
94 | + renderArr.push(routes[0]); | |
95 | + for (let i = 1; i < routes.length; i += 1) { | |
96 | + // 去重 | |
97 | + renderArr = renderArr.filter(item => getRelation(item, routes[i]) !== 1); | |
98 | + // 是否包含 | |
99 | + const isAdd = renderArr.every(item => getRelation(item, routes[i]) === 3); | |
100 | + if (isAdd) { | |
101 | + renderArr.push(routes[i]); | |
102 | + } | |
103 | + } | |
104 | + return renderArr; | |
105 | +} | |
106 | + | |
107 | +/** | |
108 | + * Get router routing configuration | |
109 | + * { path:{name,...param}}=>Array<{name,path ...param}> | |
110 | + * @param {string} path | |
111 | + * @param {routerData} routerData | |
112 | + */ | |
113 | +export function getRoutes(path, routerData) { | |
114 | + let routes = Object.keys(routerData).filter( | |
115 | + routePath => routePath.indexOf(path) === 0 && routePath !== path | |
116 | + ); | |
117 | + // Replace path to '' eg. path='user' /user/name => name | |
118 | + routes = routes.map(item => item.replace(path, '')); | |
119 | + // Get the route to be rendered to remove the deep rendering | |
120 | + const renderArr = getRenderArr(routes); | |
121 | + // Conversion and stitching parameters | |
122 | + const renderRoutes = renderArr.map(item => { | |
123 | + const exact = !routes.some(route => route !== item && getRelation(route, item) === 1); | |
124 | + return { | |
125 | + exact, | |
126 | + ...routerData[`${path}${item}`], | |
127 | + key: `${path}${item}`, | |
128 | + path: `${path}${item}`, | |
129 | + }; | |
130 | + }); | |
131 | + return renderRoutes; | |
132 | +} | |
133 | + | |
134 | +export function getPageQuery() { | |
135 | + return parse(window.location.href.split('?')[1]); | |
136 | +} | |
137 | + | |
138 | +export function getQueryPath(path = '', query = {}) { | |
139 | + const search = stringify(query); | |
140 | + if (search.length) { | |
141 | + return `${path}?${search}`; | |
142 | + } | |
143 | + return path; | |
144 | +} | |
145 | + | |
146 | +/* eslint no-useless-escape:0 */ | |
147 | +const reg = /(((^https?:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+(?::\d+)?|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)$/; | |
148 | + | |
149 | +export function isUrl(path) { | |
150 | + return reg.test(path); | |
151 | +} | |
152 | + | |
153 | +export function formatWan(val) { | |
154 | + const v = val * 1; | |
155 | + if (!v || Number.isNaN(v)) return ''; | |
156 | + | |
157 | + let result = val; | |
158 | + if (val > 10000) { | |
159 | + result = Math.floor(val / 10000); | |
160 | + result = ( | |
161 | + <span> | |
162 | + {result} | |
163 | + <span | |
164 | + style={{ | |
165 | + position: 'relative', | |
166 | + top: -2, | |
167 | + fontSize: 14, | |
168 | + fontStyle: 'normal', | |
169 | + marginLeft: 2, | |
170 | + }} | |
171 | + > | |
172 | + 万 | |
173 | + </span> | |
174 | + </span> | |
175 | + ); | |
176 | + } | |
177 | + return result; | |
178 | +} | |
179 | + | |
180 | +// 给官方演示站点用,用于关闭真实开发环境不需要使用的特性 | |
181 | +export function isAntdPro() { | |
182 | + return window.location.hostname === 'preview.pro.ant.design'; | |
183 | +} | ... | ... |
ant-design-pro/Monitor/@/utils/utils.less
0 → 100644
1 | +.textOverflow() { | |
2 | + overflow: hidden; | |
3 | + text-overflow: ellipsis; | |
4 | + word-break: break-all; | |
5 | + white-space: nowrap; | |
6 | +} | |
7 | + | |
8 | +.textOverflowMulti(@line: 3, @bg: #fff) { | |
9 | + overflow: hidden; | |
10 | + position: relative; | |
11 | + line-height: 1.5em; | |
12 | + max-height: @line * 1.5em; | |
13 | + text-align: justify; | |
14 | + margin-right: -1em; | |
15 | + padding-right: 1em; | |
16 | + &:before { | |
17 | + background: @bg; | |
18 | + content: '...'; | |
19 | + padding: 0 1px; | |
20 | + position: absolute; | |
21 | + right: 14px; | |
22 | + bottom: 0; | |
23 | + } | |
24 | + &:after { | |
25 | + background: white; | |
26 | + content: ''; | |
27 | + margin-top: 0.2em; | |
28 | + position: absolute; | |
29 | + right: 14px; | |
30 | + width: 1em; | |
31 | + height: 1em; | |
32 | + } | |
33 | +} | |
34 | + | |
35 | +// mixins for clearfix | |
36 | +// ------------------------ | |
37 | +.clearfix() { | |
38 | + zoom: 1; | |
39 | + &:before, | |
40 | + &:after { | |
41 | + content: ' '; | |
42 | + display: table; | |
43 | + } | |
44 | + &:after { | |
45 | + clear: both; | |
46 | + visibility: hidden; | |
47 | + font-size: 0; | |
48 | + height: 0; | |
49 | + } | |
50 | +} | ... | ... |
ant-design-pro/Monitor/README.md
0 → 100644
ant-design-pro/Monitor/package.json
0 → 100644
1 | +{ | |
2 | + "name": "@umi-block/monitor", | |
3 | + "version": "0.0.1", | |
4 | + "description": "Monitor", | |
5 | + "main": "src/index.js", | |
6 | + "scripts": { | |
7 | + "dev": "umi dev" | |
8 | + }, | |
9 | + "repository": { | |
10 | + "type": "git", | |
11 | + "url": "https://github.com/umijs/umi-blocks/monitor" | |
12 | + }, | |
13 | + "dependencies": { | |
14 | + "react": "^16.6.3", | |
15 | + "dva": "^2.4.0", | |
16 | + "antd": "^3.10.9", | |
17 | + "ant-design-pro": "^2.1.1", | |
18 | + "numeral": "^2.0.6", | |
19 | + "qs": "^6.6.0", | |
20 | + "hash.js": "^1.1.5", | |
21 | + "moment": "^2.22.2", | |
22 | + "nzh": "^1.0.3" | |
23 | + }, | |
24 | + "devDependencies": { | |
25 | + "umi": "^2.3.0-beta.1", | |
26 | + "umi-plugin-react": "^1.3.0-beta.1", | |
27 | + "umi-plugin-block-dev": "^1.0.0" | |
28 | + }, | |
29 | + "license": "ISC" | |
30 | +} | ... | ... |
ant-design-pro/Monitor/src/Monitor.less
0 → 100644
1 | +@import '~antd/lib/style/themes/default.less'; | |
2 | +@import '~@/utils/utils.less'; | |
3 | + | |
4 | +.mapChart { | |
5 | + padding-top: 24px; | |
6 | + height: 452px; | |
7 | + text-align: center; | |
8 | + img { | |
9 | + display: inline-block; | |
10 | + max-width: 100%; | |
11 | + max-height: 437px; | |
12 | + } | |
13 | +} | |
14 | + | |
15 | +.pieCard :global(.pie-stat) { | |
16 | + font-size: 24px !important; | |
17 | +} | |
18 | + | |
19 | +@media screen and (max-width: @screen-lg) { | |
20 | + .mapChart { | |
21 | + height: auto; | |
22 | + } | |
23 | +} | ... | ... |
ant-design-pro/Monitor/src/_mock.js
0 → 100644
1 | +import moment from 'moment'; | |
2 | + | |
3 | +// mock data | |
4 | +const visitData = []; | |
5 | +const beginDay = new Date().getTime(); | |
6 | + | |
7 | +const fakeY = [7, 5, 4, 2, 4, 7, 5, 6, 5, 9, 6, 3, 1, 5, 3, 6, 5]; | |
8 | +for (let i = 0; i < fakeY.length; i += 1) { | |
9 | + visitData.push({ | |
10 | + x: moment(new Date(beginDay + 1000 * 60 * 60 * 24 * i)).format('YYYY-MM-DD'), | |
11 | + y: fakeY[i], | |
12 | + }); | |
13 | +} | |
14 | + | |
15 | +const visitData2 = []; | |
16 | +const fakeY2 = [1, 6, 4, 8, 3, 7, 2]; | |
17 | +for (let i = 0; i < fakeY2.length; i += 1) { | |
18 | + visitData2.push({ | |
19 | + x: moment(new Date(beginDay + 1000 * 60 * 60 * 24 * i)).format('YYYY-MM-DD'), | |
20 | + y: fakeY2[i], | |
21 | + }); | |
22 | +} | |
23 | + | |
24 | +const salesData = []; | |
25 | +for (let i = 0; i < 12; i += 1) { | |
26 | + salesData.push({ | |
27 | + x: `${i + 1}月`, | |
28 | + y: Math.floor(Math.random() * 1000) + 200, | |
29 | + }); | |
30 | +} | |
31 | +const searchData = []; | |
32 | +for (let i = 0; i < 50; i += 1) { | |
33 | + searchData.push({ | |
34 | + index: i + 1, | |
35 | + keyword: `搜索关键词-${i}`, | |
36 | + count: Math.floor(Math.random() * 1000), | |
37 | + range: Math.floor(Math.random() * 100), | |
38 | + status: Math.floor((Math.random() * 10) % 2), | |
39 | + }); | |
40 | +} | |
41 | +const salesTypeData = [ | |
42 | + { | |
43 | + x: '家用电器', | |
44 | + y: 4544, | |
45 | + }, | |
46 | + { | |
47 | + x: '食用酒水', | |
48 | + y: 3321, | |
49 | + }, | |
50 | + { | |
51 | + x: '个护健康', | |
52 | + y: 3113, | |
53 | + }, | |
54 | + { | |
55 | + x: '服饰箱包', | |
56 | + y: 2341, | |
57 | + }, | |
58 | + { | |
59 | + x: '母婴产品', | |
60 | + y: 1231, | |
61 | + }, | |
62 | + { | |
63 | + x: '其他', | |
64 | + y: 1231, | |
65 | + }, | |
66 | +]; | |
67 | + | |
68 | +const salesTypeDataOnline = [ | |
69 | + { | |
70 | + x: '家用电器', | |
71 | + y: 244, | |
72 | + }, | |
73 | + { | |
74 | + x: '食用酒水', | |
75 | + y: 321, | |
76 | + }, | |
77 | + { | |
78 | + x: '个护健康', | |
79 | + y: 311, | |
80 | + }, | |
81 | + { | |
82 | + x: '服饰箱包', | |
83 | + y: 41, | |
84 | + }, | |
85 | + { | |
86 | + x: '母婴产品', | |
87 | + y: 121, | |
88 | + }, | |
89 | + { | |
90 | + x: '其他', | |
91 | + y: 111, | |
92 | + }, | |
93 | +]; | |
94 | + | |
95 | +const salesTypeDataOffline = [ | |
96 | + { | |
97 | + x: '家用电器', | |
98 | + y: 99, | |
99 | + }, | |
100 | + { | |
101 | + x: '食用酒水', | |
102 | + y: 188, | |
103 | + }, | |
104 | + { | |
105 | + x: '个护健康', | |
106 | + y: 344, | |
107 | + }, | |
108 | + { | |
109 | + x: '服饰箱包', | |
110 | + y: 255, | |
111 | + }, | |
112 | + { | |
113 | + x: '其他', | |
114 | + y: 65, | |
115 | + }, | |
116 | +]; | |
117 | + | |
118 | +const offlineData = []; | |
119 | +for (let i = 0; i < 10; i += 1) { | |
120 | + offlineData.push({ | |
121 | + name: `Stores ${i}`, | |
122 | + cvr: Math.ceil(Math.random() * 9) / 10, | |
123 | + }); | |
124 | +} | |
125 | +const offlineChartData = []; | |
126 | +for (let i = 0; i < 20; i += 1) { | |
127 | + offlineChartData.push({ | |
128 | + x: new Date().getTime() + 1000 * 60 * 30 * i, | |
129 | + y1: Math.floor(Math.random() * 100) + 10, | |
130 | + y2: Math.floor(Math.random() * 100) + 10, | |
131 | + }); | |
132 | +} | |
133 | + | |
134 | +const radarOriginData = [ | |
135 | + { | |
136 | + name: '个人', | |
137 | + ref: 10, | |
138 | + koubei: 8, | |
139 | + output: 4, | |
140 | + contribute: 5, | |
141 | + hot: 7, | |
142 | + }, | |
143 | + { | |
144 | + name: '团队', | |
145 | + ref: 3, | |
146 | + koubei: 9, | |
147 | + output: 6, | |
148 | + contribute: 3, | |
149 | + hot: 1, | |
150 | + }, | |
151 | + { | |
152 | + name: '部门', | |
153 | + ref: 4, | |
154 | + koubei: 1, | |
155 | + output: 6, | |
156 | + contribute: 5, | |
157 | + hot: 7, | |
158 | + }, | |
159 | +]; | |
160 | + | |
161 | +const radarData = []; | |
162 | +const radarTitleMap = { | |
163 | + ref: '引用', | |
164 | + koubei: '口碑', | |
165 | + output: '产量', | |
166 | + contribute: '贡献', | |
167 | + hot: '热度', | |
168 | +}; | |
169 | +radarOriginData.forEach(item => { | |
170 | + Object.keys(item).forEach(key => { | |
171 | + if (key !== 'name') { | |
172 | + radarData.push({ | |
173 | + name: item.name, | |
174 | + label: radarTitleMap[key], | |
175 | + value: item[key], | |
176 | + }); | |
177 | + } | |
178 | + }); | |
179 | +}); | |
180 | + | |
181 | +const getFakeChartData = { | |
182 | + visitData, | |
183 | + visitData2, | |
184 | + salesData, | |
185 | + searchData, | |
186 | + offlineData, | |
187 | + offlineChartData, | |
188 | + salesTypeData, | |
189 | + salesTypeDataOnline, | |
190 | + salesTypeDataOffline, | |
191 | + radarData, | |
192 | +}; | |
193 | + | |
194 | +export default { | |
195 | + 'GET /api/fake_chart_data': getFakeChartData, | |
196 | +}; | ... | ... |
1 | +module.exports = { | |
2 | + navTheme: 'dark', // theme for nav menu | |
3 | + primaryColor: '#1890FF', // primary color of ant design | |
4 | + layout: 'sidemenu', // nav menu position: sidemenu or topmenu | |
5 | + contentWidth: 'Fluid', // layout of content: Fluid or Fixed, only works when layout is topmenu | |
6 | + fixedHeader: false, // sticky header | |
7 | + autoHideHeader: false, // auto hide header | |
8 | + fixSiderbar: false, // sticky siderbar | |
9 | +}; | ... | ... |
ant-design-pro/Monitor/src/index.js
0 → 100644
1 | +import React, { PureComponent } from 'react'; | |
2 | +import { connect } from 'dva'; | |
3 | +import { formatMessage, FormattedMessage } from 'umi/locale'; | |
4 | +import { Row, Col, Card, Tooltip } from 'antd'; | |
5 | +import { Pie, WaterWave, Gauge, TagCloud } from 'ant-design-pro/lib/Charts'; | |
6 | +import NumberInfo from 'ant-design-pro/lib/NumberInfo'; | |
7 | +import CountDown from 'ant-design-pro/lib/CountDown'; | |
8 | +import ActiveChart from '@/components/ActiveChart'; | |
9 | +import numeral from 'numeral'; | |
10 | +import GridContent from '@/components/PageHeaderWrapper/GridContent'; | |
11 | + | |
12 | +import Authorized from '@/utils/Authorized'; | |
13 | +import styles from './Monitor.less'; | |
14 | + | |
15 | +const { Secured } = Authorized; | |
16 | + | |
17 | +const targetTime = new Date().getTime() + 3900000; | |
18 | + | |
19 | +// use permission as a parameter | |
20 | +const havePermissionAsync = new Promise(resolve => { | |
21 | + // Call resolve on behalf of passed | |
22 | + setTimeout(() => resolve(), 300); | |
23 | +}); | |
24 | + | |
25 | +@Secured(havePermissionAsync) | |
26 | +@connect(({ monitor, loading }) => ({ | |
27 | + monitor, | |
28 | + loading: loading.models.monitor, | |
29 | +})) | |
30 | +class Monitor extends PureComponent { | |
31 | + componentDidMount() { | |
32 | + const { dispatch } = this.props; | |
33 | + dispatch({ | |
34 | + type: 'monitor/fetchTags', | |
35 | + }); | |
36 | + } | |
37 | + | |
38 | + render() { | |
39 | + const { monitor, loading } = this.props; | |
40 | + const { tags } = monitor; | |
41 | + | |
42 | + return ( | |
43 | + <GridContent> | |
44 | + <Row gutter={24}> | |
45 | + <Col xl={18} lg={24} md={24} sm={24} xs={24} style={{ marginBottom: 24 }}> | |
46 | + <Card | |
47 | + title={ | |
48 | + <FormattedMessage | |
49 | + id="app.monitor.trading-activity" | |
50 | + defaultMessage="Real-Time Trading Activity" | |
51 | + /> | |
52 | + } | |
53 | + bordered={false} | |
54 | + > | |
55 | + <Row> | |
56 | + <Col md={6} sm={12} xs={24}> | |
57 | + <NumberInfo | |
58 | + subTitle={ | |
59 | + <FormattedMessage | |
60 | + id="app.monitor.total-transactions" | |
61 | + defaultMessage="Total transactions today" | |
62 | + /> | |
63 | + } | |
64 | + suffix="元" | |
65 | + total={numeral(124543233).format('0,0')} | |
66 | + /> | |
67 | + </Col> | |
68 | + <Col md={6} sm={12} xs={24}> | |
69 | + <NumberInfo | |
70 | + subTitle={ | |
71 | + <FormattedMessage | |
72 | + id="app.monitor.sales-target" | |
73 | + defaultMessage="Sales target completion rate" | |
74 | + /> | |
75 | + } | |
76 | + total="92%" | |
77 | + /> | |
78 | + </Col> | |
79 | + <Col md={6} sm={12} xs={24}> | |
80 | + <NumberInfo | |
81 | + subTitle={ | |
82 | + <FormattedMessage | |
83 | + id="app.monitor.remaining-time" | |
84 | + defaultMessage="Remaining time of activity" | |
85 | + /> | |
86 | + } | |
87 | + total={<CountDown target={targetTime} />} | |
88 | + /> | |
89 | + </Col> | |
90 | + <Col md={6} sm={12} xs={24}> | |
91 | + <NumberInfo | |
92 | + subTitle={ | |
93 | + <FormattedMessage | |
94 | + id="app.monitor.total-transactions-per-second" | |
95 | + defaultMessage="Total transactions per second" | |
96 | + /> | |
97 | + } | |
98 | + suffix="元" | |
99 | + total={numeral(234).format('0,0')} | |
100 | + /> | |
101 | + </Col> | |
102 | + </Row> | |
103 | + <div className={styles.mapChart}> | |
104 | + <Tooltip | |
105 | + title={ | |
106 | + <FormattedMessage | |
107 | + id="app.monitor.waiting-for-implementation" | |
108 | + defaultMessage="Waiting for implementation" | |
109 | + /> | |
110 | + } | |
111 | + > | |
112 | + <img | |
113 | + src="https://gw.alipayobjects.com/zos/rmsportal/HBWnDEUXCnGnGrRfrpKa.png" | |
114 | + alt="map" | |
115 | + /> | |
116 | + </Tooltip> | |
117 | + </div> | |
118 | + </Card> | |
119 | + </Col> | |
120 | + <Col xl={6} lg={24} md={24} sm={24} xs={24}> | |
121 | + <Card | |
122 | + title={ | |
123 | + <FormattedMessage | |
124 | + id="app.monitor.activity-forecast" | |
125 | + defaultMessage="Activity forecast" | |
126 | + /> | |
127 | + } | |
128 | + style={{ marginBottom: 24 }} | |
129 | + bordered={false} | |
130 | + > | |
131 | + <ActiveChart /> | |
132 | + </Card> | |
133 | + <Card | |
134 | + title={<FormattedMessage id="app.monitor.efficiency" defaultMessage="Efficiency" />} | |
135 | + style={{ marginBottom: 24 }} | |
136 | + bodyStyle={{ textAlign: 'center' }} | |
137 | + bordered={false} | |
138 | + > | |
139 | + <Gauge | |
140 | + title={formatMessage({ id: 'app.monitor.ratio', defaultMessage: 'Ratio' })} | |
141 | + height={180} | |
142 | + percent={87} | |
143 | + /> | |
144 | + </Card> | |
145 | + </Col> | |
146 | + </Row> | |
147 | + <Row gutter={24}> | |
148 | + <Col xl={12} lg={24} sm={24} xs={24} style={{ marginBottom: 24 }}> | |
149 | + <Card | |
150 | + title={ | |
151 | + <FormattedMessage | |
152 | + id="app.monitor.proportion-per-category" | |
153 | + defaultMessage="Proportion Per Category" | |
154 | + /> | |
155 | + } | |
156 | + bordered={false} | |
157 | + className={styles.pieCard} | |
158 | + > | |
159 | + <Row style={{ padding: '16px 0' }}> | |
160 | + <Col span={8}> | |
161 | + <Pie | |
162 | + animate={false} | |
163 | + percent={28} | |
164 | + subTitle={ | |
165 | + <FormattedMessage id="app.monitor.fast-food" defaultMessage="Fast food" /> | |
166 | + } | |
167 | + total="28%" | |
168 | + height={128} | |
169 | + lineWidth={2} | |
170 | + /> | |
171 | + </Col> | |
172 | + <Col span={8}> | |
173 | + <Pie | |
174 | + animate={false} | |
175 | + color="#5DDECF" | |
176 | + percent={22} | |
177 | + subTitle={ | |
178 | + <FormattedMessage | |
179 | + id="app.monitor.western-food" | |
180 | + defaultMessage="Western food" | |
181 | + /> | |
182 | + } | |
183 | + total="22%" | |
184 | + height={128} | |
185 | + lineWidth={2} | |
186 | + /> | |
187 | + </Col> | |
188 | + <Col span={8}> | |
189 | + <Pie | |
190 | + animate={false} | |
191 | + color="#2FC25B" | |
192 | + percent={32} | |
193 | + subTitle={ | |
194 | + <FormattedMessage id="app.monitor.hot-pot" defaultMessage="Hot pot" /> | |
195 | + } | |
196 | + total="32%" | |
197 | + height={128} | |
198 | + lineWidth={2} | |
199 | + /> | |
200 | + </Col> | |
201 | + </Row> | |
202 | + </Card> | |
203 | + </Col> | |
204 | + <Col xl={6} lg={12} sm={24} xs={24} style={{ marginBottom: 24 }}> | |
205 | + <Card | |
206 | + title={ | |
207 | + <FormattedMessage | |
208 | + id="app.monitor.popular-searches" | |
209 | + defaultMessage="Popular Searches" | |
210 | + /> | |
211 | + } | |
212 | + loading={loading} | |
213 | + bordered={false} | |
214 | + bodyStyle={{ overflow: 'hidden' }} | |
215 | + > | |
216 | + <TagCloud data={tags} height={161} /> | |
217 | + </Card> | |
218 | + </Col> | |
219 | + <Col xl={6} lg={12} sm={24} xs={24} style={{ marginBottom: 24 }}> | |
220 | + <Card | |
221 | + title={ | |
222 | + <FormattedMessage | |
223 | + id="app.monitor.resource-surplus" | |
224 | + defaultMessage="Resource Surplus" | |
225 | + /> | |
226 | + } | |
227 | + bodyStyle={{ textAlign: 'center', fontSize: 0 }} | |
228 | + bordered={false} | |
229 | + > | |
230 | + <WaterWave | |
231 | + height={161} | |
232 | + title={ | |
233 | + <FormattedMessage id="app.monitor.fund-surplus" defaultMessage="Fund Surplus" /> | |
234 | + } | |
235 | + percent={34} | |
236 | + /> | |
237 | + </Card> | |
238 | + </Col> | |
239 | + </Row> | |
240 | + </GridContent> | |
241 | + ); | |
242 | + } | |
243 | +} | |
244 | + | |
245 | +export default Monitor; | ... | ... |
ant-design-pro/Monitor/src/models/monitor.js
0 → 100644
1 | +import { queryTags } from '@/services/api'; | |
2 | + | |
3 | +export default { | |
4 | + namespace: 'monitor', | |
5 | + | |
6 | + state: { | |
7 | + tags: [], | |
8 | + }, | |
9 | + | |
10 | + effects: { | |
11 | + *fetchTags(_, { call, put }) { | |
12 | + const response = yield call(queryTags); | |
13 | + yield put({ | |
14 | + type: 'saveTags', | |
15 | + payload: response.list, | |
16 | + }); | |
17 | + }, | |
18 | + }, | |
19 | + | |
20 | + reducers: { | |
21 | + saveTags(state, action) { | |
22 | + return { | |
23 | + ...state, | |
24 | + tags: action.payload, | |
25 | + }; | |
26 | + }, | |
27 | + }, | |
28 | +}; | ... | ... |
ant-design-pro/Monitor/src/models/setting.js
0 → 100644
1 | +import { message } from 'antd'; | |
2 | +import defaultSettings from '../defaultSettings'; | |
3 | + | |
4 | +let lessNodesAppended; | |
5 | +const updateTheme = primaryColor => { | |
6 | + // Don't compile less in production! | |
7 | + if (APP_TYPE !== 'site') { | |
8 | + return; | |
9 | + } | |
10 | + // Determine if the component is remounted | |
11 | + if (!primaryColor) { | |
12 | + return; | |
13 | + } | |
14 | + const hideMessage = message.loading('正在编译主题!', 0); | |
15 | + function buildIt() { | |
16 | + if (!window.less) { | |
17 | + return; | |
18 | + } | |
19 | + setTimeout(() => { | |
20 | + window.less | |
21 | + .modifyVars({ | |
22 | + '@primary-color': primaryColor, | |
23 | + }) | |
24 | + .then(() => { | |
25 | + hideMessage(); | |
26 | + }) | |
27 | + .catch(() => { | |
28 | + message.error('Failed to update theme'); | |
29 | + hideMessage(); | |
30 | + }); | |
31 | + }, 200); | |
32 | + } | |
33 | + if (!lessNodesAppended) { | |
34 | + // insert less.js and color.less | |
35 | + const lessStyleNode = document.createElement('link'); | |
36 | + const lessConfigNode = document.createElement('script'); | |
37 | + const lessScriptNode = document.createElement('script'); | |
38 | + lessStyleNode.setAttribute('rel', 'stylesheet/less'); | |
39 | + lessStyleNode.setAttribute('href', '/color.less'); | |
40 | + lessConfigNode.innerHTML = ` | |
41 | + window.less = { | |
42 | + async: true, | |
43 | + env: 'production', | |
44 | + javascriptEnabled: true | |
45 | + }; | |
46 | + `; | |
47 | + lessScriptNode.src = 'https://gw.alipayobjects.com/os/lib/less.js/3.8.1/less.min.js'; | |
48 | + lessScriptNode.async = true; | |
49 | + lessScriptNode.onload = () => { | |
50 | + buildIt(); | |
51 | + lessScriptNode.onload = null; | |
52 | + }; | |
53 | + document.body.appendChild(lessStyleNode); | |
54 | + document.body.appendChild(lessConfigNode); | |
55 | + document.body.appendChild(lessScriptNode); | |
56 | + lessNodesAppended = true; | |
57 | + } else { | |
58 | + buildIt(); | |
59 | + } | |
60 | +}; | |
61 | + | |
62 | +const updateColorWeak = colorWeak => { | |
63 | + document.body.className = colorWeak ? 'colorWeak' : ''; | |
64 | +}; | |
65 | + | |
66 | +export default { | |
67 | + namespace: 'setting', | |
68 | + state: defaultSettings, | |
69 | + reducers: { | |
70 | + getSetting(state) { | |
71 | + const setting = {}; | |
72 | + const urlParams = new URL(window.location.href); | |
73 | + Object.keys(state).forEach(key => { | |
74 | + if (urlParams.searchParams.has(key)) { | |
75 | + const value = urlParams.searchParams.get(key); | |
76 | + setting[key] = value === '1' ? true : value; | |
77 | + } | |
78 | + }); | |
79 | + const { primaryColor, colorWeak } = setting; | |
80 | + if (state.primaryColor !== primaryColor) { | |
81 | + updateTheme(primaryColor); | |
82 | + } | |
83 | + updateColorWeak(colorWeak); | |
84 | + return { | |
85 | + ...state, | |
86 | + ...setting, | |
87 | + }; | |
88 | + }, | |
89 | + changeSetting(state, { payload }) { | |
90 | + const urlParams = new URL(window.location.href); | |
91 | + Object.keys(defaultSettings).forEach(key => { | |
92 | + if (urlParams.searchParams.has(key)) { | |
93 | + urlParams.searchParams.delete(key); | |
94 | + } | |
95 | + }); | |
96 | + Object.keys(payload).forEach(key => { | |
97 | + if (key === 'collapse') { | |
98 | + return; | |
99 | + } | |
100 | + let value = payload[key]; | |
101 | + if (value === true) { | |
102 | + value = 1; | |
103 | + } | |
104 | + if (defaultSettings[key] !== value) { | |
105 | + urlParams.searchParams.set(key, value); | |
106 | + } | |
107 | + }); | |
108 | + const { primaryColor, colorWeak, contentWidth } = payload; | |
109 | + if (state.primaryColor !== primaryColor) { | |
110 | + updateTheme(primaryColor); | |
111 | + } | |
112 | + if (state.contentWidth !== contentWidth && window.dispatchEvent) { | |
113 | + window.dispatchEvent(new Event('resize')); | |
114 | + } | |
115 | + updateColorWeak(colorWeak); | |
116 | + window.history.replaceState(null, 'setting', urlParams.href); | |
117 | + return { | |
118 | + ...state, | |
119 | + ...payload, | |
120 | + }; | |
121 | + }, | |
122 | + }, | |
123 | +}; | ... | ... |
请
注册
或
登录
后发表评论