jia 3 years ago
parent
commit
f00e322854
  1. 12
      src/api/menu.js
  2. 33
      src/layout/components/Navbar.vue
  3. 4
      src/main.js
  4. 1
      src/styles/scss/index.scss
  5. 29
      src/utils/get-img-width.js
  6. 751
      src/views/article/index.vue
  7. 675
      src/views/menu/index.vue

12
src/api/menu.js

@ -37,17 +37,17 @@ export function roleMenuTreeselect(roleId) {
// 新增菜单 // 新增菜单
export function addMenu(data) { export function addMenu(data) {
return request({ return request({
url: '/api/v1/menu', url: '/menu/AddMenu',
method: 'post', method: 'post',
data: data data: data
}) })
} }
// 修改菜单 // 修改菜单
export function updateMenu(data, id) { export function updateMenu(data ) {
return request({ return request({
url: '/api/v1/menu/' + id, url: '/menu/menuEdit',
method: 'put', method: 'post',
data: data data: data
}) })
} }
@ -55,8 +55,8 @@ export function updateMenu(data, id) {
// 删除菜单 // 删除菜单
export function delMenu(data) { export function delMenu(data) {
return request({ return request({
url: '/api/v1/menu', url: '/menu/menuDel',
method: 'delete', method: 'post',
data: data data: data
}) })
} }

33
src/layout/components/Navbar.vue

@ -1,8 +1,6 @@
<template> <template>
<el-menu class="navbar-header-fixed" mode="horizontal"> <el-menu class="navbar-header-fixed" mode="horizontal">
<div class="name"> <div class="name">Hamlet管理端</div>
Hamlet管理端
</div>
<div class="top-right"> <div class="top-right">
<div class="hb-bd"> <div class="hb-bd">
<hamburger <hamburger
@ -14,9 +12,10 @@
<div class="top-select"> <div class="top-select">
<div class="go-index">{{ name }}</div> <div class="go-index">{{ name }}</div>
<div class="logout" v-if="this.$store.state.user.token" @click="logout">注销</div> <div class="logout" v-if="this.$store.state.user.token" @click="logout">
注销
</div>
<div class="login" v-else @click="$router.push('/login')">登录</div> <div class="login" v-else @click="$router.push('/login')">登录</div>
</div> </div>
</div> </div>
</el-menu> </el-menu>
@ -27,38 +26,37 @@ import { mapGetters } from "vuex";
import Hamburger from "@/components/Hamburger"; import Hamburger from "@/components/Hamburger";
export default { export default {
components: { components: {
Hamburger Hamburger,
}, },
data: () => ({ data: () => ({
mix: false, mix: false,
userImage: require("@/assets/user.png"), userImage: require("@/assets/user.png"),
isMac: process.platform === "darwin" isMac: process.platform === "darwin",
}), }),
mounted() { mounted() {},
},
methods: { methods: {
toggleSideBar() { toggleSideBar() {
console.log('toggle') console.log("toggle");
this.$store.dispatch("ToggleSideBar"); this.$store.dispatch("ToggleSideBar");
}, },
logout() { logout() {
this.$store.dispatch("user/FedLogOut").then(() => { this.$store.dispatch("user/FedLogOut").then(() => {
this.$message({ this.$message({
message: "退出成功", message: "退出成功",
type: "success" type: "success",
}); });
this.$router.push('/login') this.$router.push("/login");
}); });
}, },
}, },
computed: { computed: {
...mapGetters(["name", "role", "sidebar"]) ...mapGetters(["name", "role", "sidebar"]),
}, },
beforeDestroy() { beforeDestroy() {
console.log("销毁计时器------------"); console.log("销毁计时器------------");
clearInterval(this.timer); clearInterval(this.timer);
this.timer = null; this.timer = null;
} },
}; };
</script> </script>
@ -72,7 +70,7 @@ export default {
right: 0; right: 0;
z-index: 1002; z-index: 1002;
height: 36px; height: 36px;
-webkit-user-select:none; -webkit-user-select: none;
-webkit-app-region: drag; -webkit-app-region: drag;
background-color: #525151; background-color: #525151;
border: none !important; border: none !important;
@ -101,7 +99,7 @@ export default {
height: 100%; height: 100%;
justify-content: space-between; justify-content: space-between;
// padding: 0 5px; // padding: 0 5px;
color: #BFBDBD; color: #bfbdbd;
.hb-bd { .hb-bd {
display: flex; display: flex;
justify-content: center; justify-content: center;
@ -137,7 +135,7 @@ export default {
font-family: SourceHanSansSC-regular; font-family: SourceHanSansSC-regular;
} }
.tools { .tools {
color: #BFBDBD; color: #bfbdbd;
margin-left: 32px; margin-left: 32px;
padding: 0 8px; padding: 0 8px;
display: flex; display: flex;
@ -147,7 +145,6 @@ export default {
margin: 0 5px; margin: 0 5px;
cursor: pointer; cursor: pointer;
} }
} }
.select-right ::v-deep .el-dropdown > span { .select-right ::v-deep .el-dropdown > span {
font-size: 6px; font-size: 6px;

4
src/main.js

@ -22,6 +22,10 @@ import VueI18n from 'vue-i18n'
import loadLanguage from './i18n' import loadLanguage from './i18n'
const languages = loadLanguage() const languages = loadLanguage()
// 获取图片大小
import getImgWidth from './utils/get-img-width';
Vue.prototype.$getImgWidth = getImgWidth;
// console.log(process.env.VUE_APP_NAME); // console.log(process.env.VUE_APP_NAME);
// 创建 i18n // 创建 i18n

1
src/styles/scss/index.scss

@ -4,6 +4,7 @@
@import './element-ui.scss'; @import './element-ui.scss';
@import './sidebar.scss'; @import './sidebar.scss';
@import './btn.scss'; @import './btn.scss';
@import './admin.scss';
body { body {
margin: 0; margin: 0;

29
src/utils/get-img-width.js

@ -0,0 +1,29 @@
import { Message } from 'element-ui'
export default function (file, width, height) {
return new Promise(resolve => {
let reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = function (e) {
let txt = e.target.result;
let img = document.createElement("img");
img.src = txt;
img.onload = function () {
if (img.width === width && img.height === height) {
resolve(true)
} else {
Message({
message: `图片上传失败,宽高错误`,
type: "warning",
duration: 5000
});
resolve(false);
}
};
};
})
}
// 1. 650 350
// 1. 650 350
// 1. 650 350
// 1. 650 350
// 1. 650 350

751
src/views/article/index.vue

@ -1,84 +1,191 @@
<template> <template>
<div class="app-container"> <div class="app-container">
<div class="filter-container"> <el-card class="box-card">
<el-button class="filter-item el-button el-button--primary el-button--mini" type="primary" icon="el-icon-edit" @click="handleCreate"> <el-row :gutter="20">
添加文章 <!--部门数据-->
</el-button> <el-col :span="4" :xs="24">
</div> <div class="head-container">
<el-table <el-input
v-loading="listLoading" v-model="deptName"
:data="list" placeholder="请输入分类名称"
border clearable
fit size="small"
highlight-current-row prefix-icon="el-icon-search"
style="width: 100%;" style="margin-bottom: 20px"
> :default-expand-all="false"
<el-table-column label="ID" prop="id" align="center"> />
<template slot-scope="{row}"> </div>
<span>{{ row.article_id }}</span> <div class="head-container">
</template> <el-tree
</el-table-column> ref="tree"
<el-table-column label="分类" align="center"> :data="categoryOptions"
<template slot-scope="{row}"> highlight-current
<span>{{ row.category_id | getCateName(categoriesJson) }}</span> :props="defaultProps"
</template> :expand-on-click-node="false"
</el-table-column> :filter-node-method="filterNode"
<el-table-column label="标题" align="center"> @node-click="handleNodeClick"
<template slot-scope="{row}"> />
<span>{{ row.title }}</span> </div>
</template> </el-col>
</el-table-column> <!--用户数据-->
<el-table-column label="封面图" align="center"> <el-col :span="20" :xs="24">
<template slot-scope="{row}"> <el-form
<img :src="row.img" height="100" /> ref="queryForm"
</template> :model="listQuery"
</el-table-column> :inline="true"
<el-table-column label="外链" align="center"> label-width="68px"
<template slot-scope="{row}"> >
<span>{{ row.url }}</span> <el-form-item label="文章标题" prop="title">
</template> <el-input
</el-table-column> v-model="listQuery.title"
<el-table-column label="标签详情"> placeholder="请输入文章标题"
<template slot-scope="{row}"> clearable
<span>{{ row.label_name | getTagDetail }}</span> size="small"
</template> style="width: 160px"
</el-table-column> @keyup.enter.native="getList"
<el-table-column label="创建时间" align="center"> />
<template slot-scope="{row}"> </el-form-item>
<span>{{ row.create_time }}</span> <el-form-item label="文章标签" prop="label_name">
</template> <el-input
</el-table-column> v-model="listQuery.label_name"
<el-table-column label="操作" align="center" class-name="small-padding fixed-width"> placeholder="请输入文章标签"
<template slot-scope="scope"> clearable
size="small"
style="width: 160px"
@keyup.enter.native="getList"
/>
</el-form-item>
<el-form-item label="状态" prop="is_offline">
<el-select
v-model="listQuery.is_offline"
placeholder="文章状态"
clearable
size="small"
style="width: 160px"
>
<el-option
v-for="dict in statusOptions"
:key="dict.value"
:label="dict.label"
:value="dict.value"
/>
</el-select>
</el-form-item>
<el-form-item>
<el-button <el-button
type="primary"
icon="el-icon-search"
size="mini" size="mini"
type="text" @click="getList"
icon="el-icon-edit" >搜索</el-button
@click="handleUpdate(scope.row)" >
>修改</el-button> </el-form-item>
</el-form>
<el-row :gutter="10" class="mb8">
<el-col :span="1.5">
<el-button <el-button
type="primary"
icon="el-icon-plus"
size="mini" size="mini"
type="text" @click="handleCreate"
icon="el-icon-delete" >新增</el-button
@click="handleDelete(scope.row)" >
>删除</el-button> </el-col>
</template> </el-row>
</el-table-column> <el-table
</el-table> v-loading="listLoading"
:data="list"
border
fit
highlight-current-row
style="width: 100%"
>
<el-table-column label="ID" prop="id" align="center">
<template slot-scope="{ row }">
<span>{{ row.article_id }}</span>
</template>
</el-table-column>
<el-table-column label="分类" align="center">
<template slot-scope="{ row }">
<span>{{ row.category_id | getCateName(categoriesJson) }}</span>
</template>
</el-table-column>
<el-table-column label="标题" align="center">
<template slot-scope="{ row }">
<span>{{ row.title }}</span>
</template>
</el-table-column>
<el-table-column label="封面图" align="center">
<template slot-scope="{ row }">
<img :src="row.img" height="100" />
</template>
</el-table-column>
<el-table-column label="外链" align="center">
<template slot-scope="{ row }">
<span>{{ row.url }}</span>
</template>
</el-table-column>
<el-table-column label="标签详情">
<template slot-scope="{ row }">
<span>{{ row.label_name | getTagDetail }}</span>
</template>
</el-table-column>
<el-table-column label="创建时间" align="center">
<template slot-scope="{ row }">
<span>{{ row.create_time }}</span>
</template>
</el-table-column>
<el-table-column
label="操作"
align="center"
class-name="small-padding fixed-width"
>
<template slot-scope="scope">
<el-button
size="mini"
type="text"
icon="el-icon-edit"
@click="handleUpdate(scope.row)"
>修改</el-button
>
<el-button
size="mini"
type="text"
icon="el-icon-delete"
@click="handleDelete(scope.row)"
>删除</el-button
>
</template>
</el-table-column>
</el-table>
<pagination
v-show="total > 0"
:total="total"
:page.sync="listQuery.page"
:limit.sync="listQuery.limit"
@pagination="getList"
/>
</el-col>
</el-row>
</el-card>
<pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" /> <!-- 添加或修改分类对话框 -->
<!-- 添加或修改分类对话框 --> <el-drawer
<el-drawer ref="drawer"
ref="drawer" :title="textMap[dialogStatus]"
:title="textMap[dialogStatus]" :visible.sync="dialogFormVisible"
:visible.sync="dialogFormVisible" direction="rtl"
direction="rtl" custom-class="demo-drawer"
custom-class="drawer" size="950px"
size="950px" >
<div class="demo-drawer__content" v-if="dialogFormVisible">
<el-form
ref="dataForm"
:model="temp"
label-position="left"
label-width="70px"
style
> >
<div class="drawer__content">
<!-- <el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible" :fullscreen="dialogFullscreen"> -->
<el-form ref="dataForm" :model="temp" label-position="left" label-width="70px" style="">
<el-form-item label="类型"> <el-form-item label="类型">
<treeselect <treeselect
v-model="temp.category_id" v-model="temp.category_id"
@ -89,14 +196,23 @@
/> />
</el-form-item> </el-form-item>
<template v-if="tagData.length"> <template v-if="tagData.length">
<el-form-item :label="item.label" v-for="(item,index) in tagData" :key="index"> <el-form-item
<el-select v-model="chooseTagData[index]" multiple placeholder="请选择" style="width:100%"> :label="item.label"
v-for="(item, index) in tagData"
:key="index"
>
<el-select
v-model="chooseTagData[index]"
multiple
placeholder="请选择"
style="width: 100%"
>
<el-option <el-option
v-for="(sItem,sIndex) in item.value" v-for="(sItem, sIndex) in item.value"
:key="sIndex" :key="sIndex"
:label="sItem" :label="sItem"
:value="sItem"> :value="sItem"
</el-option> ></el-option>
</el-select> </el-select>
</el-form-item> </el-form-item>
</template> </template>
@ -104,7 +220,12 @@
<el-input v-model="temp.title" /> <el-input v-model="temp.title" />
</el-form-item> </el-form-item>
<el-form-item label="日期" prop="time"> <el-form-item label="日期" prop="time">
<el-date-picker v-model="temp.time" value-format="yyyy-MM-dd HH:mm:ss" type="date" placeholder="选择日期"></el-date-picker> <el-date-picker
v-model="temp.time"
value-format="yyyy-MM-dd HH:mm:ss"
type="date"
placeholder="选择日期"
></el-date-picker>
</el-form-item> </el-form-item>
<el-form-item label="外链" prop="url"> <el-form-item label="外链" prop="url">
<el-input v-model="temp.url" /> <el-input v-model="temp.url" />
@ -113,9 +234,22 @@
<el-input type="textarea" v-model="temp.description" /> <el-input type="textarea" v-model="temp.description" />
</el-form-item> </el-form-item>
<el-form-item label="封面" prop="img" required> <el-form-item label="封面" prop="img" required>
<img v-if="temp.img" :src="temp.img" class="el-upload el-upload--picture-card" style="float:left"> <img
<el-upload ref="sys_app_logo" :on-success="uploadSuccess" :on-error="uploadError" v-if="temp.img"
:action="uploadAction" style="float:left" list-type="picture-card" :show-file-list="false"> :src="temp.img"
class="el-upload el-upload--picture-card"
style="float: left"
/>
<el-upload
ref="sys_app_logo"
:on-success="uploadSuccess"
:on-error="uploadError"
:action="uploadAction"
style="float: left"
list-type="picture-card"
:show-file-list="false"
:before-upload="validationImages"
>
<i class="el-icon-plus" /> <i class="el-icon-plus" />
</el-upload> </el-upload>
</el-form-item> </el-form-item>
@ -126,44 +260,71 @@
:limit="1" :limit="1"
:on-exceed="handleFileExceed" :on-exceed="handleFileExceed"
:onSuccess="uploadFileSuccess" :onSuccess="uploadFileSuccess"
:file-list=" temp.script_url ? [JSON.parse(temp.script_url)] : [] " :file-list="temp.script_url ? [JSON.parse(temp.script_url)] : []"
> >
<el-button size="small" type="primary">点击上传</el-button> <el-button size="small" type="primary">点击上传</el-button>
<!-- <div slot="tip" class="el-upload__tip"> <!-- <div slot="tip" class="el-upload__tip">
只能上传jpg/png文件且不超过500kb 只能上传jpg/png文件且不超过500kb
</div> --> </div>-->
</el-upload> </el-upload>
</el-form-item> </el-form-item>
<el-form-item label="视频时长" prop="video_time"> <el-form-item label="视频时长" prop="video_time">
<el-time-picker v-model="temp.video_time" value-format="HH:mm:ss" type="time" placeholder="选择时间"></el-time-picker> <el-time-picker
v-model="temp.video_time"
value-format="HH:mm:ss"
type="time"
placeholder="选择时间"
></el-time-picker>
</el-form-item> </el-form-item>
<el-form-item label="内容" class="editor-box"> <el-form-item label="内容" class="editor-box">
<vue-ueditor-wrap v-model="temp.content" :config="ueditorConfig" :destroy="true" v-if="dialogFormVisible" /> <vue-ueditor-wrap
v-model="temp.content"
:config="ueditorConfig"
:destroy="true"
v-if="dialogFormVisible"
/>
</el-form-item> </el-form-item>
</el-form> </el-form>
<div class="drawer__footer"> <div class="demo-drawer__footer">
<el-button type="primary" @click="submitForm"> </el-button> <el-button type="primary" @click="submitForm"> </el-button>
<el-button @click="dialogFormVisible = false"> </el-button> <el-button @click="dialogFormVisible = false"> </el-button>
</div> </div>
</div> </div>
</el-drawer> </el-drawer>
</div> </div>
</template> </template>
<script> <script>
import { validPhone,isEmpty } from '@/utils/validate' import { validPhone, isEmpty } from "@/utils/validate";
import { fetchList, createArticle, updateArticle,delArticle, fetchArticleDetails } from '@/api/article' import {
import Pagination from '@/components/Pagination' // secondary package based on el-pagination fetchList,
import VueUeditorWrap from "vue-ueditor-wrap" createArticle,
import { listCategory } from '@/api/category' updateArticle,
import Treeselect from '@riophae/vue-treeselect' delArticle,
import '@riophae/vue-treeselect/dist/vue-treeselect.css' fetchArticleDetails,
} from "@/api/article";
import Pagination from "@/components/Pagination"; // secondary package based on el-pagination
import VueUeditorWrap from "vue-ueditor-wrap";
import { listCategory } from "@/api/category";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
export default { export default {
name: 'articleIndex', name: "articleIndex",
components: { Pagination, Treeselect, VueUeditorWrap }, components: { Pagination, Treeselect, VueUeditorWrap },
data() { data() {
return { return {
deptName: "",
defaultProps: {
children: "children",
label: "category_name",
},
//
statusOptions: [
{ value: 2, label: "上线" },
{ value: 1, label: "下线" },
],
categoryOptionsLeft: undefined,
tableKey: 0, tableKey: 0,
list: null, list: null,
total: 0, total: 0,
@ -171,6 +332,10 @@ export default {
listQuery: { listQuery: {
page: 1, page: 1,
limit: 20, limit: 20,
is_offline: 2,
title: "",
label_name: "",
category_id: undefined,
}, },
// accountRules: { // accountRules: {
// phone: [{ required: true, trigger: 'blur', validator: RulePhone }], // phone: [{ required: true, trigger: 'blur', validator: RulePhone }],
@ -180,238 +345,295 @@ export default {
UEDITOR_HOME_URL: "/UEditor/", UEDITOR_HOME_URL: "/UEditor/",
serverUrl: process.env.VUE_APP_BASE_API + "/files/baiduUp", serverUrl: process.env.VUE_APP_BASE_API + "/files/baiduUp",
initialFrameHeight: 300, initialFrameHeight: 300,
scaleEnabled:true scaleEnabled: true,
}, },
uploadAction: process.env.VUE_APP_BASE_API + '/files/uploadFile', uploadAction: process.env.VUE_APP_BASE_API + "/files/uploadFile",
temp: { temp: {
id: undefined, id: undefined,
category_id: undefined, category_id: undefined,
title: '', title: "",
time: '', time: "",
img: '', img: "",
script_url: '', script_url: "",
content: '', content: "",
description: '', description: "",
video_time: '' video_time: "",
}, },
dialogFullscreen: true, dialogFullscreen: true,
dialogFormVisible: false, dialogFormVisible: false,
dialogStatus: '', dialogStatus: "",
textMap: { textMap: {
update: 'Edit', update: "Edit",
create: 'Create' create: "Create",
}, },
rules: { rules: {
title: [{ required: true, message: 'title is required', trigger: 'blur' }] title: [
{ required: true, message: "title is required", trigger: "blur" },
],
}, },
categoryOptions: [], categoryOptions: [],
// categoriesJson:[], // categoriesJson:[],
downloadLoading: false, downloadLoading: false,
// tagData:[], // tagData:[],
chooseTagData:[] chooseTagData: [],
} //
validation: false,
};
}, },
mounted() { mounted() {
this.getList() this.getList();
this.getTreeselect() this.getTreeselect();
}, },
computed: { computed: {
categoriesJson() { categoriesJson() {
var res = this.handleCategory(this.categoryOptions) var res = this.handleCategory(this.categoryOptions);
return res return res;
}, },
tagData() { tagData() {
let matchData = null let matchData = null;
this.categoriesJson.forEach(item=>{ this.categoriesJson.forEach((item) => {
if(item.id==this.temp.category_id){ if (item.id == this.temp.category_id) {
matchData = item.label_name matchData = item.label_name;
} }
}) });
return matchData ? JSON.parse(matchData) : []; return matchData ? JSON.parse(matchData) : [];
} },
}, },
watch:{ watch: {
tagData(newVal) { tagData(newVal) {
console.log("tagDAta"); console.log("tagDAta");
console.log(newVal); console.log(newVal);
if (!newVal.length) { if (!newVal.length) {
this.chooseTagData = [] this.chooseTagData = [];
} }
}, },
chooseTagData(newVal){ chooseTagData(newVal) {
console.log("chooseTagData"); console.log("chooseTagData");
console.log(newVal); console.log(newVal);
} },
//
deptName(val) {
this.$refs.tree.filter(val);
},
}, },
filters: { filters: {
getCateName(id, categoriesJson) { getCateName(id, categoriesJson) {
for (var i=0;i<categoriesJson.length;i++) { for (var i = 0; i < categoriesJson.length; i++) {
if (id == categoriesJson[i].id) { if (id == categoriesJson[i].id) {
return categoriesJson[i].name return categoriesJson[i].name;
} }
} }
}, },
getTagDetail(data) { getTagDetail(data) {
if (!data) { if (!data) {
return return;
} }
let str='' let str = "";
data = JSON.parse(data); data = JSON.parse(data);
data.forEach(item=>{ data.forEach((item) => {
if (item.value.length) { if (item.value.length) {
str += `${item.label}${item.value.join("、")}` str += `${item.label}${item.value.join("、")}`;
} }
}) });
return str return str;
}, },
}, },
methods: { methods: {
//
async validationImages(file) {
let width = 0;
let height = 0;
console.log(this.temp);
switch (this.temp.category_id) {
case 23: //
width = 650;
height = 350;
break;
case 25: //
width = 130;
height = 130;
break;
case 24: //
width = 130;
height = 130;
break;
case 7: //
width = 380;
height = 220;
break;
case 6: //
width = 380;
height = 220;
break;
}
let res = await this.$getImgWidth(file, width, height);
this.validation = res;
return res;
},
//
handleNodeClick(data) {
this.listQuery.category_id = data.id;
this.getList();
},
handleCategory(array) { handleCategory(array) {
var res = [] var res = [];
array.forEach((item,index)=>{ array.forEach((item, index) => {
let obj={} let obj = {};
obj.id = item.category_id obj.id = item.category_id;
obj.name = item.category_name obj.name = item.category_name;
obj.label_name = item.label_name obj.label_name = item.label_name;
res.push(obj) res.push(obj);
if(item.children) { if (item.children) {
res.push(...this.handleCategory(item.children)) res.push(...this.handleCategory(item.children));
} }
}) });
return res return res;
},
//
filterNode(value, data) {
if (!value) return true;
return data.category_name.indexOf(value) !== -1;
}, },
getList() { getList() {
this.listLoading = true this.listLoading = true;
fetchList(this.listQuery).then(response => { fetchList(this.listQuery).then((response) => {
this.list = response.data.list console.log(response);
this.total = response.data.count this.list = response.data.list;
this.total = response.data.count;
// Just to simulate the time of the request // Just to simulate the time of the request
setTimeout(() => { setTimeout(() => {
this.listLoading = false this.listLoading = false;
}, 1.5 * 1000) }, 1.5 * 1000);
}) });
}, },
handleFilter() { handleFilter() {
this.listQuery.page = 1 this.listQuery.page = 1;
this.getList() this.getList();
}, },
handleModifyStatus(row, status) { handleModifyStatus(row, status) {
this.$message({ this.$message({
message: '操作Success', message: "操作Success",
type: 'success' type: "success",
}) });
row.status = status row.status = status;
}, },
resetTemp() { resetTemp() {
this.temp = { this.temp = {
id: undefined, id: undefined,
category_id: undefined, category_id: undefined,
title: '', title: "",
time: '', time: "",
img: '', img: "",
script_url: '', script_url: "",
content: '' content: "",
} description: "",
video_time: "",
};
}, },
submitForm() { submitForm() {
let matchData = [...this.tagData] let matchData = [...this.tagData];
this.chooseTagData.forEach((item,index)=>{ this.chooseTagData.forEach((item, index) => {
matchData[index]['value'] = item matchData[index]["value"] = item;
}) });
this.temp.label_name = JSON.stringify(matchData); this.temp.label_name = JSON.stringify(matchData);
if (this.dialogStatus == 'create') { if (this.dialogStatus == "create") {
this.createData() this.createData();
} else if (this.dialogStatus == 'update') { } else if (this.dialogStatus == "update") {
this.updateData() this.updateData();
} }
}, },
handleCreate() { handleCreate() {
this.resetTemp() this.resetTemp();
this.dialogStatus = 'create' this.temp.category_id = this.listQuery.category_id;
this.dialogFormVisible = true this.dialogStatus = "create";
this.dialogFormVisible = true;
this.$nextTick(() => { this.$nextTick(() => {
this.$refs['dataForm'].clearValidate() this.$refs["dataForm"].clearValidate();
}) });
}, },
createData() { createData() {
// this.$refs['dataForm'].validate((valid) => { // this.$refs['dataForm'].validate((valid) => {
// if (valid) { // if (valid) {
createArticle(this.temp).then(() => { createArticle(this.temp).then(() => {
this.dialogFormVisible = false this.dialogFormVisible = false;
this.$message({ this.$message({
message: "添加成功", message: "添加成功",
type: "success", type: "success",
duration: 2 * 1000, duration: 2 * 1000,
}); });
this.getList() this.getList();
}) });
// } // }
// }) // })
}, },
handleUpdate(row) { handleUpdate(row) {
let article_id = row.article_id let article_id = row.article_id;
fetchArticleDetails({article_id}).then(res => { this.dialogStatus = "update";
this.resetTemp();
this.dialogFormVisible = true;
fetchArticleDetails({ article_id }).then((res) => {
this.temp = res.data; this.temp = res.data;
if (this.temp.label_name) { if (this.temp.label_name) {
let data = JSON.parse(this.temp.label_name) let data = JSON.parse(this.temp.label_name);
data.forEach((item,index)=>{ data.forEach((item, index) => {
this.chooseTagData[index] = item.value this.chooseTagData[index] = item.value;
}) });
} }
this.dialogStatus = 'update'
this.dialogFormVisible = true
this.$nextTick(() => { this.$nextTick(() => {
this.$refs['dataForm'].clearValidate() this.$refs["dataForm"].clearValidate();
}) });
}) });
}, },
updateData() { updateData() {
// this.$refs['dataForm'].validate((valid) => { // this.$refs['dataForm'].validate((valid) => {
// if (valid) { // if (valid) {
updateArticle(this.temp).then(() => { updateArticle(this.temp).then(() => {
this.dialogFormVisible = false this.dialogFormVisible = false;
this.$message({ this.$message({
message: "更新成功", message: "更新成功",
type: "success", type: "success",
duration: 2 * 1000, duration: 2 * 1000,
}); });
this.getList() this.getList();
}) });
// } // }
// }) // })
}, },
handleDelete({title,article_id}) { handleDelete({ title, article_id }) {
this.$confirm('是否确认删除名称为"' + title + '"的数据项?', '警告', { this.$confirm('是否确认删除名称为"' + title + '"的数据项?', "警告", {
confirmButtonText: '确定', confirmButtonText: "确定",
cancelButtonText: '取消', cancelButtonText: "取消",
type: 'warning' type: "warning",
}).then(function() { })
console.log('del') .then(function () {
return delArticle({ article_id }) console.log("del");
}).then((response) => { return delArticle({ article_id });
if (response.code === 200) { })
this.$message({ .then((response) => {
message: "删除分类成功", if (response.code === 200) {
type: "success", this.$message({
duration: 2 * 1000, message: "删除分类成功",
}); type: "success",
this.open = false duration: 2 * 1000,
this.getList() });
} else { this.open = false;
this.$message({ this.getList();
message: "删除分类失败", } else {
type: "error", this.$message({
duration: 2 * 1000, message: "删除分类失败",
}); type: "error",
} duration: 2 * 1000,
}).catch(function() {}) });
}
})
.catch(function () {});
}, },
uploadSuccess(response, file) { uploadSuccess(response, file) {
if (response.state == 'SUCCESS') { console.log(response);
this.temp.img = response.url if (response.state == "SUCCESS" && this.validation) {
this.temp.img = response.url;
} }
// const uid = file.uid; // const uid = file.uid;
// const objKeyArr = Object.keys(this.listObj); // const objKeyArr = Object.keys(this.listObj);
@ -424,12 +646,12 @@ export default {
// } // }
}, },
uploadFileSuccess(response, file) { uploadFileSuccess(response, file) {
let obj = {} let obj = {};
obj.name = response.original obj.name = response.original;
obj.url = response.url obj.url = response.url;
this.temp.script_url = JSON.stringify(obj) this.temp.script_url = JSON.stringify(obj);
}, },
handleFileExceed(files, fileList){ handleFileExceed(files, fileList) {
this.$message.warning("只允许上传一个脚本"); this.$message.warning("只允许上传一个脚本");
}, },
uploadRemove(file) { uploadRemove(file) {
@ -450,45 +672,42 @@ export default {
}, },
/** 查询分类下拉树结构 */ /** 查询分类下拉树结构 */
getTreeselect() { getTreeselect() {
listCategory().then(response => { listCategory().then((response) => {
this.categoryOptions = [] this.categoryOptions = [];
this.categoryOptions.push(...response.data) this.categoryOptions.push(...response.data);
}) });
}, },
/** 转换分类数据结构 */ /** 转换分类数据结构 */
normalizer(node) { normalizer(node) {
if (node.children && !node.children.length) { if (node.children && !node.children.length) {
delete node.children delete node.children;
} }
return { return {
id: node.category_id, id: node.category_id,
label: node.category_name, label: node.category_name,
children: node.children children: node.children,
} };
}, },
// //
chooseCategory(node){ chooseCategory(node) {
this.tagData = node.label_name ? JSON.parse(node.label_name) : []; this.tagData = node.label_name ? JSON.parse(node.label_name) : [];
} },
} },
} };
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.app-container { .app-container {
.filter-container { .filter-container {
margin-left: 5px; margin-left: 5px;
margin-bottom: 6px; margin-bottom: 6px;
} }
::v-deep .el-drawer__body{ ::v-deep .el-drawer__body {
padding: 20px; padding: 20px;
} }
::v-deep section { .editor-box {
overflow-y: scroll; ::v-deep .el-form-item__content {
} line-height: 20px;
.editor-box {
::v-deep .el-form-item__content {
line-height: 20px;
}
} }
} }
}
</style> </style>

675
src/views/menu/index.vue

@ -1,270 +1,287 @@
<template> <template>
<el-card class="box-card"> <el-card class="box-card">
<el-form :inline="true"> <el-form :inline="true">
<el-form-item label="菜单名称"> <el-form-item label="菜单名称">
<el-input <el-input
v-model="queryParams.title" v-model="queryParams.title"
placeholder="请输入菜单名称" placeholder="请输入菜单名称"
clearable clearable
size="small" size="small"
@keyup.enter.native="handleQuery" @keyup.enter.native="handleQuery"
/> />
</el-form-item> </el-form-item>
<el-form-item label="状态"> <el-form-item label="状态">
<el-select v-model="queryParams.visible" placeholder="菜单状态" clearable size="small"> <el-select v-model="queryParams.visible" placeholder="菜单状态" clearable size="small">
<el-option <el-option
v-for="dict in visibleOptions" v-for="dict in visibleOptions"
:key="dict.value" :key="dict.value"
:label="dict.label" :label="dict.label"
:value="dict.value" :value="dict.value"
/> />
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button> <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
<el-button <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAdd">新增</el-button>
type="primary" </el-form-item>
icon="el-icon-plus" </el-form>
size="mini"
@click="handleAdd"
>新增</el-button>
</el-form-item>
</el-form>
<el-table
v-loading="loading"
:data="menuList"
border
row-key="id"
:tree-props="{children: 'children', hasChildren: 'hasChildren'}"
>
<el-table-column prop="title" label="菜单名称" :show-overflow-tooltip="true" width="180px" />
<el-table-column prop="icon" label="图标" align="center" width="100px">
<template slot-scope="scope">
<svg-icon :icon-class="scope.row.icon" />
</template>
</el-table-column>
<el-table-column prop="sort" label="排序" width="60px" />
<el-table-column prop="path" label="组件路径" :show-overflow-tooltip="true">
<template slot-scope="scope">
<span v-if="scope.row.menuType=='A'">{{ scope.row.path }}</span>
<span v-else>{{ scope.row.component }}</span>
</template>
</el-table-column>
<el-table-column label="创建时间" align="center" prop="createdAt" width="180">
<template slot-scope="scope">
<span>{{ scope.row.create_time }}</span>
</template>
</el-table-column>
<el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="180">
<template slot-scope="scope">
<el-button
size="mini"
type="text"
icon="el-icon-edit"
@click="handleUpdate(scope.row)"
>修改</el-button>
<el-button
size="mini"
type="text"
icon="el-icon-plus"
@click="handleAdd(scope.row)"
>新增</el-button>
<el-button
size="mini"
type="text"
icon="el-icon-delete"
@click="handleDelete(scope.row)"
>删除</el-button>
</template>
</el-table-column>
</el-table>
<!-- 添加或修改菜单对话框 --> <el-table
<el-drawer v-loading="loading"
ref="drawer" :data="menuList"
:title="title" border
:before-close="cancel" row-key="id"
:visible.sync="open" :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
direction="rtl" >
custom-class="demo-drawer" <el-table-column prop="title" label="菜单名称" :show-overflow-tooltip="true" width="180px" />
size="830px" <el-table-column prop="icon" label="图标" align="center" width="100px">
> <template slot-scope="scope">
<div class="demo-drawer__content"> <svg-icon :icon-class="scope.row.icon" />
<el-form ref="form" :model="form" :rules="rules" label-position="top" label-width="106px"> </template>
<el-row> </el-table-column>
<el-col :span="24"> <el-table-column prop="sort" label="排序" width="60px" />
<el-form-item prop="parentId"> <el-table-column prop="path" label="组件路径" :show-overflow-tooltip="true">
<span slot="label"> <template slot-scope="scope">
上级菜单 <span v-if="scope.row.menuType == 'A'">{{ scope.row.path }}</span>
<el-tooltip content="指当前菜单停靠的菜单归属" placement="top"> <span v-else>{{ scope.row.component }}</span>
<i class="el-icon-question" /> </template>
</el-tooltip> </el-table-column>
</span> <el-table-column label="创建时间" align="center" prop="createdAt" width="180">
<!-- <treeselect <template slot-scope="scope">
v-model="form.parentId" <span>{{ scope.row.create_time }}</span>
:options="menuOptions" </template>
:normalizer="normalizer" </el-table-column>
:show-count="true" <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="180">
placeholder="选择上级菜单" <template slot-scope="scope">
/> --> <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)">修改</el-button>
</el-form-item> <el-button size="mini" type="text" icon="el-icon-plus" @click="handleAdd(scope.row)">新增</el-button>
</el-col> <el-button
<el-col :span="12"> size="mini"
<el-form-item prop="title"> type="text"
<span slot="label"> icon="el-icon-delete"
菜单标题 @click="handleDelete(scope.row)"
<el-tooltip content="菜单位置显示的说明信息" placement="top"> >删除</el-button>
<i class="el-icon-question" /> </template>
</el-tooltip> </el-table-column>
</span> </el-table>
<el-input v-model="form.title" placeholder="请输入菜单标题" />
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item prop="sort">
<span slot="label">
显示排序
<el-tooltip content="根据序号升序排列" placement="top">
<i class="el-icon-question" />
</el-tooltip>
</span>
<el-input-number v-model="form.sort" controls-position="right" :min="0" />
</el-form-item>
</el-col>
<el-col :span="24"> <!-- 添加或修改菜单对话框 -->
<el-form-item prop="menuType"> <el-drawer
<span slot="label"> ref="drawer"
菜单类型 :title="title"
<el-tooltip content="包含目录:以及菜单或者菜单组,菜单:具体对应某一个页面,按钮:功能才做按钮;" placement="top"> :before-close="cancel"
<i class="el-icon-question" /> :visible.sync="open"
</el-tooltip> direction="rtl"
</span> custom-class="demo-drawer"
<el-radio-group v-model="form.menuType"> size="830px"
<el-radio label="M">目录</el-radio> >
<el-radio label="C">菜单</el-radio> <div class="demo-drawer__content">
<el-radio label="F">按钮</el-radio> <el-form ref="form" :model="form" :rules="rules" label-position="top" label-width="106px">
</el-radio-group> <el-row>
</el-form-item> <el-col :span="24">
</el-col> <el-form-item prop="parentId">
<el-col :span="24"> <span slot="label">
<el-form-item label="菜单图标"> 上级菜单
<el-popover <el-tooltip content="指当前菜单停靠的菜单归属" placement="top">
placement="bottom-start" <i class="el-icon-question" />
width="460" </el-tooltip>
trigger="click" </span>
@show="$refs['iconSelect'].reset()" <treeselect
> v-model="form.fid"
<IconSelect ref="iconSelect" @selected="selected" /> :options="menuOptions"
<el-input slot="reference" v-model="form.icon" placeholder="点击选择图标" readonly> :normalizer="normalizer"
<svg-icon :show-count="true"
v-if="form.icon" placeholder="选择上级菜单"
slot="prefix" />
:icon-class="form.icon" </el-form-item>
class="el-input__icon" </el-col>
style="height: 32px;width: 16px;" <el-col :span="12">
/> <el-form-item prop="title">
<i v-else slot="prefix" class="el-icon-search el-input__icon" /> <span slot="label">
</el-input> 菜单标题
</el-popover> <el-tooltip content="菜单位置显示的说明信息" placement="top">
</el-form-item> <i class="el-icon-question" />
</el-col> </el-tooltip>
<el-col :span="12"> </span>
<el-form-item v-if="form.menuType == 'M' || form.menuType == 'C'" prop="menuName"> <el-input v-model="form.title" placeholder="请输入菜单标题" />
<span slot="label"> </el-form-item>
路由名称 </el-col>
<el-tooltip content="需要和页面name保持一致,对应页面即可选择缓存" placement="top"> <el-col :span="12">
<i class="el-icon-question" /> <el-form-item prop="sort">
</el-tooltip> <span slot="label">
</span> 显示排序
<el-input v-model="form.menuName" placeholder="请输入路由名称" /> <el-tooltip content="根据序号升序排列" placement="top">
</el-form-item> <i class="el-icon-question" />
</el-col> </el-tooltip>
</span>
<el-input-number v-model="form.sort" controls-position="right" :min="0" />
</el-form-item>
</el-col>
<el-col v-if="form.menuType == 'M' || form.menuType == 'C'" :span="12"> <el-col :span="12">
<el-form-item prop="component"> <el-form-item prop="menu_name">
<span slot="label"> <span slot="label">
组件路径 路由名称
<el-tooltip content="菜单对应的具体vue页面文件路径views的下级路径/admin/sys-api/index;目录类型:填写Layout,如何有二级目录请参照日志目录填写;" placement="top"> <el-tooltip content="需要和页面name保持一致,对应页面即可选择缓存" placement="top">
<i class="el-icon-question" /> <i class="el-icon-question" />
</el-tooltip> </el-tooltip>
</span> </span>
<el-input v-model="form.component" placeholder="请输入组件路径" /> <el-input v-model="form.menu_name" placeholder="请输入路由名称" />
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col :span="12"> <el-col :span="12">
<el-form-item v-if="form.menuType == 'M' || form.menuType == 'C'"> <el-form-item prop="component">
<span slot="label"> <span slot="label">
是否外链 组件路径
<el-tooltip content="可以通过iframe打开指定地址" placement="top"> <el-tooltip
<i class="el-icon-question" /> content="菜单对应的具体vue页面文件路径views的下级路径/admin/sys-api/index;目录类型:填写Layout,如何有二级目录请参照日志目录填写;"
</el-tooltip> placement="top"
</span> >
<el-radio-group v-model="form.isFrame"> <i class="el-icon-question" />
<el-radio label="0"></el-radio> </el-tooltip>
<el-radio label="1"></el-radio> </span>
</el-radio-group> <el-input v-model="form.component" placeholder="请输入组件路径" />
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col :span="12"> <el-col :span="12">
<el-form-item v-if="form.menuType != 'F'" prop="path"> <el-form-item v-if="form.menuType != 'F'" prop="path">
<span slot="label"> <span slot="label">
路由地址 路由地址
<el-tooltip content="访问此页面自定义的url地址,建议/开头书写,例如 /app-name/menu-name" placement="top"> <el-tooltip
<i class="el-icon-question" /> content="访问此页面自定义的url地址,建议/开头书写,例如 /app-name/menu-name"
</el-tooltip> placement="top"
</span> >
<el-input v-model="form.path" placeholder="请输入路由地址" /> <i class="el-icon-question" />
</el-form-item> </el-tooltip>
</el-col> </span>
<el-input v-model="form.path" placeholder="请输入路由地址" />
</el-form-item>
</el-col>
<el-col :span="12"> <el-col :span="12">
<el-form-item v-if="form.menuType == 'F' || form.menuType == 'C'"> <el-form-item v-if="form.menuType == 'F' || form.menuType == 'C'">
<span slot="label"> <span slot="label">
权限标识 权限标识
<el-tooltip content="前端权限控制按钮是否显示" placement="top"> <el-tooltip content="前端权限控制按钮是否显示" placement="top">
<i class="el-icon-question" /> <i class="el-icon-question" />
</el-tooltip> </el-tooltip>
</span> </span>
<el-input v-model="form.permission" placeholder="请权限标识" maxlength="50" /> <el-input v-model="form.permission" placeholder="请权限标识" maxlength="50" />
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col :span="12"> <el-col :span="12">
<el-form-item v-if="form.menuType != 'F'"> <el-form-item v-if="form.menuType != 'F'">
<span slot="label"> <span slot="label">
菜单状态 菜单状态
<el-tooltip content="需要显示在菜单列表的菜单设置为显示,否则设置为隐藏" placement="top"> <el-tooltip content="需要显示在菜单列表的菜单设置为显示,否则设置为隐藏" placement="top">
<i class="el-icon-question" /> <i class="el-icon-question" />
</el-tooltip> </el-tooltip>
</span> </span>
<el-radio-group v-model="form.visible"> <el-radio-group v-model="form.visible">
<el-radio <el-radio
v-for="dict in visibleOptions" v-for="dict in visibleOptions"
:key="dict.value" :key="dict.value"
:label="dict.value" :label="dict.value"
>{{ dict.label }}</el-radio> >{{ dict.label }}</el-radio>
</el-radio-group> </el-radio-group>
</el-form-item> </el-form-item>
</el-col> </el-col>
</el-row> <el-col :span="12">
</el-form> <el-form-item>
<div class="demo-drawer__footer"> <span slot="label">
<el-button type="primary" @click="submitForm"> </el-button> 菜单栏状态
<el-button @click="cancel"> </el-button> <el-tooltip content="需要显示菜单列表的设置为显示,否则设置为隐藏" placement="top">
</div> <i class="el-icon-question" />
</div> </el-tooltip>
</span>
</el-drawer> <el-radio-group v-model="form.show_sidebar">
</el-card> <el-radio
v-for="dict in visibleOptions"
:key="dict.value"
:label="dict.value"
>{{ dict.label }}</el-radio>
</el-radio-group>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item>
<span slot="label">
标签栏状态
<el-tooltip content="需要显示标签栏的设置为显示,否则设置为隐藏" placement="top">
<i class="el-icon-question" />
</el-tooltip>
</span>
<el-radio-group v-model="form.show_tags">
<el-radio
v-for="dict in showTagsOptions"
:key="dict.value"
:label="dict.value"
>{{ dict.label }}</el-radio>
</el-radio-group>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item>
<span slot="label">
底部栏状态
<el-tooltip content="需要显示底部工具栏的设置为显示,否则设置为隐藏" placement="top">
<i class="el-icon-question" />
</el-tooltip>
</span>
<el-radio-group v-model="form.show_bottom">
<el-radio
v-for="dict in showBottomOptions"
:key="dict.value"
:label="dict.value"
>{{ dict.label }}</el-radio>
</el-radio-group>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item>
<span slot="label">
是否隐藏面包屑
</span>
<el-radio-group v-model="form.hide_breadcrumb">
<el-radio
v-for="dict in hideBreadcrumbOptions"
:key="dict.value"
:label="dict.value"
>{{ dict.label }}</el-radio>
</el-radio-group>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item>
<span slot="label">
参数
<el-tooltip
content="非技术人员请勿修改"
placement="top"
>
<i class="el-icon-question" />
</el-tooltip>
</span>
<el-input v-model="form.params" placeholder="" />
</el-form-item>
</el-col>
</el-row>
</el-form>
<div class="demo-drawer__footer">
<el-button type="primary" @click="submitForm"> </el-button>
<el-button @click="cancel"> </el-button>
</div>
</div>
</el-drawer>
</el-card>
</template> </template>
<script> <script>
import { listMenu, getMenu, delMenu, addMenu, updateMenu } from '@/api/menu' import { listMenu, getMenu, delMenu, addMenu, updateMenu } from '@/api/menu'
const Treeselect = require('@riophae/vue-treeselect') import Treeselect from '@riophae/vue-treeselect'
import '@riophae/vue-treeselect/dist/vue-treeselect.css' import '@riophae/vue-treeselect/dist/vue-treeselect.css'
import IconSelect from '@/components/IconSelect' import IconSelect from '@/components/IconSelect'
@ -284,7 +301,22 @@ export default {
// //
open: false, open: false,
// //
visibleOptions: [], visibleOptions: [
{value: false, label: "隐藏"},
{value: true, label: "显示"}
],
showBottomOptions: [
{value: false, label: "隐藏"},
{value: true, label: "显示"}
],
showTagsOptions: [
{value: false, label: "隐藏"},
{value: true, label: "显示"}
],
hideBreadcrumbOptions: [
{value: false, label: "否"},
{value: true, label: "是"}
],
// //
queryParams: { queryParams: {
title: undefined, title: undefined,
@ -293,7 +325,22 @@ export default {
}, },
// //
form: { form: {
apis: [], id: undefined,
fid: 0,
title: undefined,
menu_name: undefined,
icon: undefined,
menu_type: 'user',
component: undefined,
path: undefined,
sort: 0,
visible: '0',
no_cache: 1,
show_sidebar: 1,
show_tags: 1,
show_bottom: 1,
is_hot: 0,
params: undefined
}, },
// //
rules: { rules: {
@ -341,19 +388,17 @@ export default {
delete node.children delete node.children
} }
return { return {
id: node.menuId, id: node.id,
label: node.title, label: node.title,
children: node.children children: node.children
} }
}, },
/** 查询菜单下拉树结构 */ /** 查询菜单下拉树结构 */
getTreeselect() { getTreeselect() {
listMenu().then(response => { this.menuOptions = []
this.menuOptions = [] const menu = { id: 0, title: '主类目', children: [] }
const menu = { menuId: 0, title: '主类目', children: [] } menu.children = this.menuList
menu.children = response.data this.menuOptions.push(menu)
this.menuOptions.push(menu)
})
}, },
// //
cancel() { cancel() {
@ -363,18 +408,23 @@ export default {
// //
reset() { reset() {
this.form = { this.form = {
menuId: undefined, id: undefined,
parentId: 0, fid: 0,
menuName: undefined, title: undefined,
menu_name: undefined,
icon: undefined, icon: undefined,
menuType: 'M', menu_type: 'user',
apis: [], component: undefined,
path: undefined,
sort: 0, sort: 0,
action: this.form.menuType === 'A' ? this.form.action : '', visible: '0',
isFrame: '1', no_cache: 1,
visible: '0' show_sidebar: 1,
show_tags: 1,
show_bottom: 1,
is_hot: 0,
params: undefined
} }
this.resetForm('form')
}, },
/** 搜索按钮操作 */ /** 搜索按钮操作 */
handleQuery() { handleQuery() {
@ -385,51 +435,57 @@ export default {
this.reset() this.reset()
this.getTreeselect() this.getTreeselect()
if (row != null) { if (row != null) {
this.form.parentId = row.menuId this.form.fid = row.id
} }
this.open = true this.open = true
this.title = '添加菜单' this.title = '添加菜单'
}, },
/** 修改按钮操作 */ /** 修改按钮操作 */
handleUpdate(row) { handleUpdate(row) {
console.log(row)
this.reset() this.reset()
this.getTreeselect() this.getTreeselect()
getMenu(row.menuId).then(response => { // getMenu(row.menuId).then(response => {
this.form = response.data this.form = row
this.open = true this.open = true
this.title = '修改菜单' this.title = '修改菜单'
}) // })
},
setApis(apiArray) {
var l = []
for (var index = 0; index < apiArray.length; index++) {
const element = apiArray[index]
l.push(element.id)
}
this.form.apis = l
}, },
/** 提交按钮 */ /** 提交按钮 */
submitForm: function() { submitForm: function () {
delete this.form.children
this.$refs['form'].validate(valid => { this.$refs['form'].validate(valid => {
if (valid) { if (valid) {
if (this.form.menuId !== undefined) { if (this.form.id !== undefined) {
updateMenu(this.form, this.form.menuId).then(response => { updateMenu(this.form).then(response => {
if (response.code === 200) { if (response.code === 200) {
this.msgSuccess(response.msg) this.$message({
message: response.msg,
type: 'success'
})
this.open = false this.open = false
this.getList() this.getList()
} else { } else {
this.msgError(response.msg) this.$message({
message: response.msg,
type: 'error'
})
} }
}) })
} else { } else {
addMenu(this.form).then(response => { addMenu(this.form).then(response => {
if (response.code === 200) { if (response.code === 200) {
this.msgSuccess(response.msg) this.$message({
message: response.msg,
type: 'success'
})
this.open = false this.open = false
this.getList() this.getList()
} else { } else {
this.msgError(response.msg) this.$message({
message: response.msg,
type: 'error'
})
} }
}) })
} }
@ -442,37 +498,42 @@ export default {
confirmButtonText: '确定', confirmButtonText: '确定',
cancelButtonText: '取消', cancelButtonText: '取消',
type: 'warning' type: 'warning'
}).then(function() { }).then(function () {
var Ids = (row.menuId && [row.menuId]) || this.ids return delMenu({ 'id': row.id })
return delMenu({ 'ids': Ids })
}).then((response) => { }).then((response) => {
if (response.code === 200) { if (response.code === 200) {
this.msgSuccess(response.msg) this.$message({
message: response.msg,
type: 'success'
})
this.open = false this.open = false
this.getList() this.getList()
} else { } else {
this.msgError(response.msg) this.$message({
message: response.msg,
type: 'error'
})
} }
}).catch(function() {}) }).catch(function () { })
} }
} }
} }
</script> </script>
<style lang="css"> <style lang="css">
.panel .el-transfer__buttons{ .panel .el-transfer__buttons {
width: 150px; width: 150px;
} }
.panel .el-transfer__buttons .el-button + .el-button{ .panel .el-transfer__buttons .el-button + .el-button {
margin-left:0; margin-left: 0;
} }
.panel .el-transfer-panel{ .panel .el-transfer-panel {
width: 300px; width: 300px;
} }
.el-col { .el-col {
padding: 0 5px; padding: 0 5px;
} }
.el-drawer__header{ .el-drawer__header {
margin-bottom: 0; margin-bottom: 0;
} }
</style> </style>
|||||||
100:0
Loading…
Cancel
Save