提交 27387af1 编写于 作者: fxy060608's avatar fxy060608

fix(app): attribute support json types

上级 a53b4733
......@@ -6000,11 +6000,11 @@ var serviceContext = (function (vue) {
this.webview = webview;
}
sendMessage(data) {
const message = {
const message = JSON.parse(JSON.stringify({
__message: {
data,
},
};
}));
const id = this.webview.id;
if (BroadcastChannel_) {
const channel = new BroadcastChannel_(id);
......
import { hasOwn } from '@vue/shared'
import { hasOwn, isString } from '@vue/shared'
import {
App,
Component,
......@@ -15,6 +15,8 @@ import { createWrapper, UniCustomElement } from '.'
import { $, removeElement } from '../page'
import { queuePostActionJob } from '../scheduler'
const JSON_PREFIX = '$JSON$:'
const JSON_PREFIX_LEN = JSON_PREFIX.length
export class UniComponent extends UniNode {
declare $: UniCustomElement
protected $props!: Record<string, any>
......@@ -80,6 +82,9 @@ export class UniComponent extends UniNode {
this.$props[name] = null
}
setAttr(name: string, value: unknown) {
if (isString(value) && value.indexOf(JSON_PREFIX) === 0) {
value = JSON.parse(value.substr(JSON_PREFIX_LEN))
}
this.$props[name] = value
}
removeAttr(name: string) {
......
......@@ -11114,11 +11114,29 @@ export default function vueFactory(exports) {
invoker.modifiers = [...modifiers];
return invoker;
} // fixed by xxxxxx 不强制更新value,否则即使不变,也会从 service 同步到 view 中
}
var forcePatchProps = {
AD: ['data'],
'AD-DRAW': ['data'],
'LIVE-PLAYER': ['picture-in-picture-mode'],
MAP: ['markers', 'polyline', 'circles', 'controls', 'include-points', 'polygons'],
PICKER: ['range', 'value'],
'PICKER-VIEW': ['value'],
'RICH-TEXT': ['nodes'],
VIDEO: ['danmu-list', 'header'],
'WEB-VIEW': ['webview-styles']
};
var forcePatchProp = (_, key) => false; // key === 'value'
var forcePatchProp = (_, key) => {
var keys = forcePatchProps[_.nodeName];
if (keys && keys.indexOf(key) > -1) {
return true;
}
return false;
};
var patchProp = (el, key, prevValue, nextValue, parentComponent) => {
switch (key) {
......@@ -11138,6 +11156,16 @@ export default function vueFactory(exports) {
patchEvent(el, key, prevValue, nextValue);
}
} else {
if (isProxy(nextValue)) {
var equal = prevValue === nextValue; // 触发收集最新依赖
nextValue = '$JSON$:' + JSON.stringify(nextValue);
if (equal && el.getAttribute(key) === nextValue) {
return;
}
}
patchAttr(el, key, nextValue);
}
......
......@@ -9116,8 +9116,31 @@ function createInvoker(initialValue, instance) {
return invoker;
}
// fixed by xxxxxx 不强制更新value,否则即使不变,也会从 service 同步到 view 中
const forcePatchProp = (_, key) => false; // key === 'value'
const forcePatchProps = {
AD: ['data'],
'AD-DRAW': ['data'],
'LIVE-PLAYER': ['picture-in-picture-mode'],
MAP: [
'markers',
'polyline',
'circles',
'controls',
'include-points',
'polygons'
],
PICKER: ['range', 'value'],
'PICKER-VIEW': ['value'],
'RICH-TEXT': ['nodes'],
VIDEO: ['danmu-list', 'header'],
'WEB-VIEW': ['webview-styles']
};
const forcePatchProp = (_, key) => {
const keys = forcePatchProps[_.nodeName];
if (keys && keys.indexOf(key) > -1) {
return true;
}
return false;
};
const patchProp = (el, key, prevValue, nextValue, parentComponent) => {
switch (key) {
// special
......@@ -9135,6 +9158,14 @@ const patchProp = (el, key, prevValue, nextValue, parentComponent) => {
}
}
else {
if (isProxy(nextValue)) {
const equal = prevValue === nextValue;
// 触发收集最新依赖
nextValue = '$JSON$:' + JSON.stringify(nextValue);
if (equal && el.getAttribute(key) === nextValue) {
return;
}
}
patchAttr(el, key, nextValue);
}
break;
......
......@@ -4843,17 +4843,18 @@ function useProvideRadioGroup(props2, trigger) {
}
});
const uniForm = vue.inject(uniFormKey, false);
if (uniForm) {
uniForm.addField({
submit: () => {
let data = ["", null];
if (props2.name !== "") {
data[0] = props2.name;
data[1] = getFieldsValue();
}
return data;
const formField = {
submit: () => {
let data = ["", null];
if (props2.name !== "") {
data[0] = props2.name;
data[1] = getFieldsValue();
}
});
return data;
}
};
if (uniForm) {
uniForm.addField(formField);
}
function setFieldChecked(field, radioChecked) {
field.value = {
......
......@@ -11052,16 +11052,20 @@ function useProvideRadioGroup(props2, trigger) {
}
});
const uniForm = inject(uniFormKey, false);
if (uniForm) {
uniForm.addField({
submit: () => {
let data = ["", null];
if (props2.name !== "") {
data[0] = props2.name;
data[1] = getFieldsValue();
}
return data;
const formField = {
submit: () => {
let data = ["", null];
if (props2.name !== "") {
data[0] = props2.name;
data[1] = getFieldsValue();
}
return data;
}
};
if (uniForm) {
uniForm.addField(formField);
onBeforeUnmount(() => {
uniForm.removeField(formField);
});
}
function setFieldChecked(field, radioChecked) {
......
......@@ -19,3 +19,5 @@ export function initApp(app: App) {
globalProperties.$applyOptions = applyOptions
}
}
export { traverse } from './reactivity'
import { isObject, isArray, isMap, isSet, isPlainObject } from '@vue/shared'
import { isRef } from 'vue'
export function traverse(value: unknown, seen: Set<unknown> = new Set()) {
if (!isObject(value) || seen.has(value) || (value as any)['__v_skip']) {
return value
}
seen.add(value)
if (isRef(value)) {
traverse(value.value, seen)
} else if (isArray(value)) {
for (let i = 0; i < value.length; i++) {
traverse(value[i], seen)
}
} else if (isSet(value) || isMap(value)) {
value.forEach((v: any) => {
traverse(v, seen)
})
} else if (isPlainObject(value)) {
for (const key in value) {
traverse((value as any)[key], seen)
}
}
return value
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册