|
@@ -1,181 +0,0 @@
|
|
|
-<template>
|
|
|
- <el-card class="form-container" shadow="never">
|
|
|
- <el-form ref="rolesFrom" :model="rolesForm" :rules="rules" label-width="150px">
|
|
|
- <el-form-item label="角色名称:" prop="roleName">
|
|
|
- <el-input v-model="rolesForm.roleName" maxlength="20" />
|
|
|
- </el-form-item>
|
|
|
- <el-form-item label="角色描述:" prop="roleDesc">
|
|
|
- <el-input v-model="rolesForm.roleDesc" maxlength="20" />
|
|
|
- </el-form-item>
|
|
|
- <el-form-item label="角色授权:">
|
|
|
- <el-tree ref="tree" :data="treeData" show-checkbox node-key="id" :props="defaultProps" @node-click="handleNodeClick" />
|
|
|
- </el-form-item>
|
|
|
- <el-form-item>
|
|
|
- <el-button type="primary" @click="onSubmit('rolesFrom')">提交</el-button>
|
|
|
- <el-button v-if="!isEdit" @click="resetForm('rolesFrom')">重置</el-button>
|
|
|
- </el-form-item>
|
|
|
- </el-form>
|
|
|
- </el-card>
|
|
|
-</template>
|
|
|
-
|
|
|
-<script>
|
|
|
-import { updateRole, createRole } from '@/api/role'
|
|
|
-import { sysMenuTree } from '@/api/menu'
|
|
|
-import { validAlphabets } from '@/utils/validate'
|
|
|
-
|
|
|
-const defaultRole = {
|
|
|
- roleDesc: '',
|
|
|
- roleName: '',
|
|
|
- menuIds: '',
|
|
|
- id: 0
|
|
|
-}
|
|
|
-export default {
|
|
|
- name: 'RolesFormDetail',
|
|
|
- // components: { SingleUpload },
|
|
|
- filters: {},
|
|
|
- props: {
|
|
|
- isEdit: {
|
|
|
- type: Boolean,
|
|
|
- default: false
|
|
|
- }
|
|
|
- },
|
|
|
- data() {
|
|
|
- const validateRoleName = (rule, value, callback) => {
|
|
|
- if (!validAlphabets(value)) {
|
|
|
- callback(new Error('请输入英文角色名称'))
|
|
|
- } else {
|
|
|
- callback()
|
|
|
- }
|
|
|
- }
|
|
|
- return {
|
|
|
- rolesForm: Object.assign({}, defaultRole),
|
|
|
- selectProductCateList: [],
|
|
|
- rules: {
|
|
|
- roleName: [
|
|
|
- { required: true, message: '请输入英文角色名称', trigger: 'blur', validator: validateRoleName },
|
|
|
- { min: 2, max: 20, message: '长度在 6 到 20 个字符', trigger: 'blur' }
|
|
|
- ],
|
|
|
- roleDesc: [
|
|
|
- { required: true, message: '请输入角色描述', trigger: 'blur' },
|
|
|
- { min: 2, max: 20, message: '长度在 2 到 20 个字符', trigger: 'blur' }
|
|
|
- ]
|
|
|
- },
|
|
|
- treeData: [],
|
|
|
- defaultProps: {
|
|
|
- children: 'subMenus',
|
|
|
- label: 'title'
|
|
|
- },
|
|
|
- filterProductAttrList: [
|
|
|
- {
|
|
|
- value: []
|
|
|
- }
|
|
|
- ],
|
|
|
- changOptionName: ''
|
|
|
- }
|
|
|
- },
|
|
|
- created() {
|
|
|
- // eslint-disable-next-line no-empty
|
|
|
- if (this.isEdit) {
|
|
|
-
|
|
|
- } else {
|
|
|
- this.rolesForm = Object.assign({}, defaultRole)
|
|
|
- }
|
|
|
- this.getSysMenuTree()
|
|
|
- },
|
|
|
- methods: {
|
|
|
- handleNodeClick(data, node) {
|
|
|
- console.log(node)
|
|
|
- },
|
|
|
- getSysMenuTree() {
|
|
|
- // 属性菜单
|
|
|
- sysMenuTree().then(response => {
|
|
|
- this.treeData = response.data
|
|
|
- })
|
|
|
- },
|
|
|
- onSubmit(formName) {
|
|
|
- this.$refs[formName].validate(valid => {
|
|
|
- if (valid) {
|
|
|
- this.$confirm('是否提交数据', '提示', {
|
|
|
- confirmButtonText: '确定',
|
|
|
- cancelButtonText: '取消',
|
|
|
- type: 'warning'
|
|
|
- }).then(() => {
|
|
|
- if (this.isEdit) {
|
|
|
- this.rolesForm.menuIds = this.getCheckedNodes()
|
|
|
- updateRole(this.$route.query.id, this.rolesForm).then(response => {
|
|
|
- this.$message({
|
|
|
- message: '修改成功',
|
|
|
- type: 'success',
|
|
|
- duration: 1000
|
|
|
- })
|
|
|
- this.$router.back()
|
|
|
- })
|
|
|
- } else {
|
|
|
- this.rolesForm.menuIds = this.getCheckedNodes()
|
|
|
- createRole(this.rolesForm).then(response => {
|
|
|
- this.$refs[formName].resetFields()
|
|
|
- this.resetForm(formName)
|
|
|
- this.$message({
|
|
|
- message: '提交成功',
|
|
|
- type: 'success',
|
|
|
- duration: 1000
|
|
|
- })
|
|
|
- })
|
|
|
- }
|
|
|
- })
|
|
|
- } else {
|
|
|
- this.$message({
|
|
|
- message: '验证失败',
|
|
|
- type: 'error',
|
|
|
- duration: 1000
|
|
|
- })
|
|
|
- return false
|
|
|
- }
|
|
|
- })
|
|
|
- },
|
|
|
- getCheckedNodes() {
|
|
|
- // 获取选中系统菜单Id
|
|
|
- console.log(this.$refs.tree.getCheckedNodes())
|
|
|
- const res = this.$refs.tree.getCheckedNodes()
|
|
|
- const menuIds = res[0].id
|
|
|
- console.log('menuIds', menuIds)
|
|
|
- return menuIds
|
|
|
- },
|
|
|
- resetForm(formName) {
|
|
|
- this.$refs[formName].resetFields()
|
|
|
- this.rolesForm = Object.assign({}, defaultRole)
|
|
|
- },
|
|
|
- removeFilterAttr(productAttributeId) {
|
|
|
- if (this.filterProductAttrList.length === 1) {
|
|
|
- this.$message({
|
|
|
- message: '至少要留一个',
|
|
|
- type: 'warning',
|
|
|
- duration: 1000
|
|
|
- })
|
|
|
- return
|
|
|
- }
|
|
|
- var index = this.filterProductAttrList.indexOf(productAttributeId)
|
|
|
- if (index !== -1) {
|
|
|
- this.filterProductAttrList.splice(index, 1)
|
|
|
- }
|
|
|
- },
|
|
|
- handleAddFilterAttr() {
|
|
|
- if (this.filterProductAttrList.length === 3) {
|
|
|
- this.$message({
|
|
|
- message: '最多添加三个',
|
|
|
- type: 'warning',
|
|
|
- duration: 1000
|
|
|
- })
|
|
|
- return
|
|
|
- }
|
|
|
- this.filterProductAttrList.push({
|
|
|
- value: null,
|
|
|
- key: Date.now()
|
|
|
- })
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
-</script>
|
|
|
-
|
|
|
-<style scoped>
|
|
|
-</style>
|