tab优化,表格优化

This commit is contained in:
Gary Fu
2024-01-01 18:34:58 +08:00
parent cd12a30764
commit 702a1bb8fb
9 changed files with 98 additions and 14 deletions

View File

@@ -10,6 +10,10 @@
* @property {string} slot 自定义插槽
* @property [ButtonProps] buttons 自定义按钮
* @property {Object} attrs 其他属性
* @property {string} link 链接地址
* @property {Object} linkAttrs 链接配置
* @method click 点击事件
* @method formatter 格式化
*/
/**
* 配置信息
@@ -22,6 +26,9 @@ const props = defineProps({
type: Object,
required: true
},
/**
* @type {'large'|'small'|'default'}
*/
buttonSize: {
type: String,
default: 'small'
@@ -37,13 +44,24 @@ const props = defineProps({
:property="column.property"
:width="column.width"
v-bind="column.attrs"
:formatter="column.formatter"
>
<template
v-if="column.slot"
v-if="column.slot||column.link||column.click"
#default="scope"
>
<el-link
v-if="column.link||column.click"
:href="column.link"
type="primary"
v-bind="column.linkAttrs"
@click="column.click&&column.click(scope.row, scope)"
>
{{ scope.row[column.property] }}
</el-link>
<slot
v-bind="scope"
:column-conf="column"
name="default"
/>
</template>

View File

@@ -67,7 +67,10 @@ const props = defineProps({
}
}
})
/**
*
* @type {ComputedRef<[CommonTableColumn]>}
*/
const calcColumns = computed(() => {
let _columns = props.columns
if (props.buttons.length || props.buttonsSlot) {
@@ -102,8 +105,10 @@ const calcColumns = computed(() => {
#default="scope"
>
<slot
v-if="column.slot"
:scope="scope"
:item="scope.row"
:column-conf="scope.columnConf"
:name="column.slot"
/>
</template>

View File

@@ -25,6 +25,16 @@ const menuName = computed(() => {
const menuInfo = computed(() => {
return props.tabItem.path === '/' ? { icon: 'HomeFilled' } : useMenuInfo(props.tabItem)
})
const menuIcon = computed(() => {
if (menuInfo.value && menuInfo.value.icon) {
return menuInfo.value.icon
}
if (props.tabItem.meta && props.tabItem.meta.icon) {
return props.tabItem.meta.icon
}
return null
})
</script>
<template>
@@ -35,8 +45,8 @@ const menuInfo = computed(() => {
<el-dropdown trigger="contextmenu">
<span class="custom-tabs-label">
<common-icon
v-if="tabsViewStore.isShowTabIcon && menuInfo && menuInfo.icon"
:icon="menuInfo.icon"
v-if="tabsViewStore.isShowTabIcon && menuIcon"
:icon="menuIcon"
/>
<span>{{ menuName }}</span>
</span>

View File

@@ -30,6 +30,7 @@ common.label.modify = '修改'
common.label.delete = '删除'
common.label.search = '搜索'
common.label.find = '查找'
common.label.back = '返回'
//* =======================msg=====================//
common.msg.nonNull = '{0}不能为空'

View File

@@ -30,6 +30,7 @@ common.label.modify = 'Modify'
common.label.delete = 'Delete'
common.label.search = 'Search'
common.label.find = 'Find'
common.label.back = 'Back'
//* =======================msg=====================//
common.msg.nonNull = '{0} is required.'

View File

@@ -9,5 +9,18 @@ export default [{
}, {
path: '/tables',
name: 'tables',
component: () => import('@/views/tools/Tables.vue')
children: [{
path: '',
name: 'tables-index',
component: () => import('@/views/tools/Tables.vue')
}, {
path: 'edit',
name: 'tables-edit',
component: () => import('@/views/tools/TableEdit.vue'),
meta: {
replaceTabHistory: 'tables-index',
labelKey: 'common.label.edit',
icon: 'Edit'
}
}]
}]

View File

@@ -40,18 +40,26 @@ export const useTabsViewStore = defineStore('tabsView', () => {
}
}
const addHistoryTab = (tab, insertIdx) => {
const checkMataReplaceHistory = (historyTab, tab) => {
// 如果meta中配置有replaceTabHistory默认替换相关的tab
return historyTab.meta && historyTab.meta.replaceTabHistory && historyTab.meta.replaceTabHistory === tab.name
}
const addHistoryTab = (tab) => {
// 添加tab
if (isTabMode.value) {
const idx = historyTabs.value.findIndex(v => v.path === tab.path)
if (idx < 0) {
if (insertIdx !== undefined) {
historyTabs.value.splice(insertIdx, 0, tab)
} else {
historyTabs.value.push(Object.assign({}, tab)) // 可能是Proxy需要解析出来
const replaceIdx = historyTabs.value.findIndex(v => checkMataReplaceHistory(v, tab) || checkMataReplaceHistory(tab, v))
if (replaceIdx > -1) {
console.info(replaceIdx, historyTabs.value[replaceIdx])
if (replaceIdx !== undefined) {
historyTabs.value.splice(replaceIdx, 1, Object.assign({}, tab))
return
}
}
historyTabs.value.push(Object.assign({}, tab)) // 可能是Proxy需要解析出来
if (isCachedTabMode.value && tab.name) {
console.info('=======================add tab', tab.name)
if (!cachedTabs.value.includes(tab.name)) {
cachedTabs.value.push(tab.name)
}

View File

@@ -0,0 +1,21 @@
<script setup>
import { useRouter } from 'vue-router'
const router = useRouter()
</script>
<template>
<div>
<strong>编辑数据</strong>
<br>
<el-link
type="primary"
@click="router.back()"
>
{{ $t('common.label.back') }}
</el-link>
</div>
</template>
<style scoped>
</style>

View File

@@ -33,14 +33,18 @@ const tableData = [
*/
const columns = [{
label: '用户名',
property: 'userName'
property: 'userName',
link: '#/tables/edit'
}, {
label: '性别',
property: 'gender',
slot: 'gender'
}, {
label: '出生日期',
property: 'birthday'
property: 'birthday',
click (item) {
console.info('=================', item)
}
}, {
label: '地址',
property: 'address'
@@ -77,7 +81,10 @@ const buttons = ref([{
</el-tag>
</template>
<template #buttons="{item}">
<el-button @click="console.info(item)">
<el-button
size="small"
@click="console.info(item)"
>
测试
</el-button>
</template>