|
@@ -0,0 +1,155 @@
|
|
|
+<template>
|
|
|
+ <CommonPage back :title="detail.title ">
|
|
|
+ <template #action>
|
|
|
+ <NButton type="primary">
|
|
|
+ <i class="i-material-symbols:add mr-4 text-18" />
|
|
|
+ 新增子菜单
|
|
|
+ </NButton>
|
|
|
+ </template>
|
|
|
+
|
|
|
+ <MeCrud ref="$table" v-model:query-items="queryItems" :scroll-x="1200" :columns="columns" :get-data="api.read">
|
|
|
+ <MeQueryItem label="标题" :label-width="50">
|
|
|
+ <n-input v-model:value="queryItems.title" type="text" placeholder="请输入标题名" clearable>
|
|
|
+ <template #password-visible-icon />
|
|
|
+ </n-input>
|
|
|
+ </MeQueryItem>
|
|
|
+ <MeQueryItem label="状态" :label-width="50">
|
|
|
+ <n-select
|
|
|
+ v-model:value="queryItems.enable" clearable :options="[
|
|
|
+ { label: '启用', value: 1 },
|
|
|
+ { label: '停用', value: 0 },
|
|
|
+ ]"
|
|
|
+ />
|
|
|
+ </MeQueryItem>
|
|
|
+ </MeCrud>
|
|
|
+ </CommonPage>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script setup>
|
|
|
+import { MeCrud, MeQueryItem } from '@/components'
|
|
|
+import { useCrud } from '@/composables'
|
|
|
+import { formatDateTime } from '@/utils'
|
|
|
+import { NButton, NSwitch } from 'naive-ui'
|
|
|
+import { useRoute, useRouter } from 'vue-router'
|
|
|
+
|
|
|
+import api from './api.js'
|
|
|
+
|
|
|
+const $table = ref(null)
|
|
|
+
|
|
|
+const router = useRouter()
|
|
|
+const route = useRoute()
|
|
|
+const detail = ref({
|
|
|
+ title: '',
|
|
|
+ id: null,
|
|
|
+})
|
|
|
+/** QueryBar筛选参数(可选) */
|
|
|
+const queryItems = ref({
|
|
|
+ parentId: route.params.id,
|
|
|
+})
|
|
|
+const { handleDelete, handleEdit }
|
|
|
+ = useCrud({
|
|
|
+ name: '文章',
|
|
|
+ doCreate: api.create,
|
|
|
+ doDelete: api.delete,
|
|
|
+ doUpdate: api.update,
|
|
|
+ initForm: { enable: true },
|
|
|
+ refresh: (_, keepCurrentPage) => $table.value?.handleSearch(keepCurrentPage),
|
|
|
+ })
|
|
|
+
|
|
|
+async function getMenuDetail() {
|
|
|
+ const { data } = await api.getOne(route.params.id)
|
|
|
+ if (data) {
|
|
|
+ console.log('data', data)
|
|
|
+ detail.value = data
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+const columns = [
|
|
|
+ { title: '标题名', key: 'title', width: '200' },
|
|
|
+ { title: '分类', key: 'category.title' },
|
|
|
+ {
|
|
|
+ title: '创建时间',
|
|
|
+ key: 'createTime',
|
|
|
+ render: row => h('span', formatDateTime(row.createTime)),
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '状态',
|
|
|
+ key: 'enable',
|
|
|
+ render: row =>
|
|
|
+ h(
|
|
|
+ NSwitch,
|
|
|
+ {
|
|
|
+ size: 'small',
|
|
|
+ rubberBand: false,
|
|
|
+ value: row.enable,
|
|
|
+ loading: !!row.enableLoading,
|
|
|
+ disabled: row.code === 'SUPER_ADMIN',
|
|
|
+ onUpdateValue: () => handleEnable(row),
|
|
|
+ },
|
|
|
+ {
|
|
|
+ checked: () => '启用',
|
|
|
+ unchecked: () => '停用',
|
|
|
+ },
|
|
|
+ ),
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '操作',
|
|
|
+ key: 'actions',
|
|
|
+ width: 200,
|
|
|
+ align: 'center',
|
|
|
+ fixed: 'right',
|
|
|
+ render(row) {
|
|
|
+ return [
|
|
|
+ h(
|
|
|
+ NButton,
|
|
|
+ {
|
|
|
+ size: 'small',
|
|
|
+ type: 'primary',
|
|
|
+ style: 'margin-left: 12px;',
|
|
|
+ disabled: row.code === 'SUPER_ADMIN',
|
|
|
+ onClick: () => handleEdit(row),
|
|
|
+ },
|
|
|
+ {
|
|
|
+ default: () => '编辑',
|
|
|
+ icon: () => h('i', { class: 'i-material-symbols:edit-outline text-14' }),
|
|
|
+ },
|
|
|
+ ),
|
|
|
+
|
|
|
+ h(
|
|
|
+ NButton,
|
|
|
+ {
|
|
|
+ size: 'small',
|
|
|
+ type: 'error',
|
|
|
+ style: 'margin-left: 12px;',
|
|
|
+ disabled: row.code === 'SUPER_ADMIN',
|
|
|
+ onClick: () => handleDelete(row.id),
|
|
|
+ },
|
|
|
+ {
|
|
|
+ default: () => '删除',
|
|
|
+ icon: () => h('i', { class: 'i-material-symbols:delete-outline text-14' }),
|
|
|
+ },
|
|
|
+ ),
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ },
|
|
|
+]
|
|
|
+
|
|
|
+async function handleEnable(row) {
|
|
|
+ row.enableLoading = true
|
|
|
+ try {
|
|
|
+ await api.update({ id: row.id, enable: !row.enable })
|
|
|
+ row.enableLoading = false
|
|
|
+ $message.success('操作成功')
|
|
|
+ $table.value?.handleSearch()
|
|
|
+ }
|
|
|
+ catch (error) {
|
|
|
+ console.error(error)
|
|
|
+ row.enableLoading = false
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+onMounted(() => {
|
|
|
+ $table.value?.handleSearch()
|
|
|
+ getMenuDetail()
|
|
|
+})
|
|
|
+</script>
|