Ai
1 Star 2 Fork 1

旻天信息/mttk-vue-wrap

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
compBaseModelValue.ts 2.20 KB
一键复制 编辑 原始数据 按行查看 历史
旻天信息 提交于 2025-02-07 11:01 +08:00 . v0.3.1
import { computed, isRef, unref } from "vue";
import { getByPath, setByPath } from "./pathUtil";
import {WrapConfigType} from './types.ts'
export function buildModelValue(configStd:WrapConfigType) {
//Add modelValue if modelValue is configured
function tryApplyModelValue(all: any) {
if ( !configStd ||unref(configStd) == undefined){
return
}
//获取configStd可能的配置
tryApplyModelValueInternal(all,configStd)
//Check whether there is ~mvs
const mvs=unref(unref(configStd)['~mvs'])
if(!mvs||!Array.isArray(mvs)||mvs.length==0){
return
}
//
for(const c of mvs){
tryApplyModelValueInternal(all,c)
}
}
//
return {tryApplyModelValue };
}
//
function tryApplyModelValueInternal(all: any, configSingle: any) {
//whether modelValue is configured.If not, do not build modelValue otherwise it may have unexpected result
if (
!configSingle ||
unref(configSingle) == undefined ||
! (unref(configSingle).hasOwnProperty("~modelValue"))
) {
return;
}
//modelValue
const modelValue = computed({
get() {
let modelValuePath = unref(configSingle)["~modelValuePath"];
if (modelValuePath) {
return getByPath(
unref(unref(configSingle)["~modelValue"]),
modelValuePath
);
} else {
return unref(unref(configSingle)["~modelValue"]);
}
},
set(valueNew) {
//
let modelValuePath = unref(configSingle)["~modelValuePath"];
if (modelValuePath) {
setByPath(
unref(unref(configSingle)["~modelValue"]),
modelValuePath,
valueNew
);
} else {
if (isRef(unref(configSingle)["~modelValue"])) {
unref(configSingle)["~modelValue"].value = valueNew;
} else {
unref(configSingle)["~modelValue"] = valueNew;
}
}
},
});
//modelValueName
const modelValueName = computed(() => {
//
return unref(configSingle)["~modelValueName"] || "modelValue";
});
//Add model value related properties
all[modelValueName.value] = modelValue.value,
all["onUpdate:" + modelValueName.value] = (value: any) => {
modelValue.value = value;
}
//
return modelValue
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
TypeScript
1
https://gitee.com/jamie0828/mttk-vue-wrap.git
git@gitee.com:jamie0828/mttk-vue-wrap.git
jamie0828
mttk-vue-wrap
mttk-vue-wrap
master

搜索帮助