修复tabs query bug 代码优化

This commit is contained in:
吕金泽 2022-03-20 19:50:51 +08:00
parent 4bcd0cfc3b
commit 61aa570cf2
9 changed files with 56 additions and 52 deletions

View File

@ -28,7 +28,10 @@ const emit = defineEmits(['update:modelValue', 'change'])
const magicTable = ref() const magicTable = ref()
const props = defineProps({ const props = defineProps({
modelValue: Array, modelValue: {
type: Array,
default: () => []
},
cols: { cols: {
type: Array, type: Array,
default: () => [] default: () => []
@ -36,11 +39,15 @@ const props = defineProps({
showNo: { showNo: {
type: Boolean, type: Boolean,
default: true default: true
},
operation: {
type: Boolean,
default: true
} }
}) })
const tableOptions = reactive({ const tableOptions = reactive({
data: [], data: props.modelValue,
cols: [], cols: [],
showNo: props.showNo showNo: props.showNo
}) })
@ -48,25 +55,26 @@ const tableOptions = reactive({
for (var i in props.cols) { for (var i in props.cols) {
var col = props.cols[i] var col = props.cols[i]
tableOptions.cols.push({ tableOptions.cols.push({
type: 'dynamic', ...col,
field: col.field, type: 'dynamic'
label: col.label
}) })
} }
tableOptions.cols.push({ if(props.operation){
label: '操作', tableOptions.cols.push({
type: 'btns', label: '操作',
width: 85, type: 'btns',
fixed: 'right', width: 85,
btns: [{ fixed: 'right',
label: '删除', btns: [{
type: 'danger', label: '删除',
click: (row, index) => { type: 'danger',
tableOptions.data.splice(index, 1) click: (row, index) => {
} tableOptions.data.splice(index, 1)
}] }
}) }]
})
}
watch(() => props.modelValue, (value) => { watch(() => props.modelValue, (value) => {
console.log(value) console.log(value)

View File

@ -56,10 +56,6 @@ for(var key in props.where){
} }
} }
watch(() => props.where,() => {
console.log(props.where)
})
const emit = defineEmits(['search', 'mounted']) const emit = defineEmits(['search', 'mounted'])
function input(input){ function input(input){

View File

@ -75,10 +75,6 @@ const props = defineProps({
} }
}) })
watch(() => props.checkedIds, (value) => {
console.log(value)
})
const tree = ref() const tree = ref()
const treeData = ref([]) const treeData = ref([])
const searchData = ref([]) const searchData = ref([])

View File

@ -43,8 +43,10 @@
tabValue.value = global.tabValue.value tabValue.value = global.tabValue.value
}) })
function openTab(item){ function openTab(item){
console.log(global.visitedViews.map(it => it.name))
proxy.$router.push({ proxy.$router.push({
path: item.props.name path: item.props.name,
query: global.visitedViews.filter(it => it.path == item.props.name)[0].query
}) })
} }
function removeTab(path){ function removeTab(path){
@ -58,7 +60,8 @@
if(it.path == path){ if(it.path == path){
global.visitedViews.splice(i, 1) global.visitedViews.splice(i, 1)
proxy.$router.push({ proxy.$router.push({
path: global.visitedViews[global.visitedViews.length - 1].path path: global.visitedViews[global.visitedViews.length - 1].path,
query: global.visitedViews[global.visitedViews.length - 1].query
}) })
} }
}) })
@ -66,7 +69,8 @@
} }
function refresh(path){ function refresh(path){
proxy.$router.replace({ proxy.$router.replace({
path: `/redirect${path}` path: `/redirect${path}`,
query: global.visitedViews.filter(it => it.path == path)[0].query
}) })
} }
function close(type, path){ function close(type, path){
@ -85,16 +89,17 @@
} }
} }
}else{ }else{
for(var i = 0; i < global.visitedViews.length; i++){ for(var i = 0, len = global.visitedViews.length; i < len; i++){
if(global.visitedViews[i].path != path){ if(global.visitedViews[0].path != path){
global.visitedViews.splice(i, 1) global.visitedViews.splice(0, 1)
}else{ }else{
break; break;
} }
} }
} }
proxy.$router.push({ proxy.$router.push({
path: path path: path,
query: global.visitedViews.filter(it => it.path == path)[0].query
}) })
} }
</script> </script>

View File

