123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367 |
- <template>
- <div class="navigation">
- <!-- 头部细节部分 -->
- <div class="title">
- <el-row>
- <el-col :span="24">
- <div class="top">
- <el-button type="success" style="margin-left: 1%;" @click="addNew">新增</el-button>
- <el-button type="success" style="margin-left: 1%;" @click="openChange">修改</el-button>
- <el-button type="success" style="margin-left: 1%;" @click="DeleteMenu">删除</el-button>
- </div>
- </el-col>
- </el-row>
- </div>
- <!-- 头部细节部分结束 -->
- <el-row>
- <el-col :span="24">
- <div class="grid-content bg-purple-dark">
- <el-tree
- v-loading="loading"
- :data="menuList"
- show-checkbox
- default-expand-all
- check-strictly
- node-key="id"
- ref="tree"
- highlight-current
- @check="handleCheckChange"
- :props="defaultProps">
- </el-tree>
- </div>
- </el-col>
- </el-row>
- <!-- 新增菜单 -->
- <el-dialog
- @close="handleEditDialogClose"
- :visible.sync="addUserList">
- <div class="tou">导航--添加</div>
- <div class="line"></div>
- <el-form
- label-position="right"
- label-width="100px"
- :model="formMenuList">
- <el-form-item label="导航名称">
- <el-input v-model.string="formMenuList.name" auto-complete="off" placeholder="请输入导航名称"></el-input>
- </el-form-item>
- <el-form-item label="父级id">
- <el-input v-model.string="formMenuList.parentId" auto-complete="off" placeholder="请输入父级节点id"></el-input>
- </el-form-item>
- <el-form-item label="导航级数">
- <el-input v-model.string="formMenuList.level" auto-complete="off" placeholder="请输入导航级数"></el-input>
- </el-form-item>
- <el-form-item label="路由路径">
- <el-input v-model.string="formMenuList.goPageUrl" auto-complete="off" placeholder="请输入路由路径"></el-input>
- </el-form-item>
- <el-form-item label="是否首页展示">
- <el-select v-model="formMenuList.homePageFlag" placeholder="是否首页展示" style="width: 100%">
- <el-option
- v-for="item in option"
- :key="item.value"
- :label="item.label"
- :value="item.value">
- </el-option>
- </el-select>
- </el-form-item>
- <el-form-item label="菜单排序">
- <el-input v-model="formMenuList.homePageOrder" auto-complete="off" placeholder="请输入菜单排序"></el-input>
- </el-form-item>
- </el-form>
- <div slot="footer" class="dialog-footer">
- <el-button @click="addUserList = false" type="info">取 消</el-button>
- <el-button type="primary" @click="addData">新 增</el-button>
- </div>
- </el-dialog>
- <!-- 修改菜单 -->
- <el-dialog
- @close="handleEditDialogClose"
- :visible.sync="changeUser">
- <div class="tou">导航--修改</div>
- <div class="line"></div>
- <el-form
- label-position="right"
- label-width="100px"
- :model="formMenuchangeList">
- <el-form-item label="导航名称">
- <el-input v-model.string="formMenuchangeList.name" auto-complete="off" placeholder="请输入导航名称"></el-input>
- </el-form-item>
- <el-form-item label="本级导航id">
- <el-input v-model.string="formMenuchangeList.id" auto-complete="off" placeholder=" 请输入父级节点id"></el-input>
- </el-form-item>
- <el-form-item label="路由路径">
- <el-input v-model.string="formMenuchangeList.goPageUrl" auto-complete="off" placeholder="请输入路由路径"></el-input>
- </el-form-item>
- <el-form-item label="是否首页展示">
- <el-select v-model="formMenuchangeList.homePageFlag" placeholder="是否首页展示" style="width: 100%">
- <el-option
- v-for="item in option"
- :key="item.value"
- :label="item.label"
- :value="item.value">
- </el-option>
- </el-select>
- </el-form-item>
- <el-form-item label="菜单排序">
- <el-input v-model="formMenuchangeList.homePageOrder" auto-complete="off" placeholder="请输入菜单排序"></el-input>
- </el-form-item>
- </el-form>
- <div slot="footer" class="dialog-footer">
- <el-button @click="changeUser = false" type="info">取 消</el-button>
- <el-button type="primary" @click="changeData">修 改</el-button>
- </div>
- </el-dialog>
- </div>
- </template>
- <script type="text/javascript">
- export default{
- data() {
- return {
- // loading: true,
- option: [{
- value: '1',
- label: '首页不展示'
- }, {
- value: '2',
- label: '首页展示'
- }],
- formMenuList: {
- "name": "",
- "parentId": "",
- "level": "",
- "goPageUrl": "",
- "homePageFlag": "",
- "homePageOrder": ""
- },
- formMenuchangeList: {
- "id": "",
- "name": "",
- "goPageUrl": "",
- "homePageFlag": "",
- "homePageOrder": ""
- },
- menuList: [],
- dataList: '',
- addUserList: false,
- changeUser: false,
- defaultProps: {
- children: 'childList',
- label: 'name'
- },
- }
- },
- created() {
- this.loadData();
- },
- methods: {
- async loadData() {
- const response = await this.$http.get(`app/menu`);
- if (response.data.code === 1) {
- // console.log(response.data.responseData)
- this.menuList = response.data.responseData;
- this.loading = false;
- }
- },
- // 选择中的时候获取当前Id
- handleCheckChange(data, checked, indeterminate) {
- this.dataList = data;
- },
- // 增加菜单
- addNew() {
- this.addUserList = true;
- this.formMenuList.parentId = this.dataList.id;
- },
- // 新增导航
- async addData() {
- const formData = new FormData();
- formData.append('name', this.formMenuList.name);
- formData.append('parentId', this.formMenuList.parentId);
- formData.append('level', this.formMenuList.level);
- formData.append('goPageUrl', this.formMenuList.goPageUrl);
- formData.append('homePageFlag', this.formMenuList.homePageFlag);
- formData.append('homePageOrder', this.formMenuList.homePageOrder);
- const response = await this.$http.post(`app/menu`,formData);
- if(response.data.code === 1) {
- this.loadData();
- this.addUserList = false;
- this.$message({
- type: 'success',
- message: '添加成功'
- });
- }else {
- this.$message({
- type: 'error',
- message: '添加失败'
- });
- }
- },
- // 修改前判断
- openChange() {
- if(this.dataList == '') {
- this.$message.error('请选择要修改的单条数据');
- this.changeUser = false;
- return;
- };
- if(this.dataList.homePageFlag == 1) {
- this.formMenuchangeList.homePageFlag = '首页不展示'
- };
- if(this.dataList.homePageFlag == 2) {
- this.formMenuchangeList.homePageFlag = '首页展示'
- };
- this.changeUser = true;
- this.formMenuchangeList.id = this.dataList.id;
- this.formMenuchangeList.name = this.dataList.name;
- this.formMenuchangeList.goPageUrl = this.dataList.goPageUrl;
- if(this.dataList.homePageOrder == null) {
- this.formMenuchangeList.homePageOrder = '';
- }else {
- this.formMenuchangeList.homePageOrder = this.dataList.homePageOrder;
- }
- // this.formMenuchangeList.homePageFlag = this.dataList.homePageFlag;
- console.log(this.formMenuchangeList.homePageOrder)
- },
- // 修改导航
- async changeData () {
- if(this.formMenuchangeList.homePageFlag == '首页不展示') {
- this.formMenuchangeList.homePageFlag = 1
- };
- if(this.formMenuchangeList.homePageFlag == '首页展示') {
- this.formMenuchangeList.homePageFlag = 2
- };
- const formData = new FormData();
- formData.append('name', this.formMenuchangeList.name);
- formData.append('id', this.formMenuchangeList.id);
- formData.append('goPageUrl', this.formMenuchangeList.goPageUrl);
- formData.append('homePageFlag', this.formMenuchangeList.homePageFlag);
- formData.append('homePageOrder', this.formMenuchangeList.homePageOrder);
- const response = await this.$http.put(`app/menu`,formData);
- if(response.data.code === 1) {
- this.loadData();
- this.changeUser = false;
- this.$message({
- type: 'success',
- message: '修改成功'
- });
- }else {
- this.$message({
- type: 'error',
- message: '修改失败'
- });
- }
- },
- // 删除导航
- DeleteMenu() {
- if(this.dataList == '') {
- this.$message.error('请选择要删除的单条数据');
- return;
- }
- this.formMenuchangeList.menuId = this.dataList.id;
- this.$confirm('是否删除该分类', '提示' ,{
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- type: 'warning'
- }).then(async () => {
- const response = await this.$http.put(`app/menu/${this.formMenuchangeList.menuId}`);
- if(response.data.code === 1) {
- this.loadData();
- this.dataList = '';
- this.$message({
- type: 'success',
- message: '删除成功'
- });
- }else {
- this.$message({
- type: 'error',
- message: '删除失败'
- });
- }
- }).catch(() => {
- this.$message({ type: 'info', message: '已取消删除'});
- });
- },
- // 清空表单数据
- handleEditDialogClose() {
- for (var key in this.formMenuchangeList) {
- this.formMenuchangeList[key] = '';
- }
- for (var key in this.formMenuList) {
- this.formMenuList[key] = "";
- }
- this.$refs.tree.setCheckedKeys([]);
- this.dataList = '';
- },
- }
- };
- </script>
- <style>
- .navigation {
- border: 1px solid #d9d9d9;
- border-radius: 10px;
- }
- .navigation .title {
- font-size: 5px;
- margin-bottom: 20px;
- }
- .navigation .top {
- padding-top: 20px;
- padding-left: 20px;
- }
- .navigation .text {
- display: inline-block;
- color: #000;
- font-size: 16px ;
- margin-left: 1%;
- }
- .navigation .input-demo {
- display: inline-block;
- width: 20%;
- margin-left: 1%;
- }
- .navigation .block {
- font-size: 5px;
- text-align: center;
- margin-top: 25px;
- margin-bottom: 25px;
- }
- .navigation .el-dialog {
- width: 60%;
- }
- .navigation .el-dialog__header, .el-dialog__body {
- padding: 0 20px;
- }
- .navigation .tou {
- font-size: 20px;
- height: 30px;
- line-height: 30px;
- padding-top: 15px;
- }
- .navigation .line {
- margin-top: 15px;
- margin-bottom: 15px;
- width: 100%;
- height: 2px;
- background-color: #d9d9d9;
- }
- .navigation .xinxi {
- text-align: center;
- margin: 15px auto;
- font-size: 18px;
- }
- </style>
|