waibu-mpa 2.13.2 → 2.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/class/widget.js +46 -1
- package/package.json +1 -1
- package/wiki/CHANGES.md +8 -0
package/lib/class/widget.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import path from 'path'
|
|
2
2
|
|
|
3
3
|
async function widgetFactory () {
|
|
4
|
-
const { kebabCase } = this.app.lib._
|
|
4
|
+
const { kebabCase, get } = this.app.lib._
|
|
5
|
+
|
|
5
6
|
class MpaWidget extends this.app.baseClass.MpaTools {
|
|
6
7
|
static scripts = []
|
|
7
8
|
static css = []
|
|
@@ -21,6 +22,9 @@ async function widgetFactory () {
|
|
|
21
22
|
this.params = params
|
|
22
23
|
this.block = {}
|
|
23
24
|
this.setting = this._parseBase64Attr(this.params.attr.setting)
|
|
25
|
+
this.formData = get(this, `component.locals.${this.params.attr.keyLocals ?? 'form'}`, {})
|
|
26
|
+
this.oldData = get(this, `component.locals.${this.params.attr.keyOldData ?? 'oldData'}`, {})
|
|
27
|
+
this.schema = get(this, `component.locals.${this.params.attr.keySchema ?? 'schema'}`, {})
|
|
24
28
|
}
|
|
25
29
|
|
|
26
30
|
_parseBase64Attr = (text, defValue = {}) => {
|
|
@@ -93,6 +97,47 @@ async function widgetFactory () {
|
|
|
93
97
|
if (!escape) return content
|
|
94
98
|
return content.replaceAll("'", "\\'")
|
|
95
99
|
}
|
|
100
|
+
|
|
101
|
+
getProp = (name) => {
|
|
102
|
+
const { find } = this.app.lib._
|
|
103
|
+
const prop = find(this.schema.properties ?? [], { name }) ?? {}
|
|
104
|
+
return prop
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
getRef = ({ field, refName, returning } = {}) => {
|
|
108
|
+
const { get, find } = this.app.lib._
|
|
109
|
+
const prop = find(this.schema.properties ?? [], p => p.name === field)
|
|
110
|
+
if (!prop) return {}
|
|
111
|
+
if (!refName && field.endsWith('Id')) refName = field.slice(0, -2)
|
|
112
|
+
const key = this.params.attr.refName ?? refName
|
|
113
|
+
const ref = get(prop, `ref.${key}`, {})
|
|
114
|
+
if (returning === 'all') return { ref, key }
|
|
115
|
+
else if (returning === 'key') return key
|
|
116
|
+
return ref
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
getRefValue = ({ field, data, labelField, refName } = {}) => {
|
|
120
|
+
const { get, isEmpty } = this.app.lib._
|
|
121
|
+
const { ref, key } = this.getRef({ field, refName, returning: 'all' })
|
|
122
|
+
if (isEmpty(ref)) return undefined
|
|
123
|
+
labelField = labelField ?? ref.labelField ?? 'id'
|
|
124
|
+
return (get(data ?? this.formData, `_ref.${key}.${labelField}`))
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
getRefName = (field) => {
|
|
128
|
+
const { get } = this.app.lib._
|
|
129
|
+
let refName = get(this.schema, `view.widget.${field}.attr.ref-name`, this.params.attr.refName)
|
|
130
|
+
if (!refName && this.params.attr[field] && this.params.attr[field].endsWith('Id')) refName = this.params.attr[field].slice(0, -2)
|
|
131
|
+
return refName
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
getSetting = (key, defValue) => {
|
|
135
|
+
const { get, camelCase } = this.app.lib._
|
|
136
|
+
const widgetName = camelCase(this.constructor.name)
|
|
137
|
+
key = key.replaceAll('{self}', widgetName)
|
|
138
|
+
const cfg = this.app.waibu.getSetting(`${this.plugin.ns}:${key}`, { defValue, req: this.component.req })
|
|
139
|
+
return get(this.schema, `view.${key}`, cfg)
|
|
140
|
+
}
|
|
96
141
|
}
|
|
97
142
|
|
|
98
143
|
this.app.baseClass.MpaWidget = MpaWidget
|
package/package.json
CHANGED
package/wiki/CHANGES.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Changes
|
|
2
2
|
|
|
3
|
+
## 2026-04-17
|
|
4
|
+
|
|
5
|
+
- [2.14.0] Add data binding properties to ```Widget``` base class
|
|
6
|
+
- [2.14.0] Add ```Widget.getRef()```
|
|
7
|
+
- [2.14.0] Add ```Widget.getRefValue()```
|
|
8
|
+
- [2.14.0] Add ```Widget.getRefName()```
|
|
9
|
+
- [2.14.0] Add ```Widget.getSetting()```
|
|
10
|
+
|
|
3
11
|
## 2026-04-11
|
|
4
12
|
|
|
5
13
|
- [2.13.2] Bug fix in ```Wmpa.parseValue()```
|