@ -24,9 +24,13 @@ document.title = global.title
router.beforeEach((to, from) => { router.beforeEach((to, from) => {
global.tabValue.value = to.path global.tabValue.value = to.path
if((to.name && global.visitedViews.length === 0 || global.visitedViews.every(it => it.path !== to.path)) && !to.path.startsWith('/redirect') && !to.path.startsWith('/login')){ if((to.name && global.visitedViews.length === 0 || global.visitedViews.every(it => it.path !== to.path)) && !to.path.startsWith('/redirect') && !to.path.startsWith('/login')){
console.log(to)
global.visitedViews.push(to) global.visitedViews.push(to)
} }
global.visitedViews.forEach((it, i) => {
if(it.path == to.path){
global.visitedViews[i] = to
}
})
return true return true
}) })
app.use(globalProperties) app.use(globalProperties)

View File

@ -1,7 +1,7 @@
<template> <template>
<div style="padding: 50px;"> <div style="padding: 50px;">
<el-button type="primary" @click="getData" style="margin-bottom: 10px">获取数据</el-button> <el-button type="primary" @click="getData" style="margin-bottom: 10px">获取数据</el-button>
<mb-editor-table v-model="tableDatas" :cols="cols" :show-no="false" /> <mb-editor-table v-model="tableDatas" :cols="cols" :show-no="false" :operation="false" />
</div> </div>
</template> </template>

View File

@ -188,8 +188,8 @@ const tableOptions = reactive({
} }
] ]
}) })
let dialogTitle = ref('') const dialogTitle = ref('')
let searchTimeout = reactive() var searchTimeout = reactive()
const menuFormDialog = ref() const menuFormDialog = ref()
const menuFormRef = ref() const menuFormRef = ref()
@ -197,7 +197,6 @@ function reloadTable(){
proxy.$get('menu/tree').then(res => { proxy.$get('menu/tree').then(res => {
menuData.value = res.data.list menuData.value = res.data.list
tableOptions.data = menuData.value tableOptions.data = menuData.value
searchMenu()
}) })
} }
@ -208,6 +207,9 @@ function expand(){
} }
function searchMenu() { function searchMenu() {
refreshTable.value = false
tableOptions.el["default-expand-all"] = true
nextTick(() => refreshTable.value = true)
clearTimeout(searchTimeout) clearTimeout(searchTimeout)
searchTimeout = setTimeout(() => { searchTimeout = setTimeout(() => {
if(searchValue.value){ if(searchValue.value){

View File

@ -218,7 +218,7 @@ const rules = reactive({
name: [{ required: true, message: '请输入机构名称', trigger: 'change' }], name: [{ required: true, message: '请输入机构名称', trigger: 'change' }],
code: [{ required: true, message: '请输入机构编码', trigger: 'change' }] code: [{ required: true, message: '请输入机构编码', trigger: 'change' }]
}) })
const searchTimeout = null var searchTimeout = null
const officeFormDialog = ref() const officeFormDialog = ref()
const dataForm = ref() const dataForm = ref()
@ -237,9 +237,7 @@ watch(officeData, () => {
function expand(){ function expand(){
refreshTable.value = false refreshTable.value = false
tableOptions.el["default-expand-all"] = !tableOptions.el["default-expand-all"] tableOptions.el["default-expand-all"] = !tableOptions.el["default-expand-all"]
nextTick(() => { nextTick(() => refreshTable.value = true)
refreshTable.value = true
})
} }
function searchOffice() { function searchOffice() {

View File

@ -22,12 +22,11 @@
search-width="100%" search-width="100%"
:checked="false" :checked="false"
@check-change="checkChange" @check-change="checkChange"
@mounted="treeMounted"
/> />
</div> </div>
<div class="right"> <div class="right">
<mb-search :where="tableOptions.where" @search="reloadTable" @mounted="searchMounted"> <mb-search :where="tableOptions.where" @search="reloadTable">
<template #btns> <template #btns>
<el-button :loading="downloadLoading" class="filter-item" icon="ElDownload" @click="handleDownload"> <el-button :loading="downloadLoading" class="filter-item" icon="ElDownload" @click="handleDownload">
导出 导出
@ -175,16 +174,12 @@ const userFormDialog = ref()
const table = ref() const table = ref()
const userForm = ref() const userForm = ref()
function searchMounted(){ if(proxy.$route.query.roleId){
if(proxy.$route.query.roleId){ tableOptions.where.roleId.value = proxy.$route.query.roleId
tableOptions.where.roleId.value = proxy.$route.query.roleId
}
} }
function treeMounted(){ if(proxy.$route.query.officeId){
if(proxy.$route.query.officeId){ tableOptions.where.officeId = proxy.$route.query.officeId
tableOptions.where.officeId = proxy.$route.query.officeId
}
} }
function checkChange(values) { function checkChange(values) {