index.vue 21.3 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618
<!--
MIT License

Copyright (c) 2020 www.joolun.com

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
-->
<template>
  <div class="app-container">
    <!-- 搜索工作栏 -->
    <el-form ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="公众号" prop="accountId">
        <el-select v-model="accountId" placeholder="请选择公众号">
          <el-option v-for="item in accounts" :key="parseInt(item.id)" :label="item.name" :value="parseInt(item.id)" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <div class="public-account-management clearfix" v-loading="loading">
      <!--左边配置菜单-->
      <div class="left">
        <div class="weixin-hd">
            <div class="weixin-title">{{menuName}}</div>
        </div>
        <div class="weixin-menu menu_main clearfix">
          <div class="menu_bottom" v-for="(item, i) of menuList" :key="i" >
            <!-- 一级菜单 -->
            <div @click="menuClick(i, item)" class="menu_item el-icon-s-fold" :class="{'active': isActive === i}">{{item.name}}</div>
            <!-- 以下为二级菜单-->
            <div class="submenu" v-if="isSubMenuFlag === i">
              <div class="subtitle menu_bottom" v-if="item.children" v-for="(subItem, k) in item.children" :key="k">
                <div class="menu_subItem" :class="{'active': isSubMenuActive === i + '' + k}" @click="subMenuClick(subItem, i, k)">
                  {{subItem.name}}
                </div>
              </div>
              <!-- 二级菜单加号, 当长度 小于 5 才显示二级菜单的加号  -->
              <div class="menu_bottom menu_addicon" v-if="!item.children || item.children.length < 5" @click="addSubMenu(i,item)">
                <i class="el-icon-plus" />
              </div>
            </div>
          </div>
          <!-- 一级菜单加号 -->
          <div class="menu_bottom menu_addicon" v-if="menuKeyLength < 3" @click="addMenu"><i class="el-icon-plus"></i></div>
        </div>
        <div class="save_div">
            <!--<el-button class="save_btn" type="warning" size="small" @click="saveFun">保存菜单</el-button>-->
            <el-button class="save_btn" type="success" size="small" @click="saveAndReleaseFun">保存并发布菜单</el-button>
        </div>
      </div>
      <!--右边配置-->
      <div v-if="showRightFlag" class="right">
          <div class="configure_page">
              <div class="delete_btn">
                  <el-button size="mini"  type="danger" icon="el-icon-delete" @click="deleteMenu(tempObj)">删除当前菜单</el-button>
              </div>
              <div>
                  <span>菜单名称:</span>
                  <el-input class="input_width" v-model="tempObj.name" placeholder="请输入菜单名称" :maxlength=nameMaxlength clearable></el-input>
              </div>
              <div v-if="showConfigurContent">
                  <div class="menu_content">
                      <span>菜单内容:</span>
                      <el-select v-model="tempObj.type" clearable placeholder="请选择" class="menu_option">
                          <el-option v-for="item in menuOptions" :label="item.label" :value="item.value" :key="item.value"></el-option>
                      </el-select>
                  </div>
                  <div class="configur_content" v-if="tempObj.type === 'view'">
                      <span>跳转链接:</span>
                      <el-input class="input_width"  v-model="tempObj.url" placeholder="请输入链接" clearable></el-input>
                  </div>
                  <div class="configur_content" v-if="tempObj.type === 'miniprogram'">
                      <div class="applet">
                          <span>小程序的appid:</span>
                          <el-input class="input_width" v-model="tempObj.appid" placeholder="请输入小程序的appid" clearable></el-input>
                      </div>
                      <div class="applet">
                          <span>小程序的页面路径:</span>
                          <el-input class="input_width" v-model="tempObj.pagepath" placeholder="请输入小程序的页面路径,如:pages/index" clearable></el-input>
                      </div>
                      <div class="applet">
                          <span>备用网页:</span>
                          <el-input class="input_width" v-model="tempObj.url" placeholder="不支持小程序的老版本客户端将打开本网页" clearable></el-input>
                      </div>
                      <p class="blue">tips:需要和公众号进行关联才可以把小程序绑定带微信菜单上哟!</p>
                  </div>
                  <div class="configur_content" v-if="tempObj.type == 'article_view_limited'">
                      <el-row>
                          <div class="select-item" v-if="tempObj && tempObj.content && tempObj.content.articles">
                              <WxNews :objData="tempObj.content.articles"></WxNews>
                              <el-row class="ope-row">
                                  <el-button type="danger" icon="el-icon-delete" circle @click="deleteTempObj"></el-button>
                              </el-row>
                          </div>
                          <div v-if="!tempObj.content || !tempObj.content.articles">
                              <el-row>
                                  <el-col :span="24" style="text-align: center">
                                      <el-button type="success" @click="openMaterial">素材库选择<i class="el-icon-circle-check el-icon--right"></i></el-button>
                                  </el-col>
                              </el-row>
                          </div>
                          <el-dialog title="选择图文" :visible.sync="dialogNewsVisible" width="90%">
                              <WxMaterialSelect :objData="{repType:'news'}" @selectMaterial="selectMaterial"></WxMaterialSelect>
                          </el-dialog>
                      </el-row>
                  </div>
                  <div class="configur_content" v-if="tempObj.type == 'click' || tempObj.type == 'scancode_waitmsg'">
                      <WxReplySelect :objData="tempObj" v-if="hackResetWxReplySelect"></WxReplySelect>
                  </div>
              </div>
          </div>
      </div>
      <!--一进页面就显示的默认页面,当点击左边按钮的时候,就不显示了-->
      <div v-if="!showRightFlag" class="right">
          <p>请选择菜单配置</p>
      </div>
    </div>
  </div>
