feat: permissions

This commit is contained in:
JaguarJack
2022-12-07 19:28:57 +08:00
parent a1d9468a91
commit 8c537e6656
45 changed files with 1030 additions and 372 deletions

View File

@@ -43,7 +43,7 @@
<script lang="ts" setup>
import { useCreate } from '/admin/composables/curd/useCreate'
import { useShow } from '/admin/composables/curd/useShow'
import { onMounted, ref, watch } from 'vue'
import { onMounted, ref, unref, watch } from 'vue'
import http from '/admin/support/http'
const props = defineProps({
@@ -51,9 +51,7 @@ const props = defineProps({
api: String,
})
const emit = defineEmits(['close'])
const { formData, form, loading, submitForm, isClose, beforeCreate, beforeUpdate } = useCreate(props.api, props.primary)
const { formData, form, loading, submitForm, close, beforeCreate, beforeUpdate } = useCreate(props.api, props.primary)
beforeCreate.value = () => {
formData.value.parent_id = getParent(formData.value.parent_id)
@@ -67,29 +65,28 @@ const getParent = (parentId: any) => {
return typeof parentId === 'undefined' ? 0 : parentId[parentId.length - 1]
}
watch(isClose, function (value) {
if (value) {
emit('close')
}
})
if (props.primary) {
const { afterShow } = useShow(props.api, props.primary, formData)
afterShow.value = formData => {
const data = unref(formData)
data.parent_id = data.parent_id ? [data.parent_id] : 0
if (!data.data_range) {
data.data_range = null
}
formData.value = data
}
}
const emit = defineEmits(['close'])
const roles = ref()
onMounted(() => {
if (props.primary) {
useShow(props.api, props.primary).then(r => {
r.data.parent_id = r.data.parent_id ? [r.data.parent_id ] : 0;
formData.value = r.data
if (!formData.value.data_range) {
formData.value.data_range = null
}
})
}
http.get(props.api).then(r => {
roles.value = r.data.data
})
close(() => emit('close'))
})
</script>

View File

@@ -1,25 +1,15 @@
<template>
<div>
<div class="w-full min-h-0 bg-white dark:bg-regal-dark pl-5 pt-5 pr-5 rounded-lg">
<el-form :inline="true">
<Search :search="search" :reset="reset">
<template v-slot:body>
<el-form-item label="角色名称" prop="role_name">
<el-input v-model="query.role_name" name="role_name" clearable />
</el-form-item>
<el-form-item>
<el-button type="primary" @click="search()">
<Icon name="magnifying-glass" class="w-4 mr-1 -ml-1" />
搜索
</el-button>
<el-button @click="reset()">
<Icon name="arrow-path" class="w-4 mr-1 -ml-1" />
重置
</el-button>
</el-form-item>
</el-form>
</div>
<div class="pl-2 pr-2 bg-white dark:bg-regal-dark rounded-lg mt-4 pb-10">
</template>
</Search>
<div class="pl-2 pr-2 bg-white dark:bg-regal-dark rounded-lg mt-4 pb-6">
<div class="pt-5 pl-2">
<Add @click="show(null)" />
<Add @click="open(null)" />
</div>
<el-table :data="tableData" class="mt-3" v-loading="loading" row-key="id" default-expand-all :tree-props="{ children: 'children' }">
<el-table-column prop="role_name" label="角色名称" />
@@ -28,53 +18,36 @@
<el-table-column prop="created_at" label="创建时间" />
<el-table-column label="操作" width="200">
<template #default="scope">
<Update @click="show(scope.row.id)" />
<Update @click="open(scope.row.id)" />
<Destroy @click="destroy(api, scope.row.id)" />
</template>
</el-table-column>
</el-table>
</div>
<Dialog v-model="visible" :title="title" destroy-on-close>
<Create @close="close" :primary="id" :api="api" />
<Create @close="close(reset)" :primary="id" :api="api" />
</Dialog>
</div>
</template>
<script lang="ts" setup>
import { computed, onMounted, ref, watch } from 'vue'
import { computed, onMounted } from 'vue'
import Create from './create.vue'
import { useGetList } from '/admin/composables/curd/useGetList'
import { useDestroy } from '/admin/composables/curd/useDestroy'
import { useEnabled } from '/admin/composables/curd/useEnabled'
import { t } from '/admin/support/helper'
import { useOpen } from '/admin/composables/curd/useOpen'
const visible = ref<boolean>(false)
const id = ref(null)
const api = 'permissions/roles'
const title = ref<string>('')
const { data, query, search, reset, loading } = useGetList(api)
const { destroy, isDeleted } = useDestroy()
onMounted(() => search())
const { destroy, deleted } = useDestroy()
const { open, close, title, visible, id } = useOpen()
const tableData = computed(() => data.value?.data)
const close = () => {
visible.value = false
reset()
}
onMounted(() => {
search()
const show = primary => {
title.value = primary ? t('system.edit') : t('system.add')
id.value = primary
visible.value = true
}
watch(isDeleted, function () {
// change origin status
isDeleted.value = false
reset()
deleted(reset)
})
</script>