@sepveneto/mpd-core
Version:
## 安装 ```cmd pnpm i @sepveneto/mpd-core npm i @sepveneto/mpd-core yarn add @sepveneto/mpd-core ```
139 lines (136 loc) • 3.1 kB
JavaScript
import {
initEmitter
} from "./chunk-GWZNWPBX.js";
import {
__async,
__spreadValues
} from "./chunk-SW7HDZD2.js";
// src/vue/Editor.ts
import { defineComponent, h, onMounted, ref, watchEffect } from "vue-demi";
import microApp, { renderApp } from "@micro-zoe/micro-app";
var Editor_default = defineComponent({
props: {
name: {
type: String,
default: "miniprogram-design"
},
url: {
type: String,
required: true
},
inline: Boolean,
modelValue: {
type: Object,
default: () => ({
globalConfig: {},
body: {}
})
},
upload: {
type: Function,
default: () => ({})
},
remoteUrl: {
type: String,
required: true
},
schema: {
type: Object,
default: () => ({})
},
widgets: {
type: Array,
default: () => []
},
routes: {
type: Array,
default: () => [{ name: "Home", path: "/" }]
},
settings: {
type: Object,
default: () => ({})
},
extra: {
type: Object,
default: () => ({})
}
},
emits: [
"mounted",
"delete",
"change",
"update:modelValue",
"selected"
],
expose: ["clearSelected"],
setup(props, { emit, expose }) {
const isPrepare = ref(false);
microApp.addDataListener(props.name, (val) => {
const { event } = val;
if (event === "mounted") {
emit("mounted");
isPrepare.value = true;
}
});
onMounted(() => {
renderApp({
name: props.name,
url: props.url,
container: `#${props.name}`,
inline: props.inline,
"disable-patch-request": true,
// 关闭对子应用请求的拦截
"disable-memory-router": true,
// 关闭虚拟路由
data: __spreadValues({
upload: props.upload,
remoteUrl: props.remoteUrl
}, props.extra)
});
});
const { appEvent } = initEmitter({
SET_CONFIG(val) {
emit("update:modelValue", val);
emit("change", val);
},
SET_SELECTED(val) {
emit("selected", val);
},
SET_DELETE(val) {
emit("delete", val);
}
});
watchEffect(() => {
isPrepare.value && setData("SET_WIDGETS", props.widgets);
});
watchEffect(() => {
isPrepare.value && setData("SET_REMOTE_URL", props.remoteUrl);
});
watchEffect(() => {
isPrepare.value && setData("SET_SETTINGS", props.settings);
});
watchEffect(() => {
isPrepare.value && setData("SET_SCHEMA", props.schema);
});
watchEffect(() => {
isPrepare.value && setData("SET_ROUTES", props.routes);
});
watchEffect(() => {
isPrepare.value && setData("SET_CONFIG", props.modelValue);
});
function setData(name, data) {
return __async(this, null, function* () {
appEvent.emit(name, data);
});
}
expose({
clearSelected() {
setData("CLEAR_SELECTED");
}
});
return () => h("div", { id: props.name });
}
});
export {
Editor_default
};