You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

519 lines
15 KiB

3 years ago
<template>
<div class="container">
<!-- 查询配置 -->
<div>
<div ref="lxHeader">
<LxHeader
icon="md-apps"
1 year ago
:text="$route.meta.title"
3 years ago
style="margin-bottom: 10px; border: 0px; margin-top: 15px"
>
<div slot="content"></div>
<slot>
<div>
<Input
style="width: 200px; margin-right: 10px"
v-model.number="searchFields.Name"
1 year ago
placeholder="Keyword"
3 years ago
/>
<Button type="primary" @click="load" style="margin-left: 10px"
1 year ago
>search</Button
3 years ago
>
<Button type="primary" @click="edit()" style="margin-left: 10px"
1 year ago
>add menu</Button
3 years ago
>
</div>
</slot>
</LxHeader>
</div>
<div class="table-tree">
<el-table
:data="tableData"
:height="tableHeight"
class="v-table"
style="width: 100%; margin-bottom: 20px"
row-key="id"
border
default-expand-all
:tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
>
<el-table-column type="index" align="center"> </el-table-column>
1 year ago
<el-table-column prop="name" label="Menu" sortable width="180">
3 years ago
</el-table-column>
1 year ago
<el-table-column prop="url" label="Route" sortable>
3 years ago
</el-table-column>
1 year ago
<el-table-column prop="path" label="Path" sortable> </el-table-column>
<el-table-column prop="icon" label="Icon" sortable> </el-table-column>
<el-table-column prop="api_prefix" label="Api" sortable>
3 years ago
</el-table-column>
1 year ago
<el-table-column prop="sortnumber" label="Sort" sortable>
3 years ago
</el-table-column>
1 year ago
<el-table-column fixed="right" label="Operate" width="300">
3 years ago
<template slot-scope="scope">
<Button
type="primary"
@click="addchildren(scope.row)"
size="small"
style="margin-left: 10px"
ghost
1 year ago
>sub menu</Button
3 years ago
>
<Button
1 year ago
type="primary"
@click="edit(scope.row)"
3 years ago
size="small"
style="margin-left: 10px"
ghost
1 year ago
>edit</Button
3 years ago
>
<Button
1 year ago
type="error"
@click="del(scope.row)"
3 years ago
size="small"
style="margin-left: 10px"
ghost
1 year ago
>delete</Button
3 years ago
>
1 year ago
3 years ago
</template>
</el-table-column>
</el-table>
</div>
</div>
1 year ago
<el-dialog title="Edit Menu" :visible.sync="dialogFormVisible" width="60%">
3 years ago
<el-form
:model="form"
:rules="rules"
ref="form"
label-position="right"
:label-width="formLabelWidth"
>
<el-row>
<el-col :span="12">
1 year ago
<el-form-item label="Parent Menu">
3 years ago
<el-input
v-model="form.pname"
disabled
autocomplete="off"
></el-input>
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col :span="18">
1 year ago
<el-form-item label="Name" prop="name">
3 years ago
<el-input v-model="form.name" autocomplete="off"></el-input>
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col :span="18">
1 year ago
<el-form-item label="Route" prop="url">
3 years ago
<el-input v-model="form.url" autocomplete="off"></el-input>
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col :span="18">
1 year ago
<el-form-item label="Path" prop="path">
3 years ago
<el-input v-model="form.path" autocomplete="off"></el-input>
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col :span="18">
1 year ago
<el-form-item label="Customform">
3 years ago
<el-select clearable value-key="id" v-model="selectCustomForm">
3 years ago
<el-option
v-for="item in customForms"
:key="item.id"
:value="item"
:label="item.name"
></el-option>
</el-select>
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col :span="12">
1 year ago
<el-form-item label="Api" prop="api_prefix">
3 years ago
<el-input v-model="form.api_prefix" autocomplete="off"></el-input>
</el-form-item>
</el-col>
<el-col :span="12">
1 year ago
<el-form-item label="Sort">
3 years ago
<el-input v-model="form.sortnumber" autocomplete="off"></el-input>
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col :span="12">
1 year ago
<el-form-item label="Visible" prop="visible">
3 years ago
<el-select v-model="form.visible">
1 year ago
<el-option label="Yes" value="1"></el-option>
<el-option label="No" value="0"></el-option>
3 years ago
</el-select>
</el-form-item>
</el-col>
<el-col :span="12">
1 year ago
<el-form-item label="Icon" prop="icon">
3 years ago
<el-input v-model="form.icon" autocomplete="off"></el-input>
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col :span="24">
<div
style="
display: flex;
align-items: center;
justify-content: space-between;
"
>
1 year ago
<el-form-item label="Operating Authorization" prop="auth_node_tags">
3 years ago
<el-checkbox-group v-model="form.auth_node_tagsArr">
<el-checkbox
:label="item.tag"
v-for="(item, index) of list"
:key="item.id"
>
{{ item.name }}
</el-checkbox>
</el-checkbox-group>
</el-form-item>
<el-button size="small" @click="dialogOptFormVisible = true" round
1 year ago
>add</el-button
3 years ago
>
</div>
</el-col>
</el-row>
</el-form>
<div slot="footer" class="dialog-footer">
1 year ago
<el-button @click="resetForm('form')">cancel</el-button>
<el-button type="primary" @click="submitForm('form')">confirm</el-button>
3 years ago
</div>
</el-dialog>
<el-dialog
1 year ago
title="Add Operate"
3 years ago
:visible.sync="dialogOptFormVisible"
width="30%"
>
<el-form
:model="actionForm"
:rules="actionRules"
ref="actionForm"
label-position="right"
:label-width="formLabelWidth"
>
1 year ago
<el-form-item label="Tag" prop="tag">
3 years ago
<el-input v-model="actionForm.tag" autocomplete="off"></el-input>
</el-form-item>
1 year ago
<el-form-item label="Name" prop="name">
3 years ago
<el-input v-model="actionForm.name" autocomplete="off"> </el-input>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
1 year ago
<el-button @click="resetForm('actionForm')">cancel</el-button>
3 years ago
<el-button type="primary" @click="saveAuthForm('actionForm')"
1 year ago
>confirm</el-button
3 years ago
>
</div>
</el-dialog>
</div>
</template>
<script>
import LxHeader from "@/components/LxHeader/index.vue";
import { save, listmenu, del } from "@/api/system/menu";
import { index } from "@/api/system/customForm";
import { store as storeAuth, list, del as delAuth } from "@/api/system/auth.js";
export default {
components: {
LxHeader,
},
created() {
this.getCustomForms();
this.initLoad();
this.load();
},
mounted() {},
data() {
return {
selectCustomForm: "",
customForms: [],
dialogOptFormVisible: false,
dialogFormVisible: false,
formLabelWidth: "120px",
form: {
name: "",
id: "",
pid: "0",
url: "",
visible: "1",
sortnumber: 0,
icon: "",
1 year ago
pname: "Root Menu",
3 years ago
api_prefix: "",
auth_node_tagsArr: [],
auth_node_tags: "",
path: "",
},
actionRules: {
tag: [
{
required: true,
1 year ago
message: "Please Input",
3 years ago
trigger: "blur",
},
],
name: [
{
required: true,
1 year ago
message: "Please Input",
3 years ago
trigger: "blur",
},
],
},
rules: {
name: [
{
required: true,
1 year ago
message: "Please Input",
3 years ago
trigger: "blur",
},
],
url: [
{
required: true,
1 year ago
message: "Please Input",
3 years ago
trigger: "blur",
},
],
path: [
{
required: true,
1 year ago
message: "Please Input",
3 years ago
trigger: "blur",
},
],
icon: [
{
required: true,
1 year ago
message: "Please Input",
3 years ago
trigger: "blur",
},
],
visible: [
{
required: true,
1 year ago
message: "Please Select",
3 years ago
trigger: "blur",
},
],
},
tableHeight: 0,
//查询条件字段
searchFields: {
KeyWord: "",
},
tableData: [],
list: [],
actionForm: {
name: "",
tag: "",
},
};
},
methods: {
async getCustomForms() {
const res = await index({ page: 1, page_size: 999 });
this.customForms = res.data;
},
saveAuthForm(formName) {
var that = this;
this.$refs[formName].validate((valid) => {
if (valid) {
storeAuth(that.actionForm)
.then((response) => {
console.log(response);
1 year ago
this.$Message.success("Success");
3 years ago
that.dialogOptFormVisible = false;
that.loadAuth();
})
.catch((error) => {
reject(error);
});
} else {
1 year ago
this.$Message.error("Error");
3 years ago
return false;
}
});
},
loadAuth() {
var that = this;
list({
page: 1,
})
.then((res) => {
that.list = res.data;
})
.catch((error) => {});
},
initLoad() {
var that = this;
var clientHeight = document.documentElement.clientHeight;
var lxHeader_height = 96.5; //查询 头部
var paginationHeight = 37; //分页的高度
var topHeight = 50; //页面 头部
let tableHeight =
clientHeight - lxHeader_height - topHeight - paginationHeight - 20;
that.tableHeight = tableHeight;
},
load() {
var that = this;
listmenu()
.then((response) => {
that.tableData = response;
})
.catch((error) => {
//reject(error)
});
},
edit(obj) {
this.form = this.$options.data().form;
this.loadAuth();
if (obj) {
obj.visible = obj.visible.toString();
if (obj.auth_node_tags)
this.form.auth_node_tagsArr = obj.auth_node_tags.split(",");
var result = Object.assign(this.form, obj);
this.form = result;
3 years ago
if(this.form.path?.includes('?')) {
3 years ago
let queryString = this.form.path.split("?")[1];
// 将参数字符串按照“&”符号分割成数组
let paramsArray = queryString.split("&");
// 定义一个空对象用于存储参数名和参数值
let params = {};
// 遍历参数数组将每个参数名和参数值存储在params对象中
for (let i = 0; i < paramsArray.length; i++) {
let param = paramsArray[i].split("=");
let paramName = param[0];
let paramValue = param[1];
params[paramName] = paramValue;
}
// 获取custom_form_id参数的值
let customForm = params["custom_form"] ? JSON.parse(decodeURIComponent(params["custom_form"])) : {}
this.selectCustomForm = this.customForms.find(i => i.id === customForm?.custom_form_id)
3 years ago
}
}
this.dialogFormVisible = true;
},
addchildren(obj) {
this.form = this.$options.data().form;
if (obj) {
this.form.pname = obj.name;
this.form.pid = obj.id;
this.dialogFormVisible = true;
}
},
replaceCustomFormParam(str, newValue) {
// 匹配 custom_form 参数及其值
const regex = /([&?])custom_form=([^&]*)(&|$)/;
const match = str.match(regex);
if (match) {
const before = match[1]; // 匹配到的 "&" 或 "?"
const after = match[3]; // 匹配到的 "&" 或 ""(如果最后一个参数是 custom_form
const oldValue = match[2]; // 匹配到的原始值
// 替换匹配到的值
const newStr = str.replace(
`custom_form=${oldValue}`,
`custom_form=${newValue}`
);
// 如果有 "&" 则保留,否则加上 "&"
return before ? newStr : `${newStr}&`;
} else {
// 如果没有 custom_form 参数,则直接返回原字符串加上新参数
return str + `&custom_form=${newValue}`;
}
},
submitForm(formName) {
var that = this;
this.$refs[formName].validate((valid) => {
if (valid) {
if (that.selectCustomForm) {
let temp = encodeURIComponent(
`{"custom_form_id":${that.selectCustomForm?.id},"table_name":"${that.selectCustomForm?.table_name}"}`
);
if (that.form?.path?.includes("?")) {
if (that.form.path.indexOf("custom_form") === -1) {
that.form.path += `&custom_form=${temp}`;
} else {
that.form.path = that.replaceCustomFormParam(that.form.path,temp);
}
} else {
that.form.path += `?custom_form=${temp}`;
}
}
this.form.auth_node_tags = this.form.auth_node_tagsArr.join(",");
save(that.form)
.then((response) => {
console.log(response);
1 year ago
this.$Message.success("Success");
3 years ago
that.dialogFormVisible = false;
that.load();
})
.catch((error) => {
reject(error);
});
} else {
1 year ago
this.$Message.error("Error");
3 years ago
return false;
}
});
},
resetForm(formName) {
var that = this;
this.$refs[formName].resetFields();
if (formName == "form") that.dialogFormVisible = false;
else that.dialogOptFormVisible = false;
},
del(obj) {
var that = this;
if (obj) {
this.$Modal.confirm({
1 year ago
title: "Are you sure to delete it?",
3 years ago
onOk: () => {
del({
id: obj.id,
})
.then((response) => {
1 year ago
this.$Message.success("Success");
3 years ago
that.load();
})
.catch((error) => {
console.log(error);
reject(error);
});
},
onCancel: () => {
//this.$Message.info('Clicked cancel');
},
});
}
},
},
};
4 years ago
</script>