修改字典 0 的错误问题

This commit is contained in:
神仙都没用 2023-11-10 18:16:09 +08:00
parent 0a58a05d86
commit 4efb765721
3 changed files with 58 additions and 18 deletions

View File

@ -16,6 +16,9 @@
<!-- 刷新按钮 -->
<cl-refresh-btn />
<!-- 全选 -->
<el-button type="primary" @click="selectAll">全选</el-button>
<cl-filter label="状态">
<cl-select :options="options.status" prop="status" :width="120" />
</cl-filter>
@ -27,11 +30,11 @@
<cl-row>
<!-- 数据表格 -->
<cl-table ref="Table" :auto-height="false" />
<cl-table ref="Table" :auto-height="false" @selection-change="onSelectionChange" />
</cl-row>
<cl-row>
<span>已选 {{ Table?.selection.length }} </span>
<span>已选 {{ selection.length }} </span>
<cl-flex1 />
<!-- 分页控件 -->
<cl-pagination />
@ -48,12 +51,15 @@
<script lang="ts" setup name="select-user">
import { useCrud, useForm, useTable } from "@cool-vue/crud";
import { useCool } from "/@/cool";
import { nextTick, reactive, ref, watch } from "vue";
import { PropType, nextTick, reactive, ref, watch } from "vue";
import { cloneDeep } from "lodash";
//
type Item = Eps.BaseSysUserEntity;
const props = defineProps({
modelValue: {
type: Array,
type: Array as PropType<Item[]>,
default: () => []
},
isDisabled: Boolean,
@ -134,7 +140,10 @@ const Table = useTable({
const Crud = useCrud({
service: service.base.sys.user,
async onRefresh(params, { next }) {
await next(params);
const res = await next(params);
// id
loadIds.value.push(...res.list.map((e) => e.id));
//
list.value.forEach((e) => {
@ -155,16 +164,37 @@ async function refresh(params?: any) {
//
const visible = ref(false);
//
const list = ref<Item[]>([]);
//
const list = ref<Eps.BaseSysUserEntity[]>([]);
const selection = ref<any[]>([]);
// id
const loadIds = ref<number[]>([]);
//
function onSelectionChange(arr: Item[]) {
//
const ids = Array.from(new Set(loadIds.value));
//
selection.value = selection.value.filter((e) => !ids.includes(e.id!)).concat(...arr);
}
//
function open() {
visible.value = true;
//
loadIds.value = [];
//
selection.value = cloneDeep(list.value);
nextTick(() => {
refresh({
size: 10
size: 2
});
});
}
@ -176,7 +206,20 @@ function close() {
//
function select() {
list.value = cloneDeep(Table.value?.selection || []);
list.value = cloneDeep(selection.value || []);
close();
}
//
async function selectAll() {
//
await Crud.value?.service.page({ page: 1, size: 10000 }).then((res) => {
list.value = res.list;
});
//
// list.value = Table.value?.data || [];
close();
}

View File

@ -102,7 +102,7 @@
<script lang="tsx" name="demo-crud" setup>
import { useCrud, useUpsert, useTable, useAdvSearch, setFocus, useSearch } from "@cool-vue/crud";
import { useDict } from "/$/dict";
import { reactive } from "vue";
import { onMounted, reactive } from "vue";
import { ElMessage, ElMessageBox } from "element-plus";
import { useCool } from "/@/cool";
import FormBtn from "../components/form-btn.vue";
@ -255,9 +255,12 @@ const Upsert = useUpsert({
}
},
{
label: "选择用户",
label: "",
prop: "userIds",
group: "select",
props: {
labelWidth: "0px"
},
component: {
name: "slot-userIds"
}
@ -267,9 +270,6 @@ const Upsert = useUpsert({
label: "工作",
prop: "occupation",
group: "other",
hook: {
bind: "string"
},
component: {
name: "el-tree-select",
props: {
@ -420,10 +420,7 @@ const Table = useTable({
prop: "occupation",
dict: dict.get("occupation"),
dictColor: true,
minWidth: 120,
formatter(row) {
return String(row.occupation);
}
minWidth: 120
},
{
label: "状态",

View File

@ -34,7 +34,7 @@ const useDictStore = defineStore("dict", () => {
for (const [i, arr] of Object.entries(res)) {
arr.forEach((e) => {
e.label = e.name;
e.value = e.value || e.id;
e.value = e.value ?? e.id;
});
d[i] = deepTree(arr, "desc");