yuang-framework-ui-pc
Version:
yuang-framework-ui-pc Library
125 lines (124 loc) • 4.67 kB
JavaScript
import { defineComponent, mergeModels, useModel, ref, computed, watch, resolveComponent, createElementBlock, openBlock, Fragment, createBlock, createCommentVNode, unref } from "vue";
import { EleMessage } from "../utils/message";
import RoleDialog from "./components/role-dialog";
import { Select } from "@element-plus/icons-vue";
import { http } from "yuang-framework-ui-common/lib/config/httpConfig";
import { application } from "yuang-framework-ui-common/lib/config/applicationConfig";
const _sfc_main = /* @__PURE__ */ defineComponent({
...{ name: "YuUimsRoleDialog" },
__name: "index",
props: /* @__PURE__ */ mergeModels({
param: { default: {} }
}, {
"modelValue": {},
"modelModifiers": {}
}),
emits: /* @__PURE__ */ mergeModels(["change"], ["update:modelValue"]),
setup(__props, { expose: __expose, emit: __emit }) {
const props = __props;
const emit = __emit;
const modelValue = useModel(__props, "modelValue");
const initList = ref([]);
const inputValue = ref("");
const isShowDialog = ref(false);
const isInitSuccess = ref(false);
const componentParam = computed(() => ({
modelValue: modelValue.value,
isMultiple: true,
isShowInput: true,
// 是否禁止选择已存在的用户
isDisableSelectExistsUser: true,
...props.param,
initList: initList.value
}));
const init = async () => {
if (modelValue.value) {
if (!componentParam.value.isMultiple) {
if (modelValue.value != "0") {
let res = await http.get(`${application.gatewayServerBaseUrl}/uims-api/admin/uims-role/selectInfo`, { params: { id: modelValue.value } });
const info = res.data.data;
inputValue.value = info.name;
initList.value = [info];
}
} else {
let idList = modelValue.value.split("|").filter((item) => item.trim() !== "");
if (idList.length > 0) {
let res = await http.post(`${application.gatewayServerBaseUrl}/uims-api/admin/uims-role/selectInfoList`, idList);
const infoList = res.data.data;
let names = "";
for (let index in infoList) {
names += infoList[index].name + "、";
}
inputValue.value = names.substring(0, names.length - 1);
initList.value = infoList;
}
}
}
isInitSuccess.value = true;
};
const showDialog = () => {
isShowDialog.value = true;
};
const hideDialog = () => {
if (!isInitSuccess.value) {
EleMessage.warning("请等待初始化成功");
return;
}
isShowDialog.value = false;
};
const handleChange = (selections) => {
console.log("selections", selections);
modelValue.value = "";
inputValue.value = "";
if (selections.length > 0) {
if (!componentParam.value.isMultiple) {
modelValue.value = selections[0].id;
inputValue.value = selections[0].name;
} else {
let modelValueValue = "";
let inputValueValue = "";
for (let index in selections) {
modelValueValue += selections[index].id + "|";
inputValueValue += selections[index].name + "、";
}
modelValue.value = "|" + modelValueValue;
inputValue.value = inputValueValue.substring(0, inputValueValue.length - 1);
}
}
emit("change", selections);
hideDialog();
};
watch(
() => componentParam.value.modelValue,
() => {
init();
},
{ immediate: true }
);
__expose({
showDialog
});
return (_ctx, _cache) => {
const _component_el_input = resolveComponent("el-input");
return openBlock(), createElementBlock(Fragment, null, [
componentParam.value.isShowInput ? (openBlock(), createBlock(_component_el_input, {
key: 0,
modelValue: inputValue.value,
"onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => inputValue.value = $event),
"suffix-icon": unref(Select),
onClick: showDialog
}, null, 8, ["modelValue", "suffix-icon"])) : createCommentVNode("", true),
isShowDialog.value ? (openBlock(), createBlock(RoleDialog, {
key: 1,
modelValue: isShowDialog.value,
"onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => isShowDialog.value = $event),
param: componentParam.value,
onChange: handleChange
}, null, 8, ["modelValue", "param"])) : createCommentVNode("", true)
], 64);
};
}
});
export {
_sfc_main as default
};