@mixd-id/web-scaffold 0.1.2301231349 → 0.1.2301231351
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/package.json +1 -1
- package/src/index.js +47 -0
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -129,6 +129,52 @@ const popPreloads = () => {
|
|
|
129
129
|
return link
|
|
130
130
|
}
|
|
131
131
|
|
|
132
|
+
const util = {
|
|
133
|
+
|
|
134
|
+
push: (arr, item, opt = { key:"id" }) => {
|
|
135
|
+
const index = arr.findIndex((_) => _[opt.key] === item[opt.key])
|
|
136
|
+
if(index >= 0){
|
|
137
|
+
Object.assign(arr[index], item)
|
|
138
|
+
}
|
|
139
|
+
else{
|
|
140
|
+
arr.push(item)
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
|
|
144
|
+
onEvent: (arr, updates, opt = {}) => {
|
|
145
|
+
|
|
146
|
+
const [ model, event, items ] = updates
|
|
147
|
+
|
|
148
|
+
if(opt.model && opt.model !== model)
|
|
149
|
+
return
|
|
150
|
+
|
|
151
|
+
items.forEach((item) => {
|
|
152
|
+
|
|
153
|
+
const index = arr.findIndex((_) => _.id === item.id)
|
|
154
|
+
|
|
155
|
+
switch(event){
|
|
156
|
+
|
|
157
|
+
case 'create':
|
|
158
|
+
case 'update':
|
|
159
|
+
if(index >= 0){
|
|
160
|
+
Object.assign(arr[index], item)
|
|
161
|
+
}
|
|
162
|
+
else{
|
|
163
|
+
arr.push(item)
|
|
164
|
+
}
|
|
165
|
+
break
|
|
166
|
+
|
|
167
|
+
case 'destroy':
|
|
168
|
+
if(index >= 0){
|
|
169
|
+
arr.splice(index, 1)
|
|
170
|
+
}
|
|
171
|
+
break
|
|
172
|
+
}
|
|
173
|
+
})
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
}
|
|
177
|
+
|
|
132
178
|
export default{
|
|
133
179
|
|
|
134
180
|
install: (app, options) => {
|
|
@@ -148,6 +194,7 @@ export default{
|
|
|
148
194
|
app.config.globalProperties.$download = download
|
|
149
195
|
app.config.globalProperties.$preload = preload
|
|
150
196
|
app.config.globalProperties.$popPreloads = popPreloads
|
|
197
|
+
app.config.globalProperties.$util = util
|
|
151
198
|
|
|
152
199
|
app.component('Alert', defineAsyncComponent(() => import("./components/Alert.vue")))
|
|
153
200
|
app.component('Button', defineAsyncComponent(() => import("./components/Button.vue")))
|