| ¶Ô±ÈÐÂÎļþ |
| | |
| | | <template> |
| | | <div class="app-container"> |
| | | <el-form :model="queryParams" ref="queryRef" v-show="showSearch" :inline="true" label-width="68px"> |
| | | <el-form-item label="è§è²åç§°" prop="roleName"> |
| | | <el-input |
| | | v-model="queryParams.name" |
| | | placeholder="请è¾å
¥è§è²åç§°" |
| | | clearable |
| | | style="width: 240px" |
| | | @keyup.enter="handleQuery" |
| | | /> |
| | | </el-form-item> |
| | | <el-form-item label="ç¶æ" prop="status"> |
| | | <el-select |
| | | v-model="queryParams.status" |
| | | placeholder="è§è²ç¶æ" |
| | | clearable |
| | | style="width: 240px" |
| | | > |
| | | <el-option label="å¯ç¨" value="0" /> |
| | | <el-option label="ç¦ç¨" value="1" /> |
| | | </el-select> |
| | | </el-form-item> |
| | | <el-form-item> |
| | | <el-button type="primary" icon="Search" @click="handleQuery">æç´¢</el-button> |
| | | <el-button icon="Refresh" @click="resetQuery">éç½®</el-button> |
| | | </el-form-item> |
| | | </el-form> |
| | | <el-row :gutter="10" class="mb8"> |
| | | <el-col :span="1.5"> |
| | | <el-button |
| | | type="primary" |
| | | plain |
| | | icon="Plus" |
| | | @click="handleAdd" |
| | | v-hasPermi="['system:role:add']" |
| | | >æ°å¢</el-button> |
| | | </el-col> |
| | | <el-col :span="1.5"> |
| | | <el-button |
| | | type="success" |
| | | plain |
| | | icon="Edit" |
| | | :disabled="single" |
| | | @click="handleUpdate" |
| | | v-hasPermi="['system:role:edit']" |
| | | >ä¿®æ¹</el-button> |
| | | </el-col> |
| | | <el-col :span="1.5"> |
| | | <el-button |
| | | type="danger" |
| | | plain |
| | | icon="Delete" |
| | | :disabled="multiple" |
| | | @click="handleDelete" |
| | | v-hasPermi="['system:role:remove']" |
| | | >å é¤</el-button> |
| | | </el-col> |
| | | <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar> |
| | | </el-row> |
| | | |
| | | <!-- è¡¨æ ¼æ°æ® --> |
| | | <el-table v-loading="loading" :data="roleList" @selection-change="handleSelectionChange"> |
| | | <el-table-column type="selection" width="55" align="center" /> |
| | | <el-table-column label="è§è²ç¼å·" prop="no" /> |
| | | <el-table-column label="è§è²åç§°" prop="name" :show-overflow-tooltip="true" /> |
| | | <el-table-column label="ç¶æ" align="center" width="100"> |
| | | <template #default="scope"> |
| | | <el-switch |
| | | v-model="scope.row.status" |
| | | :active-value="0" |
| | | :inactive-value="1" |
| | | @change="handleStatusChange(scope.row)" |
| | | ></el-switch> |
| | | </template> |
| | | </el-table-column> |
| | | <el-table-column label="å建æ¶é´" align="center" prop="createTime"> |
| | | <template #default="scope"> |
| | | <span>{{ parseTime(scope.row.createTime) }}</span> |
| | | </template> |
| | | </el-table-column> |
| | | <el-table-column fixed="right" label="æä½" align="center" width="120"> |
| | | <template #default="scope"> |
| | | <el-tooltip content="ä¿®æ¹" placement="top" v-if="scope.row.roleId !== 1"> |
| | | <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['system:role:edit']"></el-button> |
| | | </el-tooltip> |
| | | <el-tooltip content="å é¤" placement="top" v-if="scope.row.roleId !== 1"> |
| | | <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['system:role:remove']"></el-button> |
| | | </el-tooltip> |
| | | </template> |
| | | </el-table-column> |
| | | </el-table> |
| | | |
| | | <pagination |
| | | v-show="total > 0" |
| | | :total="total" |
| | | v-model:page="queryParams.current" |
| | | v-model:limit="queryParams.size" |
| | | @pagination="getList" |
| | | /> |
| | | |
| | | <!-- æ·»å æä¿®æ¹è§è²é
ç½®å¯¹è¯æ¡ --> |
| | | <el-dialog :title="title" v-model="open" width="500px" append-to-body> |
| | | <el-form ref="roleRef" :model="form" :rules="rules" label-width="100px"> |
| | | <el-form-item label="è§è²ç¼å·" prop="no"> |
| | | <el-input |
| | | v-model="form.no" |
| | | style="max-width: 600px" |
| | | :placeholder="form.isDefaultNo ? '使ç¨ç³»ç»ç¼å·' : '请è¾å
¥è§è²ç¼å·'" |
| | | :disabled="form.isDefaultNo" |
| | | > |
| | | <template #append> |
| | | <el-checkbox v-model="form.isDefaultNo" size="large" /> |
| | | </template> |
| | | </el-input> |
| | | </el-form-item> |
| | | <el-form-item label="è§è²åç§°" prop="name"> |
| | | <el-input v-model="form.name" placeholder="请è¾å
¥è§è²åç§°" /> |
| | | </el-form-item> |
| | | </el-form> |
| | | <template #footer> |
| | | <div class="dialog-footer"> |
| | | <el-button type="primary" @click="submitForm">ç¡® å®</el-button> |
| | | <el-button @click="cancel">å æ¶</el-button> |
| | | </div> |
| | | </template> |
| | | </el-dialog> |
| | | </div> |
| | | </template> |
| | | |
| | | <script setup name="Role"> |
| | | import {onMounted} from "vue"; |
| | | import {createRole, deleteRoles, findRoleListPage, updateRole} from "@/api/projectManagement/role.js"; |
| | | |
| | | const { proxy } = getCurrentInstance() |
| | | const { sys_normal_disable } = proxy.useDict("sys_normal_disable") |
| | | |
| | | const roleList = ref([]) |
| | | const open = ref(false) |
| | | const loading = ref(true) |
| | | const showSearch = ref(true) |
| | | const ids = ref([]) |
| | | const single = ref(true) |
| | | const multiple = ref(true) |
| | | const total = ref(0) |
| | | const title = ref("") |
| | | const editingId = ref(undefined) |
| | | const form = reactive({ |
| | | isDefaultNo: true, |
| | | no: "", |
| | | name: "", |
| | | }); |
| | | |
| | | const rules = computed(() => ({ |
| | | no: [{ required: !form.isDefaultNo, message: "è§è²ç¼å·ä¸è½ä¸ºç©º", trigger: "blur" }], |
| | | name: [{ required: true, message: "è§è²åç§°ä¸è½ä¸ºç©º", trigger: "blur" }], |
| | | })); |
| | | |
| | | const data = reactive({ |
| | | queryParams: { |
| | | current: 1, |
| | | size: 10, |
| | | name: undefined, |
| | | status: undefined |
| | | }, |
| | | }) |
| | | |
| | | const { queryParams } = toRefs(data) |
| | | |
| | | /** æ¥è¯¢è§è²å表 */ |
| | | function getList() { |
| | | loading.value = true |
| | | findRoleListPage(queryParams.value).then(res => { |
| | | roleList.value = res.data.records |
| | | total.value = res.data.total |
| | | loading.value = false |
| | | }) |
| | | } |
| | | |
| | | /** æç´¢æé®æä½ */ |
| | | function handleQuery() { |
| | | queryParams.value.current = 1 |
| | | getList() |
| | | } |
| | | |
| | | /** éç½®æé®æä½ */ |
| | | function resetQuery() { |
| | | proxy.resetForm("queryRef") |
| | | queryParams.value.name = undefined |
| | | queryParams.value.status = undefined |
| | | handleQuery() |
| | | } |
| | | |
| | | /** å é¤æé®æä½ */ |
| | | function handleDelete(row) { |
| | | let roleIds = [] |
| | | if (row.id) { |
| | | roleIds = [row.id] |
| | | } else { |
| | | roleIds = ids.value |
| | | } |
| | | proxy.$modal.confirm('ç¡®å®è¦å é¤è¯¥æ°æ®å?').then(function () { |
| | | return deleteRoles(roleIds) |
| | | }).then(() => { |
| | | getList() |
| | | proxy.$modal.msgSuccess("å 餿å") |
| | | }).catch(() => {}) |
| | | } |
| | | |
| | | /** å¤éæ¡é䏿°æ® */ |
| | | function handleSelectionChange(selection) { |
| | | ids.value = selection.map(item => item.id) |
| | | single.value = selection.length != 1 |
| | | multiple.value = !selection.length |
| | | } |
| | | |
| | | /** è§è²ç¶æä¿®æ¹ */ |
| | | function handleStatusChange(row) { |
| | | let text = row.status === 0 ? "å¯ç¨" : "åç¨" |
| | | proxy.$modal.confirm('确认è¦"' + text + '""' + row.name + '"è§è²å?').then(function () { |
| | | return updateRole(row) |
| | | }).then(() => { |
| | | proxy.$modal.msgSuccess(text + "æå") |
| | | }).catch(function () { |
| | | row.status = row.status === 0 ? 1 : 0 |
| | | }) |
| | | } |
| | | |
| | | /** éç½®æ°å¢ç表å以åå
¶ä»æ°æ® */ |
| | | function reset() { |
| | | // éç½®è¡¨åæ°æ® |
| | | Object.assign(form, { |
| | | isDefaultNo: true, |
| | | no: "", |
| | | name: "", |
| | | }) |
| | | editingId.value = undefined |
| | | } |
| | | |
| | | /** æ·»å è§è² */ |
| | | function handleAdd() { |
| | | reset() |
| | | open.value = true |
| | | title.value = "æ·»å è§è²" |
| | | } |
| | | |
| | | /** ä¿®æ¹è§è² */ |
| | | function handleUpdate(row) { |
| | | reset() |
| | | editingId.value = row.id |
| | | form.no = row.no |
| | | form.name = row.name |
| | | title.value = "ä¿®æ¹è§è²" |
| | | open.value = true |
| | | } |
| | | |
| | | /** æäº¤æé® */ |
| | | function submitForm() { |
| | | proxy.$refs["roleRef"].validate(valid => { |
| | | if (valid) { |
| | | if (editingId.value) { |
| | | const data = { |
| | | id: editingId.value, |
| | | ...form |
| | | } |
| | | updateRole(data).then(response => { |
| | | proxy.$modal.msgSuccess("ä¿®æ¹æå") |
| | | }).finally(() => { |
| | | proxy.$refs["roleRef"].resetFields() |
| | | open.value = false |
| | | getList() |
| | | }) |
| | | } else { |
| | | createRole(form).then(response => { |
| | | proxy.$modal.msgSuccess("æ°å¢æå") |
| | | }).finally(() => { |
| | | proxy.$refs["roleRef"].resetFields() |
| | | open.value = false |
| | | getList() |
| | | }) |
| | | } |
| | | } |
| | | }) |
| | | } |
| | | |
| | | /** åæ¶æé® */ |
| | | function cancel() { |
| | | open.value = false |
| | | reset() |
| | | } |
| | | |
| | | onMounted(() => { |
| | | getList(); |
| | | }); |
| | | </script> |