</template>

<script>
// import { save, saveAndRelease ,getList} from '@/api/wxmp/wxmenu'
import WxReplySelect from '@/views/mp/components/wx-news/main.vue'
import WxNews from '@/views/mp/components/wx-news/main.vue';
import WxMaterialSelect from '@/views/mp/components/wx-news/main.vue'
import {getMenuList} from "@/api/mp/menu";
import {getSimpleAccounts} from "@/api/mp/account";

export default {
  name: 'mpMenu',
  components: {
      WxReplySelect,
      WxNews,
      WxMaterialSelect
  },
  data(){
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 查询参数
      accountId: undefined,
      menuList: {
        children: [],
      },

      showRightFlag:false, // 右边配置显示默认详情还是配置详情
      menu:{ // 横向菜单
          button:[
          ]
      },

      isActive: -1,// 一级菜单点中样式
      isSubMenuActive: -1, // 一级菜单点中样式
      isSubMenuFlag: -1, // 二级菜单显示标志
      tempObj:{}, // 右边临时变量,作为中间值牵引关系
      tempSelfObj: {
          // 一些临时值放在这里进行判断,如果放在 tempObj,由于引用关系,menu 也会多了多余的参数
      },
      visible2: false, //素材内容  "选择素材"按钮弹框显示隐藏
      tableData:[], //素材内容弹框数据,
      menuName:'',
      showConfigurContent:true,
      nameMaxlength:0,//名称最大长度
      menuOptions: [{
          value: 'view',
          label: '跳转网页'
      }, {
          value: 'miniprogram',
          label: '跳转小程序'
      }, {
          value: 'click',
          label: '点击回复'
      }, {
          value: 'article_view_limited',
          label: '跳转图文消息'
      }, {
          value: 'scancode_push',
          label: '扫码直接返回结果'
      }, {
          value: 'scancode_waitmsg',
          label: '扫码回复'
      }, {
          value: 'pic_sysphoto',
          label: '系统拍照发图'
      }, {
          value: 'pic_photo_or_album',
          label: '拍照或者相册'
      }, {
          value: 'pic_weixin',
          label: '微信相册'
      }, {
          value: 'location_select',
          label: '选择地理位置'
      }],
      dialogNewsVisible: false,
      hackResetWxReplySelect: false,

      // 公众号账号列表
      accounts: [],
    }
  },
  created() {
    getSimpleAccounts().then(response => {
      this.accounts = response.data;
      // 默认选中第一个
      if (this.accounts.length > 0) {
        this.setAccountId(this.accounts[0].id);
      }
      // 加载数据
      this.getList();
    })
  },
  computed: {
    menuKeyLength:function() {
      // menuObj 的长度,当长度小于 3 才显示一级菜单的加号
      return this.menu.button.length;
    }
  },
  methods: {
    // ======================== 列表查询 ========================
    /** 设置账号编号 */
    setAccountId(accountId) {
      this.accountId = accountId;
      // this.uploadData.accountId = accountId;
    },
    getList() {
      this.loading = false;
      getMenuList(this.accountId).then(response => {
        this.menuList = this.handleTree(response.data, "id");
        console.log(this.menuList)
      }).finally(() => {
        this.loading = false;
      })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      // 默认选中第一个
      if (this.accountId) {
        this.setAccountId(this.accountId)
      }
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      // 默认选中第一个
      if (this.accounts.length > 0) {
        this.setAccountId(this.accounts[0].id)
      }
      this.handleQuery()
    },

    // TODO 芋艿:未归类

    deleteTempObj(){
        this.$delete(this.tempObj,'repName')
        this.$delete(this.tempObj,'repUrl')
        this.$delete(this.tempObj,'content')
    },
    openMaterial(){
        this.dialogNewsVisible = true
    },
    selectMaterial(item){
        if(item.content.articles.length>1){
            this.$alert('您选择的是多图文,将默认跳转第一篇', '提示', {
                confirmButtonText: '确定'
            })
        }
        this.dialogNewsVisible = false
        this.tempObj.article_id = item.articleId
        this.tempObj.mediaName = item.name
        this.tempObj.url = item.url
        item.mediaType = this.tempObj.mediaType
        item.content.articles = item.content.articles.slice(0,1)
        this.tempObj.content = item.content
    },
    handleClick(tab, event){
        this.tempObj.mediaType = tab.name
    },
    saveAndReleaseFun(){
        this.$confirm('确定要保证并发布该菜单吗?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
        }).then(() => {
            this.loading = true
            saveAndRelease({
                strWxMenu:this.menu
            }).then(response => {
                this.loading = false
                if(response.code == 200){
                    this.$message({
                        showClose: true,
                        message: '发布成功',
                        type: 'success'
                    })
                }else{
                    this.$message.error(response.data.msg)
                }
            }).catch(() => {
                this.loading = false
            })
        }).catch(() => {
        })
    },
    // 一级菜单点击事件
    menuClick(i, item){
        this.hackResetWxReplySelect = false//销毁组件
        this.$nextTick(() => {
            this.hackResetWxReplySelect = true//重建组件
        })
        this.showRightFlag = true;//右边菜单
        this.tempObj = item;//这个如果放在顶部,flag会没有。因为重新赋值了。
        this.tempSelfObj.grand = "1";//表示一级菜单
        this.tempSelfObj.index = i;//表示一级菜单索引
        this.isActive = i; //一级菜单选中样式
        this.isSubMenuFlag = i; //二级菜单显示标志
        this.isSubMenuActive = -1; //二级菜单去除选中样式
        this.nameMaxlength = 4
        if(item.sub_button && item.sub_button.length > 0){
            this.showConfigurContent = false
        }else{
            this.showConfigurContent = true
        }
    },
    // 二级菜单点击事件
    subMenuClick(subItem, index, k){
        this.hackResetWxReplySelect = false//销毁组件
        this.$nextTick(() => {
            this.hackResetWxReplySelect = true//重建组件
        })
        this.showRightFlag = true;//右边菜单
        this.tempObj = subItem;//将点击的数据放到临时变量,对象有引用作用
        this.tempSelfObj.grand = "2";//表示二级菜单
        this.tempSelfObj.index = index;//表示一级菜单索引
        this.tempSelfObj.secondIndex = k;//表示二级菜单索引
        this.isSubMenuActive = index + "" + k; //二级菜单选中样式
        this.isActive = -1;//一级菜单去除样式
        this.showConfigurContent = true;
        this.nameMaxlength = 7
    },
    // 添加横向一级菜单
    addMenu(){
        let menuKeyLength = this.menuKeyLength
        let addButton = {
            name: "菜单名称",
            sub_button: []
        }
        this.$set(this.menu.button,menuKeyLength,addButton)
        this.menuClick(this.menuKeyLength-1, addButton)
    },
    // 添加横向二级菜单
    addSubMenu(i,item){
        if(!item.sub_button||item.sub_button.length<=0){
            this.$set( item, 'sub_button',[])
            this.$delete( item, 'type')
            this.$delete( item, 'pagepath')
            this.$delete( item, 'url')
            this.$delete( item, 'key')
            this.$delete( item, 'article_id')
            this.$delete( item, 'textContent')
            this.showConfigurContent = false
        }
        let subMenuKeyLength = item.sub_button.length;//获取二级菜单key长度
        let addButton = {
            name: "子菜单名称"
        }
        this.$set(item.sub_button,subMenuKeyLength,addButton);
        this.subMenuClick(item.sub_button[subMenuKeyLength], i, subMenuKeyLength)
    },
    //删除当前菜单
    deleteMenu(obj){
        let _this = this;
        this.$confirm('确定要删除吗?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
        }).then(() => {
            _this.deleteData();// 删除菜单数据
            _this.tempObj = {};
            _this.showRightFlag = false;
            this.isActive = -1;
            this.isSubMenuActive = -1;
        }).catch(() => {
        });
    },
    // 删除菜单数据
    deleteData(){
        // 一级菜单的删除方法
        if(this.tempSelfObj.grand == "1"){
            this.menu.button.splice(this.tempSelfObj.index,1);
        }
        // 二级菜单的删除方法
        if(this.tempSelfObj.grand == "2"){
            this.menu.button[this.tempSelfObj.index].sub_button.splice(this.tempSelfObj.secondIndex, 1);
        }
        this.$message({
            type: 'success',
            message: '删除成功!'
        });
    }
  },
}
</script>
<!--本组件样式-->
<style lang="less" scoped="scoped">
/* 公共颜色变量 */
.clearfix{*zoom:1;}
.clearfix::after{content: "";display: table; clear: both;}
div{
  text-align: left;
}
.weixin-hd{
  color: #fff;
  text-align: center;
  position: relative;
  bottom: 426px;
  left:0px;
  width: 300px;
  height:64px;
  background: transparent url(assets/menu_head.png) no-repeat 0 0;
  background-position: 0 0;
  background-size: 100%
}
.weixin-title{
  color:#fff;
  font-size:14px;
  width:100%;
  text-align: center;
  position:absolute;
  top: 33px;
  left: 0px;
}
.weixin-menu{
  background: transparent url(assets/menu_foot.png) no-repeat 0 0;
  padding-left: 43px;
  font-size: 12px
}
.menu_option{
  width: 40%!important;
}
.public-account-management{
  min-width: 1200px;
  width: 1200px;
  margin: 0 auto;
  .left{
      float: left;
      display: inline-block;
      width: 350px;
      height: 715px;
      background: url("assets/iphone_backImg.png") no-repeat;
      background-size: 100% auto;
      padding: 518px 25px 88px;
      position: relative;
      box-sizing: border-box;
      /*第一级菜单*/
      .menu_main{
          .menu_bottom{
              position: relative;
              float: left;
              display: inline-block;
              box-sizing: border-box;
              width: 85.5px;
              text-align: center;
              border: 1px solid #ebedee;
              background-color: #fff;
              cursor: pointer;
              &.menu_addicon{
                  height: 46px;
                  line-height: 46px;
              }
              .menu_item{
                  height: 44px;
                  line-height: 44px;
                  text-align: center;
                  box-sizing: border-box;
                  width: 100%;
                  &.active{
                      border: 1px solid #2bb673;
                  }
              }
              .menu_subItem{
                  height: 44px;
                  line-height: 44px;
                  text-align: center;
                  box-sizing: border-box;
                  &.active{
                      border: 1px solid #2bb673;
                  }
              }
          }
          i{
              color:#2bb673;
          }
          /*第二级菜单*/
          .submenu{
              position: absolute;
              width: 85.5px;
              bottom: 45px;
              .subtitle{
                  background-color: #fff;
                  box-sizing: border-box;
              }
          }
      }
      .save_div{
          margin-top: 15px;
          text-align: center;
          .save_btn{
              bottom: 20px;
              left: 100px;
          }
      }
  }
  /*右边菜单内容*/
  .right{
      float: left;
      width: 63%;
      background-color: #e8e7e7;
      padding: 20px;
      margin-left: 20px;
      -webkit-box-sizing: border-box;
      box-sizing: border-box;
      .configure_page{
          .delete_btn{
              text-align: right;
              margin-bottom: 15px;
          }
          .menu_content{
              margin-top: 20px;
          }
          .configur_content{
              margin-top: 20px;
              background-color: #fff;
              padding: 20px 10px;
              border-radius: 5px
          }
          .blue{
              color:#29b6f6;
              margin-top: 10px;
          }
          .applet{
              margin-bottom: 20px;
              span{
                  width: 20%;
              }
          }
          .material{
              .input_width{
                  width: 30%;
              }
              .el-textarea{
                  width: 80%
              }
          }
      }
  }
}
</style>
<!--修改UI框架样式-->
<!--<style lang="less" scoped>-->
<!--    .public-account-management{-->
<!--        .el-input{-->
<!--            width: 70%;-->
<!--            margin-right: 2%;-->
<!--        }-->
<!--    }-->
<!--</style>-->
<!--素材样式-->
<style lang="scss" scoped>
    .pagination{
        text-align: right;
        margin-right: 25px;
    }
    .select-item{
        width: 280px;
        padding: 10px;
        margin: 0 auto 10px auto;
        border: 1px solid #eaeaea;
    }
    .select-item2{
        padding: 10px;
        margin: 0 auto 10px auto;
        border: 1px solid #eaeaea;
    }
    .ope-row{
        padding-top: 10px;
        text-align: center;
    }
    .item-name{
        font-size: 12px;
        overflow: hidden;
        text-overflow:ellipsis;
        white-space: nowrap;
        text-align: center;
    }
</style>