Commit 0af2f0177c4baeec5c72ff08eba3c5b7a55ebd89
Merge branch 'ww' into 'main'
feat: according device select page size See merge request huang/thingskit-drawio!33
Showing
6 changed files
with
150 additions
and
27 deletions
... | ... | @@ -14,7 +14,7 @@ const GLOBAL_TOKEN = (() => { |
14 | 14 | const common = ls.get(GLOBAL_STORAGE_KEY) |
15 | 15 | return { |
16 | 16 | token: common && common.JWT_TOKEN && common.JWT_TOKEN.value, |
17 | - refreshToken: common && common.JWT_TOKEN && common.JWT_TOKEN.value, | |
17 | + refreshToken: common && common.REFRESH_TOKEN && common.REFRESH_TOKEN.value, | |
18 | 18 | } |
19 | 19 | })() |
20 | 20 | ... | ... |
... | ... | @@ -56,7 +56,7 @@ const createStorage = ( |
56 | 56 | timeout = null, |
57 | 57 | hasEncrypt = !isDEV, |
58 | 58 | } = {}) => { |
59 | - if (hasEncrypt && [ key.length, iv.length ].some((item) => item !== 16)) { | |
59 | + if (hasEncrypt && [key.length, iv.length].some((item) => item !== 16)) { | |
60 | 60 | throw new Error('When hasEncrypt is true, the key or iv must be 16 bits!'); |
61 | 61 | } |
62 | 62 | |
... | ... | @@ -86,7 +86,7 @@ const createStorage = ( |
86 | 86 | } |
87 | 87 | |
88 | 88 | getKey(key) { |
89 | - return `${ this.prefixKey }${ key }`.toUpperCase(); | |
89 | + return `${this.prefixKey}${key}`.toUpperCase(); | |
90 | 90 | } |
91 | 91 | |
92 | 92 | /** |
... | ... | @@ -110,6 +110,19 @@ const createStorage = ( |
110 | 110 | this.storage.setItem(this.getKey(key), stringifyValue); |
111 | 111 | } |
112 | 112 | |
113 | + generatorValue(key, value, expire = timeout) { | |
114 | + const stringData = { | |
115 | + value, | |
116 | + time: Date.now(), | |
117 | + expire: !isNullOrUnDef(expire) ? new Date().getTime() + expire * 1000 : null, | |
118 | + }; | |
119 | + const stringifyValue = this.hasEncrypt | |
120 | + ? this.encryption.encryptByAES(stringData) | |
121 | + : stringData; | |
122 | + | |
123 | + return stringifyValue | |
124 | + } | |
125 | + | |
113 | 126 | /** |
114 | 127 | *Read cache |
115 | 128 | * @param {string} key |
... | ... | @@ -117,17 +130,20 @@ const createStorage = ( |
117 | 130 | * @memberof Cache |
118 | 131 | */ |
119 | 132 | get(key, def = null) { |
133 | + console.log(this.getKey(key)) | |
120 | 134 | const val = this.storage.getItem(this.getKey(key)); |
121 | 135 | if (!val) return def; |
122 | 136 | |
123 | 137 | try { |
124 | 138 | const decVal = this.hasEncrypt ? this.encryption.decryptByAES(val) : val; |
125 | 139 | const data = JSON.parse(decVal); |
140 | + console.log(data) | |
126 | 141 | const { value, expire } = data; |
127 | - if (isNullOrUnDef(expire) || expire >= new Date().getTime()) { | |
128 | - return value; | |
129 | - } | |
130 | - this.remove(key); | |
142 | + // if (isNullOrUnDef(expire) || expire >= new Date().getTime()) { | |
143 | + // return value; | |
144 | + // } | |
145 | + return value | |
146 | + // this.remove(key); | |
131 | 147 | } catch (e) { |
132 | 148 | return def; |
133 | 149 | } |
... | ... | @@ -150,4 +166,4 @@ const createStorage = ( |
150 | 166 | } |
151 | 167 | }; |
152 | 168 | return new WebStorage(); |
153 | -} | |
\ No newline at end of file | ||
169 | +} | ... | ... |
... | ... | @@ -5027,6 +5027,31 @@ App.prototype.loadFile = function (id, sameWindow, file, success, force) { |
5027 | 5027 | function getSaveContent() { |
5028 | 5028 | defHttp.get('/yt/configuration/center/getConfigurationInfo/'+Editor.configurationId) |
5029 | 5029 | .then(function (response) { |
5030 | + console.log({response}) | |
5031 | + const { configurationContentList: [ data = {}] = [] } = response || {} | |
5032 | + const phoneFlag = data.platform | |
5033 | + const pageSizeControl = PageSetupDialog.getFormats | |
5034 | + PageSetupDialog.getFormats = function () { | |
5035 | + if (phoneFlag === 'phone') { | |
5036 | + return [ | |
5037 | + {key: 'iPhone 8', title: 'iPhone 8', format: new mxRectangle(0, 0, 375, 667)}, | |
5038 | + {key: 'iPhone 8 Plus', title: 'iPhone 8 Plus', format: new mxRectangle(0, 0, 415, 737)}, | |
5039 | + {key: 'iPhone X/XS', title: 'iPhone X/XS', format: new mxRectangle(0, 0, 376, 813)}, | |
5040 | + {key: 'iPhone XR/XS Max', title: 'iPhone XR/XS Max', format: new mxRectangle(0, 0, 415, 897)}, | |
5041 | + {key: 'iPad 4', title: 'iPad 4', format: new mxRectangle(0, 0, 709, 1025)}, | |
5042 | + {key: 'Galaxy S9', title: 'Galaxy S9', format: new mxRectangle(0, 0, 361, 741)}, | |
5043 | + {key: 'Galaxy S10E', title: 'Galaxy S10E', format: new mxRectangle(0, 0, 361, 741)}, | |
5044 | + {key: 'Galaxy S10E', title: 'Galaxy S10E', format: new mxRectangle(0, 0, 361, 741)}, | |
5045 | + {key: 'Galaxy S10/S10+', title: 'Galaxy S10/S10+', format: new mxRectangle(0, 0, 413, 870)}, | |
5046 | + {key: 'Pixel 2', title: 'Pixel 2', format: new mxRectangle(0, 0, 413, 732)}, | |
5047 | + {key: 'Pixel 3', title: 'Pixel 3', format: new mxRectangle(0, 0, 413, 825)}, | |
5048 | + {key: 'Pixel 3', title: 'Pixel 3', format: new mxRectangle(0, 0, 413, 825)}, | |
5049 | + {key: 'Pixel XL', title: 'Pixel XL', format: new mxRectangle(0, 0, 413, 848)}, | |
5050 | + {key: 'custom', title: mxResources.get('custom'), format: null} | |
5051 | + ] | |
5052 | + } | |
5053 | + return pageSizeControl.apply(this, arguments) | |
5054 | + } | |
5030 | 5055 | Editor.configurationName = response.configurationName + ".drawio"; |
5031 | 5056 | if(response.configurationContentList.length > 0){ |
5032 | 5057 | response.configurationContentList.forEach((item)=>{ | ... | ... |
... | ... | @@ -2065,24 +2065,33 @@ PageSetupDialog.addPageFormatPanel = function(div, namePostfix, pageFormat, page |
2065 | 2065 | */ |
2066 | 2066 | PageSetupDialog.getFormats = function() |
2067 | 2067 | { |
2068 | - return [{key: 'letter', title: 'US-Letter (8,5" x 11")', format: mxConstants.PAGE_FORMAT_LETTER_PORTRAIT}, | |
2069 | - {key: 'legal', title: 'US-Legal (8,5" x 14")', format: new mxRectangle(0, 0, 850, 1400)}, | |
2070 | - {key: 'tabloid', title: 'US-Tabloid (11" x 17")', format: new mxRectangle(0, 0, 1100, 1700)}, | |
2071 | - {key: 'executive', title: 'US-Executive (7" x 10")', format: new mxRectangle(0, 0, 700, 1000)}, | |
2072 | - {key: 'a0', title: 'A0 (841 mm x 1189 mm)', format: new mxRectangle(0, 0, 3300, 4681)}, | |
2073 | - {key: 'a1', title: 'A1 (594 mm x 841 mm)', format: new mxRectangle(0, 0, 2339, 3300)}, | |
2074 | - {key: 'a2', title: 'A2 (420 mm x 594 mm)', format: new mxRectangle(0, 0, 1654, 2336)}, | |
2075 | - {key: 'a3', title: 'A3 (297 mm x 420 mm)', format: new mxRectangle(0, 0, 1169, 1654)}, | |
2076 | - {key: 'a4', title: 'A4 (210 mm x 297 mm)', format: mxConstants.PAGE_FORMAT_A4_PORTRAIT}, | |
2077 | - {key: 'a5', title: 'A5 (148 mm x 210 mm)', format: new mxRectangle(0, 0, 583, 827)}, | |
2078 | - {key: 'a6', title: 'A6 (105 mm x 148 mm)', format: new mxRectangle(0, 0, 413, 583)}, | |
2079 | - {key: 'a7', title: 'A7 (74 mm x 105 mm)', format: new mxRectangle(0, 0, 291, 413)}, | |
2080 | - {key: 'b4', title: 'B4 (250 mm x 353 mm)', format: new mxRectangle(0, 0, 980, 1390)}, | |
2081 | - {key: 'b5', title: 'B5 (176 mm x 250 mm)', format: new mxRectangle(0, 0, 690, 980)}, | |
2082 | - {key: '16-9', title: '16:9 (1600 x 900)', format: new mxRectangle(0, 0, 900, 1600)}, | |
2083 | - {key: '16-10', title: '16:10 (1920 x 1200)', format: new mxRectangle(0, 0, 1200, 1920)}, | |
2084 | - {key: '4-3', title: '4:3 (1600 x 1200)', format: new mxRectangle(0, 0, 1200, 1600)}, | |
2085 | - {key: 'custom', title: mxResources.get('custom'), format: null}]; | |
2068 | + // HACK thingsKit 页面尺寸控制 | |
2069 | + | |
2070 | + return [ | |
2071 | + {key: '1920 * 1080', title: '1920 * 1080(推荐尺寸)', format: new mxRectangle(0, 0, 1080, 1920)}, | |
2072 | + {key: '1060 * 520', title: '1060 * 520', format: new mxRectangle(0, 0, 520, 1060)}, | |
2073 | + {key: '1440 * 900', title: '1440 * 900', format: new mxRectangle(0, 0, 900, 1440)}, | |
2074 | + {key: '1366 * 768', title: '1366* 768', format: new mxRectangle(0, 0, 768, 1366)}, | |
2075 | + {key: 'custom', title: mxResources.get('custom'), format: null} | |
2076 | + ] | |
2077 | + // return [{key: 'letter', title: 'US-Letter (8,5" x 11")', format: mxConstants.PAGE_FORMAT_LETTER_PORTRAIT}, | |
2078 | + // {key: 'legal', title: 'US-Legal (8,5" x 14")', format: new mxRectangle(0, 0, 850, 1400)}, | |
2079 | + // {key: 'tabloid', title: 'US-Tabloid (11" x 17")', format: new mxRectangle(0, 0, 1100, 1700)}, | |
2080 | + // {key: 'executive', title: 'US-Executive (7" x 10")', format: new mxRectangle(0, 0, 700, 1000)}, | |
2081 | + // {key: 'a0', title: 'A0 (841 mm x 1189 mm)', format: new mxRectangle(0, 0, 3300, 4681)}, | |
2082 | + // {key: 'a1', title: 'A1 (594 mm x 841 mm)', format: new mxRectangle(0, 0, 2339, 3300)}, | |
2083 | + // {key: 'a2', title: 'A2 (420 mm x 594 mm)', format: new mxRectangle(0, 0, 1654, 2336)}, | |
2084 | + // {key: 'a3', title: 'A3 (297 mm x 420 mm)', format: new mxRectangle(0, 0, 1169, 1654)}, | |
2085 | + // {key: 'a4', title: 'A4 (210 mm x 297 mm)', format: mxConstants.PAGE_FORMAT_A4_PORTRAIT}, | |
2086 | + // {key: 'a5', title: 'A5 (148 mm x 210 mm)', format: new mxRectangle(0, 0, 583, 827)}, | |
2087 | + // {key: 'a6', title: 'A6 (105 mm x 148 mm)', format: new mxRectangle(0, 0, 413, 583)}, | |
2088 | + // {key: 'a7', title: 'A7 (74 mm x 105 mm)', format: new mxRectangle(0, 0, 291, 413)}, | |
2089 | + // {key: 'b4', title: 'B4 (250 mm x 353 mm)', format: new mxRectangle(0, 0, 980, 1390)}, | |
2090 | + // {key: 'b5', title: 'B5 (176 mm x 250 mm)', format: new mxRectangle(0, 0, 690, 980)}, | |
2091 | + // {key: '16-9', title: '16:9 (1600 x 900)', format: new mxRectangle(0, 0, 900, 1600)}, | |
2092 | + // {key: '16-10', title: '16:10 (1920 x 1200)', format: new mxRectangle(0, 0, 1200, 1920)}, | |
2093 | + // {key: '4-3', title: '4:3 (1600 x 1200)', format: new mxRectangle(0, 0, 1200, 1600)}, | |
2094 | + // {key: 'custom', title: mxResources.get('custom'), format: null}]; | |
2086 | 2095 | }; |
2087 | 2096 | |
2088 | 2097 | /** | ... | ... |
... | ... | @@ -2366,6 +2366,8 @@ EditorUi.prototype.initCanvas = function() |
2366 | 2366 | var t = graph.view.translate; |
2367 | 2367 | graph.view.setTranslate(Math.floor(t.x + cx / s), Math.floor(t.y + cy / s)); |
2368 | 2368 | } |
2369 | + // HACK thingsKit 设置视图起点为0, 0 | |
2370 | + graph.view.setTranslate(0, 0) | |
2369 | 2371 | } |
2370 | 2372 | }); |
2371 | 2373 | ... | ... |
1 | +let requestQueue = [] | |
2 | + | |
3 | +const JWT_TOKEN_KEY = 'JWT_TOKEN'; | |
4 | +const REFRESH_TOKEN_KEY = 'REFRESH_TOKEN'; | |
1 | 5 | /** |
2 | 6 | * custom http request |
3 | 7 | */ |
... | ... | @@ -16,7 +20,11 @@ function createAxios(options) { |
16 | 20 | |
17 | 21 | instance.interceptors.request.use((config) => { |
18 | 22 | config.headers["X-Authorization"] = "Bearer " + GLOBAL_TOKEN.token |
23 | + | |
19 | 24 | return config |
25 | + }, (error) => { | |
26 | + console.log(error) | |
27 | + return error | |
20 | 28 | }) |
21 | 29 | |
22 | 30 | /** |
... | ... | @@ -28,10 +36,73 @@ function createAxios(options) { |
28 | 36 | }, |
29 | 37 | function (error) { |
30 | 38 | if (error.response.status == 401) { |
31 | - layer.alert('登录超时,请重新登录'); | |
39 | + // layer.alert('登录超时,请重新登录'); | |
40 | + // const config = error.config | |
41 | + // const url = config.url | |
42 | + // const method = config.method | |
43 | + // const data = config.data | |
44 | + // const flag = requestQueue.find(item => item.url === url) | |
45 | + // if (!flag) { | |
46 | + // console.log(url, method, data) | |
47 | + // requestQueue.push({ url, method, data }) | |
48 | + // } | |
49 | + | |
50 | + doRefreshToken() | |
32 | 51 | } |
33 | 52 | return Promise.reject(error); |
34 | 53 | } |
35 | 54 | ); |
36 | 55 | return instance; |
37 | 56 | } |
57 | + | |
58 | + | |
59 | +/** | |
60 | + * @description refresh token | |
61 | + * @param {} params | |
62 | + * @returns | |
63 | + */ | |
64 | +function doRefreshToken(params) { | |
65 | + const refreshToken = GLOBAL_TOKEN.refreshToken | |
66 | + console.log(GLOBAL_TOKEN) | |
67 | + return new Promise((resolve, reject) => { | |
68 | + axios.post('/api/auth/token', | |
69 | + { refreshToken }, | |
70 | + { | |
71 | + headers: { | |
72 | + "content-type": "application/json; charset=UTF-8", | |
73 | + "X-Authorization": "Bearer " + GLOBAL_TOKEN.token, | |
74 | + }, | |
75 | + }) | |
76 | + .then(res => { | |
77 | + | |
78 | + // 存储token | |
79 | + const { refreshToken, token } = res.data | |
80 | + Object.assign(GLOBAL_TOKEN, { refreshToken, token }) | |
81 | + const ls = createStorage({ storage: localStorage }) | |
82 | + const originData = ls.get(GLOBAL_STORAGE_KEY) | |
83 | + const newRefreshToken = ls.generatorValue(REFRESH_TOKEN_KEY, refreshToken, true) | |
84 | + const newToken = ls.generatorValue(REFRESH_TOKEN_KEY, token, true) | |
85 | + console.log(Object.assign(originData, { [REFRESH_TOKEN_KEY]: newRefreshToken, [JWT_TOKEN_KEY]: newToken })) | |
86 | + ls.set(GLOBAL_STORAGE_KEY, Object.assign(originData, { [REFRESH_TOKEN_KEY]: newRefreshToken, [JWT_TOKEN_KEY]: newToken }), true) | |
87 | + | |
88 | + // try { | |
89 | + // requestQueue.forEach(item => { | |
90 | + // const { method, url, data } = item | |
91 | + // console.log({ item }) | |
92 | + // defHttp[method](url, data) | |
93 | + // }) | |
94 | + // requestQueue = [] | |
95 | + // } catch (error) { | |
96 | + | |
97 | + // } | |
98 | + | |
99 | + window.location.reload() | |
100 | + resolve() | |
101 | + }) | |
102 | + .catch((error) => { | |
103 | + const { origin } = window.location | |
104 | + window.location.href = `${origin}/login` | |
105 | + reject(error) | |
106 | + }) | |
107 | + }) | |
108 | +} | ... | ... |