Skip to content

Commit

Permalink
style: use tags
Browse files Browse the repository at this point in the history
  • Loading branch information
cole committed Jun 27, 2024
1 parent 49474a3 commit 1d846b9
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 21 deletions.
21 changes: 10 additions & 11 deletions src/layout/hooks/useTags.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { ref, unref, watch } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import tryOnScopeDispose from '@/utils/hooks/tryOnScopeDispose'
import { localCache, TAGS__LOCAL } from '@/utils/storage'
import { cloneProxyToRaw } from '@/utils/props-util'

function useTags (menus, homeName) {
const router = useRouter()
const route = useRoute()
function useTags (menus, options) {
const { homeName, route, router } = options || {}

const homeRoute = getCurrentRoute(menus, homeName)
const cacheTags = localCache.getObj(TAGS__LOCAL)
Expand All @@ -19,7 +17,8 @@ function useTags (menus, homeName) {
return item.name === name
})
if (result === -1) {
setTagsValue([...unref(tags), cloneProxyToRaw({ name, meta, query, params })])
const newValue = cloneProxyToRaw({ name, meta, query, params })
setTagsValue([...unref(tags), newValue])
}
}
}, { immediate: true, deep: true })
Expand All @@ -31,7 +30,7 @@ function useTags (menus, homeName) {
}

function getCurrentRoute (menus, name) {
for (let item of menus) {
for (const item of menus) {
if (item.name === name) {
return item
} else if (item.children && item.children.length) {
Expand All @@ -46,20 +45,20 @@ function useTags (menus, homeName) {
localCache.setObj(TAGS__LOCAL, values)
}

function onTagClick (route) {
const { name, query, params } = route
router.push({ name, query, params })
function onTagClick (currentRoute) {
const { name, query, params } = currentRoute
router && router.push({ name, query, params })
}

function onTagClose (values, toName) {
setTagsValue(values)
if (toName) {
const result = values.find((item) => {
return item.name === toName
})
const { name, query, params } = result || {}
router.push({ name, query, params })
router && router.push({ name, query, params })
}
setTagsValue(values)
}

function onStop () {
Expand Down
11 changes: 6 additions & 5 deletions src/layout/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ export default defineComponent({
const router = useRouter()
// --
const collapsed = ref(false)
/**
* 过滤没有权限的路由
* access 权限数组, 一般是在后台请求过来放在 store 里面
*/
// 过滤没有权限的路由, 权限 access 一般是在后台请求过来放在 store 里面
const menus = getMenuList(routes, [])
const { tags, onTagClick, onTagClose } = useTags(menus, HOME_NAME)
const { tags, onTagClick, onTagClose } = useTags(menus, {
route: route,
router: router,
homeName: HOME_NAME
})

const include = computed(() => {
return unref(tags).filter((item) => {
Expand Down
2 changes: 0 additions & 2 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ async function start ({ app, router, stores }) {

/**
* 处理一些杂项
* 比如 boot 中需要重定向
* (创建一个 redirect 函数) 供 boot 调用
*/

await createBoots({ app, router, stores, urlPath, publicPath })
Expand Down
2 changes: 1 addition & 1 deletion src/packages/form/form/List.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { defineComponent } from 'vue'

// @todo 列表支持
// @todo 表单列表 开发中
export default defineComponent({
inheritAttrs: false,
props: {
Expand Down
2 changes: 1 addition & 1 deletion src/packages/form/layouts/query-filter/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export default defineComponent({

const children = filterEmptyElement(slots.default ? slots.default(slotScope) : [])
const { nodes: colNodes, offset, haveRow } = genColNodes(children, (item) => {
const { child, hidden, key } = item
const { child, hidden, key } = item || {}
const colClass = cx({ 'col-hidden': hidden })
return (
<Col key={key} class={colClass} span={unref(span)}>{child}</Col>
Expand Down
2 changes: 1 addition & 1 deletion src/packages/table/components/density/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ export default defineComponent({
const { t } = useLocaleReceiver(['Table', 'toolbar'])

function onMenuClick (params) {
props.onClick && props.onClick(params)
if (unref(tableSize) !== params.key) {
setTableSize && setTableSize(params.key)
}
props.onClick && props.onClick(params)
}

return () => {
Expand Down
1 change: 1 addition & 0 deletions src/packages/table/editable-table/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const editable = {
}, // Promise
}

// @todo 编辑表格 开发中
export default defineComponent({
inheritAttrs: false,
props: {
Expand Down

0 comments on commit 1d846b9

Please sign in to comment.