//@ts-nocheck import { defineComponent, h, reactive, markRaw, resolveComponent } from "vue"; import { DialogSourceCode } from "./DialogSourceCode"; import { defXVirTableConfigs, State_UI, xU, UI, compileVNode, defCol, $, defItem } from "@ventose/ui"; import App from "../App.vue"; import dayjs from "dayjs" export const DemoAndCode = defineComponent({ props: ["path", "title"], setup() { return { State_UI }; }, computed: { sfcURL() { return `${this.State_UI.assetsPath}${this.path}`; }, styleContainer() { return { position: "relative", overflow: this.isFold ? "hidden" : "unset", height: this.isFold ? "48px" : "unset" }; } }, data() { return { isInitDone: false, isFold: true, isLoading: true, BussinessComponent: false, BussinessComponentSourceCode: "" }; }, methods: { toggleFold() { this.isFold = !this.isFold; if (!this.isInitDone) { this.getBussinessComponent(); } }, async rerun(scfObjSourceCode) { /* TODO: 弹窗修改加载的代码 */ /* 重新运行 */ const _BussinessComponent = await xU.getVueComponentBySourceCode( this.sfcURL, scfObjSourceCode, new Proxy( { reactive, defineComponent, markRaw, State_UI, xU, UI, compileVNode, defXVirTableConfigs, defCol, $, defItem, resolveComponent, App, dayjs }, { get(target, prop) { if (target.hasOwnProperty(prop)) { return target[prop]; } if (xU[prop]) { return xU[prop]; } if (target.State_UI[prop]) { return target.State_UI[prop]; } } } ) ); this.BussinessComponent = markRaw(_BussinessComponent); this.isLoading = false; }, async getBussinessComponent() { this.BussinessComponentSourceCode = await xU.asyncLoadText(this.sfcURL); const scfObjSourceCode = xU.VueLoader(this.BussinessComponentSourceCode); this.rerun(scfObjSourceCode); }, showSourceCodeDialog() { UI.dialog.component({ title: this.path, component: DialogSourceCode, maxmin: true, fullscreen: true, area: ["500px", "400px"], code: `\`\`\`js ${this.BussinessComponentSourceCode} \`\`\``, hideButtons: true }); } }, render() { return (
{this.title || this.sfcURL}
{this.BussinessComponent ? h(this.BussinessComponent) : null}
); } });