@cloudbase/framework-plugin-low-code 0.7.10-beta.3 → 0.7.10
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/lib/builder/core/generate.d.ts.map +1 -1
- package/lib/builder/core/generate.js +6 -8
- package/lib/builder/core/index.d.ts.map +1 -1
- package/lib/builder/service/builder/webpack.d.ts +1 -1
- package/lib/builder/service/builder/webpack.d.ts.map +1 -1
- package/lib/builder/service/builder/webpack.js +17 -28
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +25 -73
- package/lib/weapps-core/utils/style.js +8 -0
- package/package.json +1 -1
- package/template/html/index.html.ejs +426 -426
- package/template/mp/app/weapps-api.js +27 -95
- package/template/mp/app.js +60 -76
- package/template/mp/common/util.js +3 -312
- package/template/mp/datasources/index.js +16 -5
- package/template/mp/package.json +2 -2
- package/template/package.json +2 -2
- package/template/src/app/global-api.js +41 -154
- package/template/src/datasources/index.js.tpl +14 -2
- package/template/src/handlers/FieldMiddleware/renderer.jsx +26 -86
- package/template/src/handlers/actionHandler/utils.js +11 -32
- package/template/src/handlers/lifecycle.js +10 -21
- package/template/src/handlers/render.jsx +6 -17
- package/template/src/handlers/utils/common.js +26 -42
- package/template/src/handlers/utils/widgets.js +9 -38
- package/template/src/index.jsx +9 -8
- package/template/src/pages/app.tpl +3 -1
- package/template/src/pages/composite.tpl +1 -1
- package/template/src/utils/formatEnum.js +1 -1
- package/template/src/utils/index.js +1 -15
- package/template/src/utils/ScanCodeComponent.js +0 -345
- package/template/src/utils/date.js +0 -324
- package/template/src/utils/scan-code-action.js +0 -27
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { observable } from 'mobx'
|
|
2
|
-
import {
|
|
2
|
+
import { createMpApp } from '@cloudbase/weda-client';
|
|
3
|
+
import { createComputed, formatEnum, enumOptions} from '<%= subLevelPath %>../common/util'
|
|
3
4
|
import process from '<%= subLevelPath %>../common/process'
|
|
4
|
-
import { DS_SDK, CLOUD_SDK, createDataset, EXTRA_API } from '<%= subLevelPath %>../datasources/index'
|
|
5
5
|
import appGlobal from '<%= subLevelPath %>../app/app-global'
|
|
6
|
-
import
|
|
6
|
+
import { CLOUD_SDK, createDataset, EXTRA_API } from '<%= subLevelPath %>../datasources/index'
|
|
7
|
+
|
|
7
8
|
|
|
8
9
|
<% if (!isBare) {%>
|
|
9
10
|
import state from '../lowcode/state'
|
|
@@ -21,78 +22,47 @@ export const app = createGlboalApi()
|
|
|
21
22
|
export { process }
|
|
22
23
|
|
|
23
24
|
function createGlboalApi() {
|
|
25
|
+
const mpApp = createMpApp({
|
|
26
|
+
appConfig: <%= appConfig %>
|
|
27
|
+
})
|
|
24
28
|
const globalAPI = {
|
|
25
29
|
id: '<%= appId %>',
|
|
26
30
|
domain: '<%= domain %>',
|
|
27
31
|
platform: 'MINIPROGRAME',
|
|
28
|
-
__internal__: {
|
|
29
|
-
activePage: null,
|
|
30
|
-
getConfig: function () {
|
|
31
|
-
return <%= appConfig %>;
|
|
32
|
-
},
|
|
33
|
-
resolveStaticResourceUrl(staticUrl) {
|
|
34
|
-
if (/^\//.test(staticUrl)) {
|
|
35
|
-
const domain = globalAPI?.__internal__?.getConfig?.()?.staticResourceDomain || globalAPI?.domain || ''
|
|
36
|
-
const url = `https://${domain}${staticUrl}`;
|
|
37
|
-
return url;
|
|
38
|
-
}
|
|
39
|
-
return staticUrl;
|
|
40
|
-
}
|
|
41
|
-
},
|
|
42
|
-
dataSources: DS_SDK,
|
|
43
32
|
pages: {},
|
|
44
33
|
session: {
|
|
45
34
|
//configure: sdk.configure,
|
|
46
35
|
//request: sdk.request,
|
|
47
36
|
//getSessionId: sdk.getSessionId,
|
|
48
37
|
},
|
|
49
|
-
enumOptions: enumOptions,
|
|
50
38
|
state: observable(state),
|
|
51
39
|
computed: createComputed(computed),
|
|
52
40
|
common,
|
|
53
|
-
relaunchHome: function () {
|
|
54
|
-
let wx_pages = getCurrentPages();
|
|
55
|
-
const { pages = [] } = globalAPI.__internal__.getConfig();
|
|
56
|
-
if (
|
|
57
|
-
wx_pages[0]?.route?.match(/pages\/(.*)\/index/)?.[1] === pages[0]?.id
|
|
58
|
-
) {
|
|
59
|
-
globalAPI.navigateBack({ delta: 10 });
|
|
60
|
-
} else if (pages[0]?.id) {
|
|
61
|
-
globalAPI.reLaunch({
|
|
62
|
-
pageId: pages[0].id,
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
},
|
|
66
41
|
invoke(params) {
|
|
67
42
|
return app.__internal__.activePage.invokeComponentMethod(params)
|
|
68
43
|
},
|
|
69
|
-
|
|
70
|
-
formatDate,
|
|
71
|
-
formatEnum,
|
|
72
|
-
get: getter,
|
|
73
|
-
set: setter,
|
|
74
|
-
/**
|
|
75
|
-
* @deprecated
|
|
76
|
-
*/
|
|
77
|
-
_getConfig(){
|
|
78
|
-
return globalAPI.__internal__.getConfig()
|
|
79
|
-
},
|
|
80
|
-
async getWXContext() {
|
|
81
|
-
const { Data } = await globalAPI.cloud.callWedaApi({
|
|
82
|
-
action: 'InvokeComponentWxModule',
|
|
83
|
-
data: {
|
|
84
|
-
Method: 'GetWxContext',
|
|
85
|
-
},
|
|
86
|
-
});
|
|
87
|
-
return typeof Data === 'string' ? JSON.parse(Data) : Data
|
|
88
|
-
},
|
|
89
|
-
getCurrentPage: function(){
|
|
90
|
-
return globalAPI.__internal__.activePage
|
|
91
|
-
}
|
|
92
|
-
},
|
|
93
|
-
// ... other sdk apis & apis from mp
|
|
44
|
+
...mpApp,
|
|
94
45
|
} // The global api exposed to lowcode
|
|
95
46
|
|
|
47
|
+
|
|
48
|
+
globalAPI.__internal__.enumOptions = enumOptions
|
|
49
|
+
globalAPI.utils.formatEnum = formatEnum
|
|
50
|
+
/**
|
|
51
|
+
* @deprecated utils._getConfig
|
|
52
|
+
*/
|
|
53
|
+
globalAPI.utils._getConfig = () => {
|
|
54
|
+
return globalAPI.__internal__.getConfig()
|
|
55
|
+
}
|
|
56
|
+
globalAPI.utils.getWXContext = async function() {
|
|
57
|
+
const { Data } = await globalAPI.cloud.callWedaApi({
|
|
58
|
+
action: 'InvokeComponentWxModule',
|
|
59
|
+
data: {
|
|
60
|
+
Method: 'GetWxContext',
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
return typeof Data === 'string' ? JSON.parse(Data) : Data
|
|
64
|
+
}
|
|
65
|
+
|
|
96
66
|
let dataset = createDataset('$global')
|
|
97
67
|
globalAPI.dataset = dataset
|
|
98
68
|
globalAPI.state.dataset = dataset
|
|
@@ -101,18 +71,6 @@ function createGlboalApi() {
|
|
|
101
71
|
globalAPI.utils.set(globalAPI.dataset.state, keyPath, userSetState[keyPath]);
|
|
102
72
|
});
|
|
103
73
|
};
|
|
104
|
-
/**
|
|
105
|
-
* 内部通用的设置状态变量值的方法
|
|
106
|
-
* varPath 结构为 $global.<变量名> 即全局变量
|
|
107
|
-
* $page.<变量名> 即当前页面变量
|
|
108
|
-
* <pageId>.<变量名> 指定页面 pageId 的变量 (应当避免修改非当前页面的变量值)
|
|
109
|
-
*/
|
|
110
|
-
globalAPI._setStateVal = (config) => {
|
|
111
|
-
// @ts-ignore
|
|
112
|
-
EXTRA_API.setState(config.varPath, config.val);
|
|
113
|
-
};
|
|
114
|
-
// mount wx apis
|
|
115
|
-
Object.assign(globalAPI, weappApis)
|
|
116
74
|
|
|
117
75
|
const subPackageName = '<%= subPackageName %>'
|
|
118
76
|
if (subPackageName) {
|
|
@@ -127,31 +85,5 @@ function createGlboalApi() {
|
|
|
127
85
|
// 避免被wx.cloud 覆盖
|
|
128
86
|
globalAPI.cloud = CLOUD_SDK
|
|
129
87
|
|
|
130
|
-
// # expose some sdk modules
|
|
131
|
-
/* const sdkModsIncluded = ['flow', 'getPageOptions', 'getLaunchOptions']
|
|
132
|
-
sdkModsIncluded.forEach(key => {
|
|
133
|
-
globalAPI[key] = sdk[key]
|
|
134
|
-
}) */
|
|
135
|
-
const { scanCode } = globalAPI
|
|
136
|
-
globalAPI.scanCode = (options) => {
|
|
137
|
-
const {enableDefaultBehavior, ...restOptions} = options;
|
|
138
|
-
const shouldReturnPromise = (!restOptions.success && !restOptions.complete && !restOptions.fail);
|
|
139
|
-
if(shouldReturnPromise) {
|
|
140
|
-
return new Promise((resolve, reject) => {
|
|
141
|
-
scanCode(restOptions).then((res) => {
|
|
142
|
-
if(enableDefaultBehavior) {
|
|
143
|
-
globalAPI.showModal({
|
|
144
|
-
title: '扫描到以下内容',
|
|
145
|
-
content: res.result,
|
|
146
|
-
showCancel: false,
|
|
147
|
-
})
|
|
148
|
-
}
|
|
149
|
-
resolve(res)
|
|
150
|
-
})
|
|
151
|
-
.catch(reject)
|
|
152
|
-
})
|
|
153
|
-
}
|
|
154
|
-
return scanCode(restOptions);
|
|
155
|
-
}
|
|
156
88
|
return globalAPI
|
|
157
89
|
}
|
package/template/mp/app.js
CHANGED
|
@@ -1,94 +1,78 @@
|
|
|
1
|
-
import { setConfig, getAccessToken, initTcb } from '@cloudbase/weda-cloud-sdk'
|
|
2
1
|
import lifeCycle from './lowcode/lifecycle'
|
|
3
2
|
import { app } from './app/weapps-api'
|
|
4
|
-
import WxReportV2 from './common/wx_yypt_report_v2'
|
|
5
3
|
// 引入数据源管理器并进行初始化
|
|
6
|
-
import { EXTRA_API, createStateDataSourceVar, generateParamsParser } from './datasources/index';
|
|
4
|
+
import { setConfig, getAccessToken, EXTRA_API, createStateDataSourceVar, generateParamsParser } from './datasources/index';
|
|
7
5
|
import { redirectToLogin, findLoginPage, getAuthConfig } from './common/util'
|
|
8
6
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
intervalTime: 3, // 间隔多久执行一次上报,默认3秒
|
|
19
|
-
reportLogsNum: 5, // 每次合并上报记录条数,默认5次
|
|
20
|
-
});
|
|
21
|
-
<% }%>
|
|
22
|
-
|
|
23
|
-
// 设置数据源请求的 loading 及 toast 处理
|
|
24
|
-
setConfig({
|
|
25
|
-
beforeDSRequest: (cfg) => {
|
|
26
|
-
if (!cfg.options || !cfg.options.showLoading) return
|
|
27
|
-
app.showLoading()
|
|
28
|
-
},
|
|
29
|
-
beforeCallFunction: async (params) => {
|
|
30
|
-
try {
|
|
31
|
-
const loginPage = findLoginPage();
|
|
7
|
+
// 设置数据源请求的 loading 及 toast 处理
|
|
8
|
+
setConfig({
|
|
9
|
+
beforeDSRequest: (cfg) => {
|
|
10
|
+
if (!cfg.options || !cfg.options.showLoading) return
|
|
11
|
+
app.showLoading()
|
|
12
|
+
},
|
|
13
|
+
beforeCallFunction: async (params) => {
|
|
14
|
+
try {
|
|
15
|
+
const loginPage = findLoginPage();
|
|
32
16
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
break;
|
|
17
|
+
let skip = false;
|
|
18
|
+
switch (params?.data?.methodName) {
|
|
19
|
+
case 'callWedaApi': {
|
|
20
|
+
if (['GetMiniProgramUserTicket', 'DescribeRuntimeResourceStrategy'].includes(params?.data?.params.action)) {
|
|
21
|
+
skip = true;
|
|
40
22
|
}
|
|
23
|
+
break;
|
|
41
24
|
}
|
|
25
|
+
}
|
|
42
26
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
27
|
+
// 后续做过滤处理
|
|
28
|
+
if (!loginPage || (params?.data?.mode === 'c' && skip)) {
|
|
29
|
+
return params;
|
|
30
|
+
}
|
|
31
|
+
// await initTcb();
|
|
32
|
+
const { accessToken } = await getAccessToken();
|
|
33
|
+
if (accessToken) {
|
|
34
|
+
params.data.accessToken = accessToken;
|
|
35
|
+
}
|
|
36
|
+
} catch (e) {
|
|
37
|
+
if (app?.cloud?.currentUser?.userType === "externalUser" && e?.error === 'unauthenticated') {
|
|
38
|
+
app.showToast({
|
|
39
|
+
title: '登录态失效',
|
|
40
|
+
icon: 'error',
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
console.error('beforeCallFunction error', e);
|
|
44
|
+
}
|
|
45
|
+
return params;
|
|
46
|
+
},
|
|
47
|
+
afterDSRequest: (cfg, error, result) => {
|
|
48
|
+
if (!cfg.options) return
|
|
49
|
+
if (cfg.options.showLoading) app.hideLoading()
|
|
50
|
+
if (!cfg.options.showToast) return
|
|
51
|
+
const isSuccess = !error && result && !result.code
|
|
52
|
+
app.showToast({ icon: isSuccess ? 'success' : 'error' })
|
|
53
|
+
},
|
|
54
|
+
async afterCallFunction(params, error, res) {
|
|
55
|
+
if (params?.data?.params?.action != 'DescribeRuntimeResourceStrategy' && ['InnerError.AuthFailure', 'InvalidAccessToken'].includes(res?.result?.code)) {
|
|
56
|
+
const loginPage = findLoginPage();
|
|
57
|
+
if (loginPage) {
|
|
58
|
+
const authConfig = await getAuthConfig();
|
|
59
|
+
let isAnonymous = true;
|
|
60
|
+
try {
|
|
61
|
+
const { accessToken } = await getAccessToken();
|
|
62
|
+
isAnonymous = !accessToken;
|
|
63
|
+
} catch (e) { }
|
|
64
|
+
if (isAnonymous && authConfig.RejectStrategy == 'to_login') {
|
|
65
|
+
redirectToLogin();
|
|
66
|
+
} else if (authConfig.RejectStrategy == 'show_warning') {
|
|
54
67
|
app.showToast({
|
|
55
|
-
title: '
|
|
68
|
+
title: '接口无访问权限',
|
|
56
69
|
icon: 'error',
|
|
57
70
|
});
|
|
58
71
|
}
|
|
59
|
-
console.error('beforeCallFunction error', e);
|
|
60
|
-
}
|
|
61
|
-
return params;
|
|
62
|
-
},
|
|
63
|
-
afterDSRequest: (cfg, error, result) => {
|
|
64
|
-
if (!cfg.options) return
|
|
65
|
-
if (cfg.options.showLoading) app.hideLoading()
|
|
66
|
-
if (!cfg.options.showToast) return
|
|
67
|
-
const isSuccess = !error && result && !result.code
|
|
68
|
-
app.showToast({ icon: isSuccess ? 'success' : 'error' })
|
|
69
|
-
},
|
|
70
|
-
async afterCallFunction(params, error, res) {
|
|
71
|
-
if (params?.data?.params?.action != 'DescribeRuntimeResourceStrategy' && ['InnerError.AuthFailure', 'InvalidAccessToken'].includes(res?.result?.code)) {
|
|
72
|
-
const loginPage = findLoginPage();
|
|
73
|
-
if (loginPage) {
|
|
74
|
-
const authConfig = await getAuthConfig();
|
|
75
|
-
let isAnonymous = true;
|
|
76
|
-
try {
|
|
77
|
-
const { accessToken } = await getAccessToken();
|
|
78
|
-
isAnonymous = !accessToken;
|
|
79
|
-
} catch (e) { }
|
|
80
|
-
if (isAnonymous && authConfig.RejectStrategy == 'to_login') {
|
|
81
|
-
redirectToLogin();
|
|
82
|
-
} else if (authConfig.RejectStrategy == 'show_warning') {
|
|
83
|
-
app.showToast({
|
|
84
|
-
title: '接口无访问权限',
|
|
85
|
-
icon: 'error',
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
72
|
}
|
|
90
73
|
}
|
|
91
|
-
}
|
|
74
|
+
}
|
|
75
|
+
})
|
|
92
76
|
|
|
93
77
|
App({
|
|
94
78
|
onLaunch(options) {
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
import { findForItemsOfWidget, mpCompToWidget } from './widget'
|
|
4
|
-
import lodashGet from 'lodash.get';
|
|
5
|
-
import lodashSet from 'lodash.set';
|
|
6
4
|
import { observable } from 'mobx';
|
|
7
5
|
import { app } from '../app/weapps-api'
|
|
8
|
-
import {
|
|
6
|
+
import { auth } from '@cloudbase/weda-client'
|
|
9
7
|
|
|
10
8
|
/**
|
|
11
9
|
* Convert abcWordSnd -> abc-word-snd
|
|
@@ -219,20 +217,6 @@ export function set(object, path, value) {
|
|
|
219
217
|
return object
|
|
220
218
|
}
|
|
221
219
|
|
|
222
|
-
/*
|
|
223
|
-
根据 object对象的path路径获取值。 如果解析 value 是 undefined 会以 defaultValue 取代。
|
|
224
|
-
*/
|
|
225
|
-
export function getter(context, path, defaultValue = undefined) {
|
|
226
|
-
return lodashGet(context, path, defaultValue);
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
/*
|
|
230
|
-
设置 object对象中对应 path 属性路径上的值,如果path不存在,则创建。 缺少的索引属性会创建为数组,而缺少的属性会创建为对象。 使用_.setWith 定制path创建
|
|
231
|
-
*/
|
|
232
|
-
export function setter(context, path, value = undefined) {
|
|
233
|
-
return lodashSet(context, path, value);
|
|
234
|
-
}
|
|
235
|
-
|
|
236
220
|
export function findLoginPage() {
|
|
237
221
|
const { app } = getApp();
|
|
238
222
|
const { pages = [] } = app.__internal__.getConfig();
|
|
@@ -314,7 +298,7 @@ export async function checkAuth(app, appId, $page) {
|
|
|
314
298
|
|
|
315
299
|
let isAnonymousUser = true;
|
|
316
300
|
try {
|
|
317
|
-
const { accessToken } = await getAccessToken();
|
|
301
|
+
const { accessToken } = await auth.getAccessToken();
|
|
318
302
|
isAnonymousUser = !accessToken;
|
|
319
303
|
} catch (e) { }
|
|
320
304
|
|
|
@@ -367,293 +351,6 @@ export function redirectToLogin(currentPage) {
|
|
|
367
351
|
}
|
|
368
352
|
}
|
|
369
353
|
|
|
370
|
-
// 日期转换
|
|
371
|
-
class CustomDate {
|
|
372
|
-
constructor() {
|
|
373
|
-
this.i18n = {
|
|
374
|
-
dayNames: [
|
|
375
|
-
'Sun',
|
|
376
|
-
'Mon',
|
|
377
|
-
'Tue',
|
|
378
|
-
'Wed',
|
|
379
|
-
'Thu',
|
|
380
|
-
'Fri',
|
|
381
|
-
'Sat',
|
|
382
|
-
'Sunday',
|
|
383
|
-
'Monday',
|
|
384
|
-
'Tuesday',
|
|
385
|
-
'Wednesday',
|
|
386
|
-
'Thursday',
|
|
387
|
-
'Friday',
|
|
388
|
-
'Saturday',
|
|
389
|
-
],
|
|
390
|
-
monthNames: [
|
|
391
|
-
'Jan',
|
|
392
|
-
'Feb',
|
|
393
|
-
'Mar',
|
|
394
|
-
'Apr',
|
|
395
|
-
'May',
|
|
396
|
-
'Jun',
|
|
397
|
-
'Jul',
|
|
398
|
-
'Aug',
|
|
399
|
-
'Sep',
|
|
400
|
-
'Oct',
|
|
401
|
-
'Nov',
|
|
402
|
-
'Dec',
|
|
403
|
-
'January',
|
|
404
|
-
'February',
|
|
405
|
-
'March',
|
|
406
|
-
'April',
|
|
407
|
-
'May',
|
|
408
|
-
'June',
|
|
409
|
-
'July',
|
|
410
|
-
'August',
|
|
411
|
-
'September',
|
|
412
|
-
'October',
|
|
413
|
-
'November',
|
|
414
|
-
'December',
|
|
415
|
-
],
|
|
416
|
-
timeNames: ['a', 'p', 'am', 'pm', 'A', 'P', 'AM', 'PM'],
|
|
417
|
-
};
|
|
418
|
-
this.masks = {
|
|
419
|
-
default: 'ddd mmm dd yyyy HH:MM:ss',
|
|
420
|
-
shortDate: 'm/d/yy',
|
|
421
|
-
paddedShortDate: 'mm/dd/yyyy',
|
|
422
|
-
mediumDate: 'mmm d, yyyy',
|
|
423
|
-
longDate: 'mmmm d, yyyy',
|
|
424
|
-
fullDate: 'dddd, mmmm d, yyyy',
|
|
425
|
-
shortTime: 'h:MM TT',
|
|
426
|
-
mediumTime: 'h:MM:ss TT',
|
|
427
|
-
longTime: 'h:MM:ss TT Z',
|
|
428
|
-
isoDate: 'yyyy-mm-dd',
|
|
429
|
-
isoTime: 'HH:MM:ss',
|
|
430
|
-
isoDateTime: 'yyyy-mm-dd\'T\'HH:MM:sso',
|
|
431
|
-
isoUtcDateTime: 'UTC:yyyy-mm-dd\'T\'HH:MM:ss\'Z\'',
|
|
432
|
-
expiresHeaderFormat: 'ddd, dd mmm yyyy HH:MM:ss Z',
|
|
433
|
-
};
|
|
434
|
-
this.token = /d{1,4}|D{3,4}|m{1,4}|yy(?:yy)?|([HhMsTt])\1?|W{1,2}|[LlopSZN]|"[^"]*"|'[^']*'/g;
|
|
435
|
-
this.timezone = /\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\d{4})?)\b/g;
|
|
436
|
-
this.timezoneClip = /[^-+\dA-Z]/g;
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
/*
|
|
440
|
-
*
|
|
441
|
-
| Name | Mask | Example |
|
|
442
|
-
| ----------------- | ------------------------------ | ------------------------ |
|
|
443
|
-
| `default` | `ddd mmm dd yyyy HH:MM:ss` | Sat Jun 09 2007 17:46:21 |
|
|
444
|
-
| `shortDate` | `m/d/yy` | 6/9/07 |
|
|
445
|
-
| `paddedShortDate` | `mm/dd/yyyy` | 06/09/2007 |
|
|
446
|
-
| `mediumDate` | `mmm d, yyyy` | Jun 9, 2007 |
|
|
447
|
-
| `longDate` | `mmmm d, yyyy` | June 9, 2007 |
|
|
448
|
-
| `fullDate` | `dddd, mmmm d, yyyy` | Saturday, June 9, 2007 |
|
|
449
|
-
| `shortTime` | `h:MM TT` | 5:46 PM |
|
|
450
|
-
| `mediumTime` | `h:MM:ss TT` | 5:46:21 PM |
|
|
451
|
-
| `longTime` | `h:MM:ss TT Z` | 5:46:21 PM EST |
|
|
452
|
-
| `isoDate` | `yyyy-mm-dd` | 2007-06-09 |
|
|
453
|
-
| `isoTime` | `HH:MM:ss` | 17:46:21 |
|
|
454
|
-
| `isoDateTime` | `yyyy-mm-dd'T'HH:MM:sso` | 2007-06-09T17:46:21+0700 |
|
|
455
|
-
| `isoUtcDateTime` | `UTC:yyyy-mm-dd'T'HH:MM:ss'Z'` | 2007-06-09T22:46:21Z |
|
|
456
|
-
*
|
|
457
|
-
*/
|
|
458
|
-
format(date, mask, utc, gmt) {
|
|
459
|
-
let newMask = mask;
|
|
460
|
-
let newDate = date;
|
|
461
|
-
let newUtc = utc;
|
|
462
|
-
let newGmt = gmt;
|
|
463
|
-
if (arguments.length === 1 && this._kindOf(newDate) === 'string' && !/\d/.test(newDate))
|
|
464
|
-
newDate = undefined;
|
|
465
|
-
newDate = newDate || newDate === 0 ? newDate : new Date();
|
|
466
|
-
if (!(newDate instanceof Date))
|
|
467
|
-
newDate = new Date(newDate);
|
|
468
|
-
if (isNaN(newDate))
|
|
469
|
-
throw TypeError('Invalid date');
|
|
470
|
-
newMask = String(this.masks[newMask] || newMask || this.masks['default']);
|
|
471
|
-
const maskSlice = newMask.slice(0, 4);
|
|
472
|
-
if (maskSlice === 'UTC:' || maskSlice === 'GMT:') {
|
|
473
|
-
newMask = newMask.slice(4);
|
|
474
|
-
newUtc = true;
|
|
475
|
-
if (maskSlice === 'GMT:')
|
|
476
|
-
newGmt = true;
|
|
477
|
-
}
|
|
478
|
-
const _ = newUtc ? 'getUTC' : 'get';
|
|
479
|
-
const _d = newDate[`${_}Date`]();
|
|
480
|
-
const D = newDate[`${_}Day`]();
|
|
481
|
-
const _m = newDate[`${_}Month`]();
|
|
482
|
-
const y = newDate[`${_}FullYear`]();
|
|
483
|
-
const _H = newDate[`${_}Hours`]();
|
|
484
|
-
const _M = newDate[`${_}Minutes`]();
|
|
485
|
-
const _s = newDate[`${_}Seconds`]();
|
|
486
|
-
const _L = newDate[`${_}Milliseconds`]();
|
|
487
|
-
const _o = newUtc ? 0 : newDate.getTimezoneOffset();
|
|
488
|
-
const _W = this._getWeek(newDate);
|
|
489
|
-
const _N = this._getDayOfWeek(newDate);
|
|
490
|
-
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
491
|
-
const self = this;
|
|
492
|
-
// @ts-ignore
|
|
493
|
-
// @ts-ignore
|
|
494
|
-
const flags = {
|
|
495
|
-
d: () => _d,
|
|
496
|
-
dd: () => self._pad(_d),
|
|
497
|
-
ddd: () => self.i18n.dayNames[D],
|
|
498
|
-
DDD: () => self._getDayName({ y, m: _m, d: _d, _, dayName: self.i18n.dayNames[D], short: true }),
|
|
499
|
-
dddd: () => self.i18n.dayNames[D + 7],
|
|
500
|
-
DDDD: () => self._getDayName({ y: y, m: _m, d: _d, _: _, dayName: self.i18n.dayNames[D + 7] }),
|
|
501
|
-
m: () => _m + 1,
|
|
502
|
-
mm: () => self._pad(_m + 1),
|
|
503
|
-
mmm: () => self.i18n.monthNames[_m],
|
|
504
|
-
mmmm: () => self.i18n.monthNames[_m + 12],
|
|
505
|
-
yy: () => String(y)
|
|
506
|
-
.slice(2),
|
|
507
|
-
yyyy: () => self._pad(y, 4),
|
|
508
|
-
h: () => _H % 12 || 12,
|
|
509
|
-
hh: () => self._pad(_H % 12 || 12),
|
|
510
|
-
H: () => _H,
|
|
511
|
-
HH: () => self._pad(_H),
|
|
512
|
-
M: () => _M,
|
|
513
|
-
MM: () => self._pad(_M),
|
|
514
|
-
s: () => _s,
|
|
515
|
-
ss: () => self._pad(_s),
|
|
516
|
-
l: () => self._pad(_L, 3),
|
|
517
|
-
L: () => self._pad(Math.floor(_L / 10)),
|
|
518
|
-
t: () => (_H < 12 ? self.i18n.timeNames[0] : self.i18n.timeNames[1]),
|
|
519
|
-
tt: () => (_H < 12 ? self.i18n.timeNames[2] : self.i18n.timeNames[3]),
|
|
520
|
-
T: () => (_H < 12 ? self.i18n.timeNames[4] : self.i18n.timeNames[5]),
|
|
521
|
-
TT: () => (_H < 12 ? self.i18n.timeNames[6] : self.i18n.timeNames[7]),
|
|
522
|
-
// eslint-disable-next-line no-nested-ternary
|
|
523
|
-
Z: () => newGmt ? 'GMT' : newUtc ? 'UTC' : (String(newDate)
|
|
524
|
-
.match(self.timezone) || ['']).pop()
|
|
525
|
-
.replace(self.timezoneClip, '')
|
|
526
|
-
.replace(/GMT\+0000/g, 'UTC'),
|
|
527
|
-
o: () => (_o > 0 ? '-' : '+') + self._pad(Math.floor(Math.abs(_o) / 60) * 100 + (Math.abs(_o) % 60), 4),
|
|
528
|
-
p: () => `${(_o > 0 ? '-' : '+') + self._pad(Math.floor(Math.abs(_o) / 60), 2)}:${self._pad(Math.floor(Math.abs(_o) % 60), 2)}`,
|
|
529
|
-
// @ts-ignore
|
|
530
|
-
S: () => ['th', 'st', 'nd', 'rd'][_d % 10 > 3 ? 0 : (((_d % 100) - (_d % 10) != 10) * _d) % 10],
|
|
531
|
-
W: () => _W,
|
|
532
|
-
WW: () => self._pad(_W),
|
|
533
|
-
N: () => _N,
|
|
534
|
-
};
|
|
535
|
-
return mask.replace(this.token, (match) => {
|
|
536
|
-
if (match in flags) {
|
|
537
|
-
return flags[match]();
|
|
538
|
-
}
|
|
539
|
-
return match.slice(1, match.length - 1);
|
|
540
|
-
});
|
|
541
|
-
}
|
|
542
|
-
|
|
543
|
-
_pad(val, len) {
|
|
544
|
-
let newVal = String(val);
|
|
545
|
-
const newLen = len || 2;
|
|
546
|
-
while (newVal.length < newLen) {
|
|
547
|
-
newVal = `0${newVal}`;
|
|
548
|
-
}
|
|
549
|
-
return newVal;
|
|
550
|
-
}
|
|
551
|
-
|
|
552
|
-
_getDayName(_ref) {
|
|
553
|
-
const { y, m, d, _, dayName } = _ref;
|
|
554
|
-
const _ref$short = _ref['short'];
|
|
555
|
-
const _short = _ref$short === void 0 ? false : _ref$short;
|
|
556
|
-
const today = new Date();
|
|
557
|
-
const yesterday = new Date();
|
|
558
|
-
yesterday.setDate(yesterday[`${_}Date`]() - 1);
|
|
559
|
-
const tomorrow = new Date();
|
|
560
|
-
tomorrow.setDate(tomorrow[`${_}Date`]() + 1);
|
|
561
|
-
const today_d = function today_d() {
|
|
562
|
-
return today[`${_}Date`]();
|
|
563
|
-
};
|
|
564
|
-
const today_m = function today_m() {
|
|
565
|
-
return today[`${_}Month`]();
|
|
566
|
-
};
|
|
567
|
-
const today_y = function today_y() {
|
|
568
|
-
return today[`${_}FullYear`]();
|
|
569
|
-
};
|
|
570
|
-
const yesterday_d = function yesterday_d() {
|
|
571
|
-
return yesterday[`${_}Date`]();
|
|
572
|
-
};
|
|
573
|
-
const yesterday_m = function yesterday_m() {
|
|
574
|
-
return yesterday[`${_}Month`]();
|
|
575
|
-
};
|
|
576
|
-
const yesterday_y = function yesterday_y() {
|
|
577
|
-
return yesterday[`${_}FullYear`]();
|
|
578
|
-
};
|
|
579
|
-
const tomorrow_d = function tomorrow_d() {
|
|
580
|
-
return tomorrow[`${_}Date`]();
|
|
581
|
-
};
|
|
582
|
-
const tomorrow_m = function tomorrow_m() {
|
|
583
|
-
return tomorrow[`${_}Month`]();
|
|
584
|
-
};
|
|
585
|
-
const tomorrow_y = function tomorrow_y() {
|
|
586
|
-
return tomorrow[`${_}FullYear`]();
|
|
587
|
-
};
|
|
588
|
-
if (today_y() === y && today_m() === m && today_d() === d) {
|
|
589
|
-
return _short ? 'Tdy' : 'Today';
|
|
590
|
-
}
|
|
591
|
-
if (yesterday_y() === y && yesterday_m() === m && yesterday_d() === d) {
|
|
592
|
-
return _short ? 'Ysd' : 'Yesterday';
|
|
593
|
-
}
|
|
594
|
-
if (tomorrow_y() === y && tomorrow_m() === m && tomorrow_d() === d) {
|
|
595
|
-
return _short ? 'Tmw' : 'Tomorrow';
|
|
596
|
-
}
|
|
597
|
-
return dayName;
|
|
598
|
-
}
|
|
599
|
-
|
|
600
|
-
_getWeek(date) {
|
|
601
|
-
const targetThursday = new Date(date.getFullYear(), date.getMonth(), date.getDate());
|
|
602
|
-
targetThursday.setDate(targetThursday.getDate() - ((targetThursday.getDay() + 6) % 7) + 3);
|
|
603
|
-
const firstThursday = new Date(targetThursday.getFullYear(), 0, 4);
|
|
604
|
-
firstThursday.setDate(firstThursday.getDate() - ((firstThursday.getDay() + 6) % 7) + 3);
|
|
605
|
-
const ds = targetThursday.getTimezoneOffset() - firstThursday.getTimezoneOffset();
|
|
606
|
-
targetThursday.setHours(targetThursday.getHours() - ds);
|
|
607
|
-
const weekDiff = (targetThursday - firstThursday) / (864e5 * 7);
|
|
608
|
-
return 1 + Math.floor(weekDiff);
|
|
609
|
-
}
|
|
610
|
-
|
|
611
|
-
_getDayOfWeek(date) {
|
|
612
|
-
let dow = date.getDay();
|
|
613
|
-
if (dow === 0) {
|
|
614
|
-
dow = 7;
|
|
615
|
-
}
|
|
616
|
-
return dow;
|
|
617
|
-
}
|
|
618
|
-
|
|
619
|
-
_kindOf(val) {
|
|
620
|
-
if (val === null) {
|
|
621
|
-
return 'null';
|
|
622
|
-
}
|
|
623
|
-
if (val === undefined) {
|
|
624
|
-
return 'undefined';
|
|
625
|
-
}
|
|
626
|
-
if (this._typeof(val) !== 'object') {
|
|
627
|
-
return this._typeof(val);
|
|
628
|
-
}
|
|
629
|
-
if (Array.isArray(val)) {
|
|
630
|
-
return 'array';
|
|
631
|
-
}
|
|
632
|
-
return {}.toString
|
|
633
|
-
.call(val)
|
|
634
|
-
.slice(8, -1)
|
|
635
|
-
.toLowerCase();
|
|
636
|
-
}
|
|
637
|
-
|
|
638
|
-
_typeof(obj) {
|
|
639
|
-
if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') {
|
|
640
|
-
this._typeof = function _typeof(obj) {
|
|
641
|
-
return typeof obj;
|
|
642
|
-
};
|
|
643
|
-
} else {
|
|
644
|
-
this._typeof = function _typeof(obj) {
|
|
645
|
-
return obj && typeof Symbol === 'function' && obj.constructor === Symbol && obj !== Symbol.prototype
|
|
646
|
-
? 'symbol'
|
|
647
|
-
: typeof obj;
|
|
648
|
-
};
|
|
649
|
-
}
|
|
650
|
-
return this._typeof(obj);
|
|
651
|
-
}
|
|
652
|
-
}
|
|
653
|
-
|
|
654
|
-
const dataInstance = new CustomDate();
|
|
655
|
-
export const formatDate = new CustomDate().format.bind(dataInstance);
|
|
656
|
-
|
|
657
354
|
let loading = {};
|
|
658
355
|
export let enumOptions = observable({});
|
|
659
356
|
export function formatEnum(path, optionname) {
|
|
@@ -685,7 +382,7 @@ function getEnumOptions(optionName) {
|
|
|
685
382
|
}
|
|
686
383
|
return '';
|
|
687
384
|
}
|
|
688
|
-
|
|
385
|
+
async function getGeneralOptions(optionName) {
|
|
689
386
|
return app.cloud.callWedaApi({
|
|
690
387
|
action: 'DescribeGeneralOptionsDetailList',
|
|
691
388
|
data: {
|
|
@@ -696,9 +393,3 @@ export async function getGeneralOptions(optionName) {
|
|
|
696
393
|
});
|
|
697
394
|
}
|
|
698
395
|
|
|
699
|
-
export const utils = {
|
|
700
|
-
formatDate,
|
|
701
|
-
get: getter,
|
|
702
|
-
set: setter,
|
|
703
|
-
formatEnum
|
|
704
|
-
};
|