feat(prop): lockList属性,禁止编辑已选项
This commit is contained in:
@ -2,13 +2,13 @@
|
|||||||
* @Author: zhaojinfeng 121016171@qq.com
|
* @Author: zhaojinfeng 121016171@qq.com
|
||||||
* @Date: 2023-08-14 11:07:15
|
* @Date: 2023-08-14 11:07:15
|
||||||
* @LastEditors: zhaojinfeng 121016171@qq.com
|
* @LastEditors: zhaojinfeng 121016171@qq.com
|
||||||
* @LastEditTime: 2023-08-16 11:11:30
|
* @LastEditTime: 2023-08-18 16:35:25
|
||||||
* @FilePath: \vue3\packages\select-transfer-modal\index.vue
|
* @FilePath: \vue3\packages\select-transfer-modal\index.vue
|
||||||
* @Description:
|
* @Description:
|
||||||
*
|
*
|
||||||
-->
|
-->
|
||||||
<template>
|
<template>
|
||||||
<span v-if="!hideButton" @click="open">
|
<span v-if="!hideButton" @click="openDialog">
|
||||||
<slot>
|
<slot>
|
||||||
<el-button type="primary" plain>点击选择</el-button>
|
<el-button type="primary" plain>点击选择</el-button>
|
||||||
</slot>
|
</slot>
|
||||||
@ -37,11 +37,20 @@
|
|||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-form>
|
</el-form>
|
||||||
<el-transfer
|
<el-transfer
|
||||||
v-model="transferValue" v-loading="loading" inline-block text-left
|
v-model="transferValue"
|
||||||
style="--el-transfer-panel-width:25vw" :titles="['待选项', '已选项']" :button-texts="['移除', '添加']" :format="{
|
v-loading="loading"
|
||||||
|
inline-block
|
||||||
|
text-left
|
||||||
|
style="--el-transfer-panel-width:25vw"
|
||||||
|
:titles="['待选项', '已选项']"
|
||||||
|
:button-texts="['移除', '添加']"
|
||||||
|
:format="{
|
||||||
noChecked: '${total}',
|
noChecked: '${total}',
|
||||||
hasChecked: '${checked}/${total}',
|
hasChecked: '${checked}/${total}',
|
||||||
}" :data="data" :filter-method="filterMethod" :props="props"
|
}"
|
||||||
|
:data="data"
|
||||||
|
:filter-method="filterMethod"
|
||||||
|
:props="props"
|
||||||
>
|
>
|
||||||
<template #default="{ option }">
|
<template #default="{ option }">
|
||||||
<slot name="transfer" :option="option">
|
<slot name="transfer" :option="option">
|
||||||
@ -90,6 +99,7 @@ const properties = withDefaults(
|
|||||||
width?: string | number
|
width?: string | number
|
||||||
zIndex?: number
|
zIndex?: number
|
||||||
props?: TransferPropsAlias
|
props?: TransferPropsAlias
|
||||||
|
lockList?: TransferKey[]
|
||||||
formattter?: (row: Record<string, any>) => any
|
formattter?: (row: Record<string, any>) => any
|
||||||
}>(),
|
}>(),
|
||||||
{
|
{
|
||||||
@ -117,12 +127,13 @@ const showDialog = ref(false)
|
|||||||
|
|
||||||
let transferValue = $ref<TransferKey[]>([])
|
let transferValue = $ref<TransferKey[]>([])
|
||||||
|
|
||||||
const temp = reactive({})
|
let temp = $ref({})
|
||||||
|
|
||||||
let currentIdList = $ref<any[]>([])
|
let currentKeyList = $ref<TransferKey[]>([])
|
||||||
|
|
||||||
function filterMethod(_query: string, item: TransferDataItem) {
|
function filterMethod(_query: string, item: TransferDataItem) {
|
||||||
return currentIdList.includes(item[properties.props.key]) || transferValue.includes(item[properties.props.key])
|
const { key = 'id' } = properties.props
|
||||||
|
return currentKeyList.includes(item[key]) || transferValue.includes(item[key])
|
||||||
}
|
}
|
||||||
|
|
||||||
const queryParams = reactive({
|
const queryParams = reactive({
|
||||||
@ -132,8 +143,13 @@ const queryParams = reactive({
|
|||||||
|
|
||||||
const data = computed(() => {
|
const data = computed(() => {
|
||||||
const all: any[] = []
|
const all: any[] = []
|
||||||
for (const key in temp)
|
const { props: { disabled = 'disabled', key = 'id' }, lockList } = properties
|
||||||
all.push(temp[key])
|
for (const i in temp) {
|
||||||
|
all.push({
|
||||||
|
...temp[i],
|
||||||
|
[disabled]: lockList?.includes(temp[i][key]),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
return all
|
return all
|
||||||
})
|
})
|
||||||
@ -143,7 +159,6 @@ let loading = $ref(false)
|
|||||||
|
|
||||||
/* 表单绑定的ref */
|
/* 表单绑定的ref */
|
||||||
const queryRef = $ref<FormInstance>(null)
|
const queryRef = $ref<FormInstance>(null)
|
||||||
|
|
||||||
/** 查询表格数据 */
|
/** 查询表格数据 */
|
||||||
async function getList() {
|
async function getList() {
|
||||||
loading = true
|
loading = true
|
||||||
@ -152,9 +167,10 @@ async function getList() {
|
|||||||
...properties.defaultParams,
|
...properties.defaultParams,
|
||||||
...queryParams,
|
...queryParams,
|
||||||
})
|
})
|
||||||
currentIdList = response.rows.map((e) => {
|
const { key = 'id' } = properties.props
|
||||||
temp[e[properties.props.key]] = e
|
currentKeyList = response.rows.map((e) => {
|
||||||
return e[properties.props.key]
|
temp[e[key]] = e
|
||||||
|
return e[key]
|
||||||
})
|
})
|
||||||
total = response.total
|
total = response.total
|
||||||
}
|
}
|
||||||
@ -162,7 +178,7 @@ async function getList() {
|
|||||||
loading = false
|
loading = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function open() {
|
function openDialog() {
|
||||||
if (properties.hideButton)
|
if (properties.hideButton)
|
||||||
emit('update:show', true)
|
emit('update:show', true)
|
||||||
else
|
else
|
||||||
@ -182,7 +198,7 @@ function confirm() {
|
|||||||
function closed() {
|
function closed() {
|
||||||
queryRef?.resetFields()
|
queryRef?.resetFields()
|
||||||
queryParams.pageNum = 1
|
queryParams.pageNum = 1
|
||||||
currentIdList = []
|
currentKeyList = []
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 重置按钮操作 */
|
/** 重置按钮操作 */
|
||||||
@ -199,12 +215,13 @@ function handleSizeChange(val: number) {
|
|||||||
|
|
||||||
function transferValueInit() {
|
function transferValueInit() {
|
||||||
const { value = [] } = properties
|
const { value = [] } = properties
|
||||||
|
const { key = 'id' } = properties.props
|
||||||
|
const newTemp = {}
|
||||||
transferValue = value.map((e) => {
|
transferValue = value.map((e) => {
|
||||||
temp[e[properties.props.key]] = e
|
newTemp[e[key]] = e
|
||||||
|
return e[key]
|
||||||
return e[properties.props.key]
|
|
||||||
})
|
})
|
||||||
|
temp = newTemp
|
||||||
}
|
}
|
||||||
|
|
||||||
transferValueInit()
|
transferValueInit()
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
* @Author: zhaojinfeng 121016171@qq.com
|
* @Author: zhaojinfeng 121016171@qq.com
|
||||||
* @Date: 2023-08-14 11:07:15
|
* @Date: 2023-08-14 11:07:15
|
||||||
* @LastEditors: zhaojinfeng 121016171@qq.com
|
* @LastEditors: zhaojinfeng 121016171@qq.com
|
||||||
* @LastEditTime: 2023-08-16 11:54:25
|
* @LastEditTime: 2023-08-18 16:45:45
|
||||||
* @FilePath: \vue3\stories\SelectTransferModal.stories.ts
|
* @FilePath: \vue3\stories\SelectTransferModal.stories.ts
|
||||||
* @Description:
|
* @Description:
|
||||||
*
|
*
|
||||||
@ -49,6 +49,7 @@ const meta = {
|
|||||||
title: '选择',
|
title: '选择',
|
||||||
width: '70%',
|
width: '70%',
|
||||||
zIndex: 2023,
|
zIndex: 2023,
|
||||||
|
lockList: undefined,
|
||||||
},
|
},
|
||||||
render: args => ({
|
render: args => ({
|
||||||
components: { ThSelectTransferModal },
|
components: { ThSelectTransferModal },
|
||||||
@ -61,6 +62,7 @@ const meta = {
|
|||||||
:form-items="args.formItems"
|
:form-items="args.formItems"
|
||||||
:default-params="args.defaultParams"
|
:default-params="args.defaultParams"
|
||||||
:hide-pagination="args.hidePagination"
|
:hide-pagination="args.hidePagination"
|
||||||
|
:lock-list="args.lockList"
|
||||||
:request="args.request"
|
:request="args.request"
|
||||||
:page-sizes="args.pageSizes"
|
:page-sizes="args.pageSizes"
|
||||||
:pager-count="args.pagerCount"
|
:pager-count="args.pagerCount"
|
||||||
@ -106,6 +108,28 @@ export const Data: Story = {
|
|||||||
render: meta.render,
|
render: meta.render,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const TransferLock: Story = {
|
||||||
|
name: '锁定已编辑项',
|
||||||
|
args: {
|
||||||
|
...Data.args,
|
||||||
|
value: [{
|
||||||
|
id: 1,
|
||||||
|
name: 'name1',
|
||||||
|
value: 'value1',
|
||||||
|
}, {
|
||||||
|
id: 12,
|
||||||
|
name: 'name12',
|
||||||
|
value: 'value12',
|
||||||
|
}, {
|
||||||
|
id: 33,
|
||||||
|
name: 'name33',
|
||||||
|
value: 'value33',
|
||||||
|
}],
|
||||||
|
lockList: [1, 12, 33],
|
||||||
|
},
|
||||||
|
render: meta.render,
|
||||||
|
}
|
||||||
|
|
||||||
export const TransferSlot: Story = {
|
export const TransferSlot: Story = {
|
||||||
name: '插槽',
|
name: '插槽',
|
||||||
args: {
|
args: {
|
||||||
@ -123,6 +147,7 @@ export const TransferSlot: Story = {
|
|||||||
:default-params="args.defaultParams"
|
:default-params="args.defaultParams"
|
||||||
:hide-pagination="args.hidePagination"
|
:hide-pagination="args.hidePagination"
|
||||||
:request="args.request"
|
:request="args.request"
|
||||||
|
:lock-list="args.lockList"
|
||||||
:page-sizes="args.pageSizes"
|
:page-sizes="args.pageSizes"
|
||||||
:pager-count="args.pagerCount"
|
:pager-count="args.pagerCount"
|
||||||
:props="args.props"
|
:props="args.props"
|
||||||
|
Reference in New Issue
Block a user