<script lang="ts" setup>
|
import { computed, ref, unref } from 'vue';
|
|
import { useMessage } from '@jnpf/hooks';
|
|
const props = defineProps(['conf', 'appConf']);
|
defineExpose({ getData });
|
const { createMessage } = useMessage();
|
|
const columns = [
|
{ title: '序号', width: 50, align: 'center', customRender: ({ index }) => index + 1 },
|
{ title: '名称', dataIndex: 'fullName', key: 'fullName' },
|
{ title: '编码', dataIndex: 'enCode', key: 'enCode' },
|
{ title: '操作', dataIndex: 'action', key: 'action', width: 50, align: 'center' },
|
];
|
const showType = ref('pc');
|
|
const getList = computed(() => (showType.value == 'pc' ? props.conf : props.appConf));
|
|
function getData() {
|
return new Promise((resolve) => {
|
if (!exist(props.conf) || !exist(props.appConf)) return;
|
resolve({ target: 1 });
|
});
|
}
|
function exist(list) {
|
let isOk = true;
|
for (let i = 0; i < list.length; i++) {
|
const e = list[i];
|
if (!e.fullName) {
|
createMessage.warning('名称不能为空');
|
isOk = false;
|
break;
|
}
|
if (!e.enCode) {
|
createMessage.warning('编码不能为空');
|
isOk = false;
|
break;
|
}
|
const idNum = list.filter((o) => o.enCode == e.enCode);
|
if (idNum.length > 1) {
|
createMessage.warning(`编码'${e.enCode}'已重复`);
|
isOk = false;
|
break;
|
}
|
}
|
return isOk;
|
}
|
function handleDelItem(index) {
|
unref(getList).splice(index, 1);
|
}
|
function handleAdd() {
|
const item = { fullName: '', enCode: '' };
|
unref(getList).push(item);
|
}
|
</script>
|
<template>
|
<div class="sys-form-title-content">
|
<jnpf-group-title content="按钮设置" :bordered="false" />
|
<div class="action-bar">
|
<div class="action-bar-left">
|
<div class="jnpf-device-switch">
|
<div class="jnpf-device-switch-item" :class="{ 'jnpf-device-switch-item--active': showType === 'pc' }" @click="showType = 'pc'">
|
<a-tooltip title="PC">
|
<i class="icon-ym icon-ym-pc"></i>
|
</a-tooltip>
|
</div>
|
<div class="jnpf-device-switch-item" :class="{ 'jnpf-device-switch-item--active': showType === 'app' }" @click="showType = 'app'">
|
<a-tooltip title="APP">
|
<i class="icon-ym icon-ym-mobile"></i>
|
</a-tooltip>
|
</div>
|
</div>
|
</div>
|
</div>
|
</div>
|
<a-table :data-source="getList" :columns="columns" size="small" :pagination="false" row-key="id">
|
<template #bodyCell="{ column, record, index }">
|
<template v-if="column.key === 'fullName'">
|
<a-input v-model:value="record.fullName" placeholder="输入名称" allow-clear />
|
</template>
|
<template v-if="column.key === 'enCode'">
|
<a-input v-model:value="record.enCode" placeholder="输入编码" allow-clear />
|
</template>
|
<template v-if="column.key === 'action'">
|
<a-button class="action-btn" type="link" color="error" @click="handleDelItem(index)" size="small">删除</a-button>
|
</template>
|
</template>
|
</a-table>
|
<div class="table-add-action" @click="handleAdd">
|
<a-button type="link" pre-icon="icon-ym icon-ym-btn-add">新增一行</a-button>
|
</div>
|
</template>
|