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

View File

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

View File

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

View File

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

View File

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

View File

@@ -9,5 +9,18 @@ export default [{
}, { }, {
path: '/tables', path: '/tables',
name: '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 // 添加tab
if (isTabMode.value) { if (isTabMode.value) {
const idx = historyTabs.value.findIndex(v => v.path === tab.path) const idx = historyTabs.value.findIndex(v => v.path === tab.path)
if (idx < 0) { if (idx < 0) {
if (insertIdx !== undefined) { const replaceIdx = historyTabs.value.findIndex(v => checkMataReplaceHistory(v, tab) || checkMataReplaceHistory(tab, v))
historyTabs.value.splice(insertIdx, 0, tab) if (replaceIdx > -1) {
} else { console.info(replaceIdx, historyTabs.value[replaceIdx])
historyTabs.value.push(Object.assign({}, tab)) // 可能是Proxy需要解析出来 if (replaceIdx !== undefined) {
historyTabs.value.splice(replaceIdx, 1, Object.assign({}, tab))
return
}
} }
historyTabs.value.push(Object.assign({}, tab)) // 可能是Proxy需要解析出来
if (isCachedTabMode.value && tab.name) { if (isCachedTabMode.value && tab.name) {
console.info('=======================add tab', tab.name)
if (!cachedTabs.value.includes(tab.name)) { if (!cachedTabs.value.includes(tab.name)) {
cachedTabs.value.push(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 = [{ const columns = [{
label: '用户名', label: '用户名',
property: 'userName' property: 'userName',
link: '#/tables/edit'
}, { }, {
label: '性别', label: '性别',
property: 'gender', property: 'gender',
slot: 'gender' slot: 'gender'
}, { }, {
label: '出生日期', label: '出生日期',
property: 'birthday' property: 'birthday',
click (item) {
console.info('=================', item)
}
}, { }, {
label: '地址', label: '地址',
property: 'address' property: 'address'
@@ -77,7 +81,10 @@ const buttons = ref([{
</el-tag> </el-tag>
</template> </template>
<template #buttons="{item}"> <template #buttons="{item}">
<el-button @click="console.info(item)"> <el-button
size="small"
@click="console.info(item)"
>
测试 测试
</el-button> </el-button>
</template> </template>