af-mobile-client-vue3 1.2.31 → 1.2.33

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.
@@ -0,0 +1,29 @@
1
+ import type TokenType from '../enums/TokenType'
2
+
3
+ export default class Token {
4
+ private type: TokenType
5
+ private value: any
6
+ private startPos: number
7
+
8
+ constructor(type: TokenType, value: any, startPos: number) {
9
+ this.type = type
10
+ this.value = value
11
+ this.startPos = startPos
12
+ }
13
+
14
+ public toString(): string {
15
+ return this.type.toString() + this.value
16
+ }
17
+
18
+ public getType(): TokenType {
19
+ return this.type
20
+ }
21
+
22
+ public getValue(): any {
23
+ return this.value
24
+ }
25
+
26
+ public getStartPos(): number {
27
+ return this.startPos
28
+ }
29
+ }
@@ -0,0 +1,81 @@
1
+ enum ExpressionType {
2
+ // >
3
+ GreaterThan,
4
+ // >=
5
+ GreaterThanOrEqual,
6
+ // <
7
+ LessThan,
8
+ // <=
9
+ LessThanOrEqual,
10
+ // = =
11
+ Equal,
12
+ // ! =
13
+ NotEqual,
14
+ // +
15
+ Add,
16
+ // -
17
+ Subtract,
18
+ //*
19
+ Multiply,
20
+ // 除法
21
+ Divide,
22
+ // 求余
23
+ Modulo,
24
+
25
+ // 字符串连接
26
+ Concat,
27
+ // 逻辑非
28
+ Not,
29
+ // 逻辑与
30
+ And,
31
+ // 逻辑或
32
+ Or,
33
+
34
+ // 常数
35
+ Constant,
36
+ // 标识符
37
+ Identity,
38
+
39
+ // 获取对象属性
40
+ Property,
41
+
42
+ // 产生Json对象
43
+ Json,
44
+ // 产生Json数组
45
+ Array,
46
+ // Json对象属性值对
47
+ Attr,
48
+ // 数组下标,[0]
49
+ ArrayIndex,
50
+ // 函数调用
51
+ Call,
52
+ // for循环
53
+ For,
54
+ // 逗号表达式
55
+ Comma,
56
+ // 赋值语句
57
+ Assign,
58
+ // 条件语句
59
+ Condition,
60
+ // 参数
61
+ Param,
62
+ // Try
63
+ Try,
64
+ // Catch
65
+ Catch,
66
+ // 跳出
67
+ Return,
68
+ // 抛出异常
69
+ Throw,
70
+ // 校验
71
+ Validate,
72
+ // 断言
73
+ Assert,
74
+ // 循环终止
75
+ Break,
76
+ // 循环跳过
77
+ Continue,
78
+ // lambda
79
+ Lambda,
80
+ }
81
+ export default ExpressionType
@@ -0,0 +1,11 @@
1
+ enum TokenType {
2
+ Int = 'Int',
3
+ Double = 'Double',
4
+ Bool = 'Bool',
5
+ String = 'String',
6
+ Identy = 'Identity',
7
+ Oper = 'Oper',
8
+ End = 'End',
9
+ Null = 'Null',
10
+ }
11
+ export default TokenType
@@ -0,0 +1,2 @@
1
+ export default class BreakWayException extends Error {
2
+ }
@@ -0,0 +1,2 @@
1
+ export default class ContinueWayException extends Error {
2
+ }
@@ -0,0 +1,29 @@
1
+ /**
2
+ * 表达式执行异常,将显示执行异常的位置信息
3
+ */
4
+ export default class ExpressionException extends Error {
5
+ constructor(source: string, pos: number, cause: Error) {
6
+ let message: string
7
+ let beforeErrorContent: string = source.substring(0, pos).trim()
8
+ const length: number = beforeErrorContent.length
9
+ if (length > 1000) {
10
+ beforeErrorContent = `以上省略......\n${beforeErrorContent.substring(length - 1000)}`
11
+ }
12
+ const afterErrorContent: string = source.substring(pos)
13
+ const afterErrorContentIndex: number = afterErrorContent.indexOf('\n')
14
+ if (afterErrorContentIndex === -1) {
15
+ message = `${beforeErrorContent.trim()} <- ${afterErrorContent}`
16
+ }
17
+ else {
18
+ message = `${beforeErrorContent.trim()} <- ${afterErrorContent.substring(0, afterErrorContentIndex)}\n后续省略......`
19
+ }
20
+
21
+ // 通过原生 Error 的 cause 参数传递原因
22
+ super(message, { cause })
23
+ this.name = this.constructor.name
24
+
25
+ if (Error.captureStackTrace) {
26
+ Error.captureStackTrace(this, this.constructor)
27
+ }
28
+ }
29
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Return 方法
3
+ */
4
+ export default class ReturnWayException extends Error {
5
+ private readonly returnObject: any
6
+ constructor(returnValue: any) {
7
+ super()
8
+ this.returnObject = returnValue
9
+ }
10
+
11
+ public getReturnObject(): any {
12
+ return this.returnObject
13
+ }
14
+ }
@@ -0,0 +1,22 @@
1
+ export default class ServiceException extends Error {
2
+ message: string
3
+ code: number | undefined
4
+ constructor(message: string, code?: number) {
5
+ super()
6
+ this.message = message
7
+ this.code = code
8
+ }
9
+
10
+ public getMessage(): string {
11
+ return this.message
12
+ }
13
+
14
+ public setMessage(message: string): ServiceException {
15
+ this.message = message
16
+ return this
17
+ }
18
+
19
+ public getCode(): number | undefined {
20
+ return this.code
21
+ }
22
+ }
@@ -0,0 +1,52 @@
1
+ import JSONObject from '../instances/JSONObject'
2
+
3
+ export default class JSONArray {
4
+ innerList: Array<any>
5
+
6
+ constructor(value?: any) {
7
+ if (value && typeof value === 'string') {
8
+ this.innerList = JSON.parse(value).map((item: any) => this.wrapValue(item))
9
+ }
10
+ else if (value && Array.isArray(value)) {
11
+ this.innerList = value.map((item: any) => this.wrapValue(item))
12
+ }
13
+ else {
14
+ this.innerList = new Array<any>()
15
+ }
16
+ }
17
+
18
+ private wrapValue(value: any): any {
19
+ if (Array.isArray(value)) {
20
+ return new JSONArray(value)
21
+ }
22
+ else if (value && JSONObject.isPlainObject(value)) {
23
+ return new JSONObject(value)
24
+ }
25
+ return value
26
+ }
27
+
28
+ public length(): number {
29
+ return this.innerList.length
30
+ }
31
+
32
+ public put(item: any) {
33
+ this.innerList.push(this.wrapValue(item))
34
+ }
35
+
36
+ public get(index: number): any {
37
+ return this.innerList[index]
38
+ }
39
+
40
+ public toString(): string {
41
+ const replacer = (key: string, value: any): any => {
42
+ if (value instanceof JSONObject) {
43
+ return value.innerMap
44
+ }
45
+ else if (value instanceof JSONArray) {
46
+ return value.innerList
47
+ }
48
+ return value
49
+ }
50
+ return JSON.stringify(this.innerList, replacer)
51
+ }
52
+ }
@@ -0,0 +1,118 @@
1
+ import JSONArray from '../instances/JSONArray'
2
+
3
+ export default class JSONObject {
4
+ innerMap: { [key: string]: any }
5
+
6
+ constructor(value?: any) {
7
+ let map: { [key: string]: any }
8
+ if (value && typeof value === 'string') {
9
+ map = JSON.parse(value)
10
+ }
11
+ else if (value && typeof value === 'object' && !Array.isArray(value)) {
12
+ map = {}
13
+ const keySet = value instanceof JSONObject ? value.keySet() : Object.keys(value)
14
+ for (const key of keySet) {
15
+ const item = value instanceof JSONObject ? value.get(key) : value[key]
16
+ if (Array.isArray(item)) {
17
+ map[key] = new JSONArray(item)
18
+ }
19
+ else if (JSONObject.isPlainObject(item)) {
20
+ map[key] = new JSONObject(item)
21
+ }
22
+ else {
23
+ map[key] = item
24
+ }
25
+ }
26
+ }
27
+ else {
28
+ map = {}
29
+ }
30
+ this.innerMap = map
31
+ }
32
+
33
+ public static isPlainObject(value: any): boolean {
34
+ if (!value || typeof value !== 'object')
35
+ return false
36
+ if (value instanceof JSONObject || value instanceof JSONArray) {
37
+ return false
38
+ }
39
+ const proto = Object.getPrototypeOf(value)
40
+ return proto === Object.prototype || proto === null
41
+ }
42
+
43
+ public put(key: string, value: any) {
44
+ if (Array.isArray(value)) {
45
+ this.innerMap[key] = new JSONArray(value)
46
+ }
47
+ else if (JSONObject.isPlainObject(value)) {
48
+ this.innerMap[key] = new JSONObject(value)
49
+ }
50
+ else {
51
+ this.innerMap[key] = value
52
+ }
53
+ }
54
+
55
+ public get(key: string): any {
56
+ return this.innerMap[key]
57
+ }
58
+
59
+ public opt(key: string): any {
60
+ return key == null ? null : this.innerMap[key]
61
+ }
62
+
63
+ public optString(key: string, defaultValue: string): string {
64
+ const result = this.opt(key)
65
+ return result || defaultValue
66
+ }
67
+
68
+ public getBoolean(key: string): boolean {
69
+ const object = this.get(key)
70
+ if (typeof object === 'boolean') {
71
+ return object as boolean
72
+ }
73
+ else {
74
+ return Boolean(object)
75
+ }
76
+ }
77
+
78
+ public optBoolean(key: string, defaultValue: boolean): boolean {
79
+ const val = this.opt(key)
80
+ if (!val) {
81
+ return defaultValue
82
+ }
83
+ return this.getBoolean(key)
84
+ }
85
+
86
+ public getInt(key: string): number {
87
+ return this.innerMap[key] as number
88
+ }
89
+
90
+ public getJSONObject(key: string): JSONObject {
91
+ return this.innerMap[key] as JSONObject
92
+ }
93
+
94
+ public getJSONArray(key: string): JSONArray {
95
+ return this.innerMap[key] as JSONArray
96
+ }
97
+
98
+ public has(key: string): boolean {
99
+ return Object.prototype.hasOwnProperty.call(this.innerMap, key)
100
+ }
101
+
102
+ public keySet(): string[] {
103
+ return Object.keys(this.innerMap)
104
+ }
105
+
106
+ public toString(): string {
107
+ const replacer = (key: string, value: any): any => {
108
+ if (value instanceof JSONObject) {
109
+ return value.innerMap
110
+ }
111
+ else if (value instanceof JSONArray) {
112
+ return value.innerList
113
+ }
114
+ return value
115
+ }
116
+ return JSON.stringify(this.innerMap, replacer)
117
+ }
118
+ }
@@ -0,0 +1,31 @@
1
+ // 自定义 Console 类
2
+ export default class LogicConsole {
3
+ public debug(...args: any[]): void {
4
+ const newArgs = this.convert(args)
5
+ console.info(...newArgs)
6
+ }
7
+
8
+ public info(...args: any[]): void {
9
+ const newArgs = this.convert(args)
10
+ console.info(...newArgs)
11
+ }
12
+
13
+ public warn(...args: any[]): void {
14
+ const newArgs = this.convert(args)
15
+ console.warn(...newArgs)
16
+ }
17
+
18
+ public error(...args: any[]): void {
19
+ const newArgs = this.convert(args)
20
+ console.error(...newArgs)
21
+ }
22
+
23
+ private convert(args: any[]): any[] {
24
+ return args.map((arg) => {
25
+ if (typeof arg === 'object' && arg !== null && typeof arg.toString === 'function') {
26
+ return arg.toString()
27
+ }
28
+ return arg
29
+ })
30
+ }
31
+ }
@@ -0,0 +1,67 @@
1
+ import ServiceException from '@af-mobile-client-vue3/expression/exception/ServiceException'
2
+ import ExpressionRunner from '@af-mobile-client-vue3/expression/ExpressionRunner'
3
+ import JSONObject from '@af-mobile-client-vue3/expression/instances/JSONObject'
4
+ import LogicConsole from '@af-mobile-client-vue3/expression/instances/LogicConsole'
5
+ import { indexedDB } from '@af-mobile-client-vue3/utils/indexedDB'
6
+
7
+ export default class LogicRunner {
8
+ private static logicConsoleInstance: LogicConsole = new LogicConsole()
9
+
10
+ /**
11
+ * 是否存在指定名称的Logic资源
12
+ *
13
+ * @param logicName Logic名称
14
+ * @return 是否存在
15
+ */
16
+ public static has(logicName: string): boolean {
17
+ return LogicRunner.getLogic(logicName, false, (result: any) => {
18
+ return result != null
19
+ })
20
+ }
21
+
22
+ /**
23
+ * 执行Logic
24
+ *
25
+ * @param logicName Logic名称
26
+ * @param param 参数
27
+ * @return 执行结果
28
+ */
29
+ public static run(logicName: string, param: JSONObject | object): any {
30
+ // 获取Logic资源
31
+ const source = LogicRunner.getLogic(logicName, false, (result: any) => {
32
+ return result
33
+ })
34
+ if (source == null) {
35
+ throw new ServiceException(`Logic资源${logicName}未找到`, 400)
36
+ }
37
+ LogicRunner.logicConsoleInstance.info('执行Logic[{}],params: {}', logicName, param)
38
+ // 附加用户注册的对象到业务逻辑中
39
+ const plugins = new JSONObject()
40
+ plugins.put('data', param)
41
+ plugins.put('log', LogicRunner.logicConsoleInstance)
42
+ plugins.put('logic', LogicRunner.prototype)
43
+ return LogicRunner.runExpression(source, plugins)
44
+ }
45
+
46
+ /**
47
+ * 执行原生表达式
48
+ *
49
+ * @param source 表达式内容
50
+ * @param params 参数
51
+ * @return 执行结果
52
+ */
53
+ public static runExpression(source: string, params: JSONObject): any {
54
+ return ExpressionRunner.run(source, params)
55
+ }
56
+
57
+ private static getLogic(logicName: string, isDev: boolean, callback: Function): any {
58
+ let apiPre = '/api/'
59
+ if (isDev) {
60
+ apiPre = '/devApi/'
61
+ }
62
+ // eslint-disable-next-line node/prefer-global/process
63
+ const serviceName = process.env.VUE_APP_SYSTEM_NAME
64
+ const getConfigUrl = `${apiPre + serviceName}/logic/openapi/getLiuliConfiguration`
65
+ indexedDB.getByWeb(logicName, getConfigUrl, { configName: logicName }, callback, undefined)
66
+ }
67
+ }
@@ -0,0 +1,13 @@
1
+ import LogicRunner from './LogicRunner'
2
+
3
+ testLogicCall()
4
+
5
+ /**
6
+ * testLogicCall
7
+ */
8
+ function testLogicCall() {
9
+ const result = LogicRunner.run('testVueLogic', {
10
+ test: '1',
11
+ })
12
+ console.info(result)
13
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * 日期工具类
3
+ */
4
+ export default class DateTools {
5
+ static instance = new DateTools()
6
+
7
+ constructor() {
8
+ if (DateTools.instance) {
9
+ return DateTools.instance
10
+ }
11
+ DateTools.instance = this
12
+ }
13
+
14
+ static getInstance() {
15
+ if (!DateTools.instance) {
16
+ DateTools.instance = new DateTools()
17
+ }
18
+ return DateTools.instance
19
+ }
20
+
21
+ /**
22
+ * 获取当前时间
23
+ * @returns {string} yyyy-MM-dd HH:mm:ss
24
+ */
25
+ getNow2() {
26
+ const now = new Date()
27
+ const year = now.getFullYear()
28
+ const month = String(now.getMonth() + 1).padStart(2, '0') // 月份从 0 开始,所以要 +1
29
+ const day = String(now.getDate()).padStart(2, '0')
30
+ const hours = String(now.getHours()).padStart(2, '0')
31
+ const minutes = String(now.getMinutes()).padStart(2, '0')
32
+ const seconds = String(now.getSeconds()).padStart(2, '0')
33
+ return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`
34
+ }
35
+ }
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Vue工具类
3
+ */
4
+ export default class VueTools {
5
+ static instance = new VueTools()
6
+
7
+ constructor() {
8
+ if (VueTools.instance) {
9
+ return VueTools.instance
10
+ }
11
+ VueTools.instance = this
12
+ }
13
+
14
+ static getInstance() {
15
+ if (!VueTools.instance) {
16
+ VueTools.instance = new VueTools()
17
+ }
18
+ return VueTools.instance
19
+ }
20
+
21
+ /**
22
+ * 获取组件实例
23
+ * @param vueRef vue实例
24
+ * @param componentName 组件实例名(refName)
25
+ * @returns {VueComponent}
26
+ */
27
+ getComponent(vueRef, componentName) {
28
+ return vueRef.$refs[componentName]
29
+ }
30
+ }
@@ -0,0 +1,7 @@
1
+ import DateTools from '@af-mobile-client-vue3/logic/plugins/common/DateTools'
2
+ import VueTools from '@af-mobile-client-vue3/logic/plugins/common/VueTools'
3
+
4
+ export default {
5
+ dateTools: DateTools.getInstance(),
6
+ vueTools: VueTools.getInstance(),
7
+ }