index.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618
  1. <!--
  2. MIT License
  3. Copyright (c) 2020 www.joolun.com
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in all
  11. copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  18. SOFTWARE.
  19. -->
  20. <template>
  21. <div class="app-container">
  22. <!-- 搜索工作栏 -->
  23. <el-form ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
  24. <el-form-item label="公众号" prop="accountId">
  25. <el-select v-model="accountId" placeholder="请选择公众号">
  26. <el-option v-for="item in accounts" :key="parseInt(item.id)" :label="item.name" :value="parseInt(item.id)" />
  27. </el-select>
  28. </el-form-item>
  29. <el-form-item>
  30. <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
  31. <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
  32. </el-form-item>
  33. </el-form>
  34. <div class="public-account-management clearfix" v-loading="loading">
  35. <!--左边配置菜单-->
  36. <div class="left">
  37. <div class="weixin-hd">
  38. <div class="weixin-title">{{menuName}}</div>
  39. </div>
  40. <div class="weixin-menu menu_main clearfix">
  41. <div class="menu_bottom" v-for="(item, i) of menuList" :key="i" >
  42. <!-- 一级菜单 -->
  43. <div @click="menuClick(i, item)" class="menu_item el-icon-s-fold" :class="{'active': isActive === i}">{{item.name}}</div>
  44. <!-- 以下为二级菜单-->
  45. <div class="submenu" v-if="isSubMenuFlag === i">
  46. <div class="subtitle menu_bottom" v-if="item.children" v-for="(subItem, k) in item.children" :key="k">
  47. <div class="menu_subItem" :class="{'active': isSubMenuActive === i + '' + k}" @click="subMenuClick(subItem, i, k)">
  48. {{subItem.name}}
  49. </div>
  50. </div>
  51. <!-- 二级菜单加号, 当长度 小于 5 才显示二级菜单的加号 -->
  52. <div class="menu_bottom menu_addicon" v-if="!item.children || item.children.length < 5" @click="addSubMenu(i,item)">
  53. <i class="el-icon-plus" />
  54. </div>
  55. </div>
  56. </div>
  57. <!-- 一级菜单加号 -->
  58. <div class="menu_bottom menu_addicon" v-if="menuKeyLength < 3" @click="addMenu"><i class="el-icon-plus"></i></div>
  59. </div>
  60. <div class="save_div">
  61. <!--<el-button class="save_btn" type="warning" size="small" @click="saveFun">保存菜单</el-button>-->
  62. <el-button class="save_btn" type="success" size="small" @click="saveAndReleaseFun">保存并发布菜单</el-button>
  63. </div>
  64. </div>
  65. <!--右边配置-->
  66. <div v-if="showRightFlag" class="right">
  67. <div class="configure_page">
  68. <div class="delete_btn">
  69. <el-button size="mini" type="danger" icon="el-icon-delete" @click="deleteMenu(tempObj)">删除当前菜单</el-button>
  70. </div>
  71. <div>
  72. <span>菜单名称:</span>
  73. <el-input class="input_width" v-model="tempObj.name" placeholder="请输入菜单名称" :maxlength=nameMaxlength clearable></el-input>
  74. </div>
  75. <div v-if="showConfigurContent">
  76. <div class="menu_content">
  77. <span>菜单内容:</span>
  78. <el-select v-model="tempObj.type" clearable placeholder="请选择" class="menu_option">
  79. <el-option v-for="item in menuOptions" :label="item.label" :value="item.value" :key="item.value"></el-option>
  80. </el-select>
  81. </div>
  82. <div class="configur_content" v-if="tempObj.type === 'view'">
  83. <span>跳转链接:</span>
  84. <el-input class="input_width" v-model="tempObj.url" placeholder="请输入链接" clearable></el-input>
  85. </div>
  86. <div class="configur_content" v-if="tempObj.type === 'miniprogram'">
  87. <div class="applet">
  88. <span>小程序的appid:</span>
  89. <el-input class="input_width" v-model="tempObj.appid" placeholder="请输入小程序的appid" clearable></el-input>
  90. </div>
  91. <div class="applet">
  92. <span>小程序的页面路径:</span>
  93. <el-input class="input_width" v-model="tempObj.pagepath" placeholder="请输入小程序的页面路径,如:pages/index" clearable></el-input>
  94. </div>
  95. <div class="applet">
  96. <span>备用网页:</span>
  97. <el-input class="input_width" v-model="tempObj.url" placeholder="不支持小程序的老版本客户端将打开本网页" clearable></el-input>
  98. </div>
  99. <p class="blue">tips:需要和公众号进行关联才可以把小程序绑定带微信菜单上哟!</p>
  100. </div>
  101. <div class="configur_content" v-if="tempObj.type == 'article_view_limited'">
  102. <el-row>
  103. <div class="select-item" v-if="tempObj && tempObj.content && tempObj.content.articles">
  104. <WxNews :objData="tempObj.content.articles"></WxNews>
  105. <el-row class="ope-row">
  106. <el-button type="danger" icon="el-icon-delete" circle @click="deleteTempObj"></el-button>
  107. </el-row>
  108. </div>
  109. <div v-if="!tempObj.content || !tempObj.content.articles">
  110. <el-row>
  111. <el-col :span="24" style="text-align: center">
  112. <el-button type="success" @click="openMaterial">素材库选择<i class="el-icon-circle-check el-icon--right"></i></el-button>
  113. </el-col>
  114. </el-row>
  115. </div>
  116. <el-dialog title="选择图文" :visible.sync="dialogNewsVisible" width="90%">
  117. <WxMaterialSelect :objData="{repType:'news'}" @selectMaterial="selectMaterial"></WxMaterialSelect>
  118. </el-dialog>
  119. </el-row>
  120. </div>
  121. <div class="configur_content" v-if="tempObj.type == 'click' || tempObj.type == 'scancode_waitmsg'">
  122. <WxReplySelect :objData="tempObj" v-if="hackResetWxReplySelect"></WxReplySelect>
  123. </div>
  124. </div>
  125. </div>
  126. </div>
  127. <!--一进页面就显示的默认页面,当点击左边按钮的时候,就不显示了-->
  128. <div v-if="!showRightFlag" class="right">
  129. <p>请选择菜单配置</p>
  130. </div>
  131. </div>
  132. </div>
  133. </template>
  134. <script>
  135. // import { save, saveAndRelease ,getList} from '@/api/wxmp/wxmenu'
  136. import WxReplySelect from '@/views/mp/components/wx-news/main.vue'
  137. import WxNews from '@/views/mp/components/wx-news/main.vue';
  138. import WxMaterialSelect from '@/views/mp/components/wx-news/main.vue'
  139. import {getMenuList} from "@/api/mp/menu";
  140. import {getSimpleAccounts} from "@/api/mp/account";
  141. export default {
  142. name: 'mpMenu',
  143. components: {
  144. WxReplySelect,
  145. WxNews,
  146. WxMaterialSelect
  147. },
  148. data(){
  149. return {
  150. // 遮罩层
  151. loading: true,
  152. // 显示搜索条件
  153. showSearch: true,
  154. // 查询参数
  155. accountId: undefined,
  156. menuList: {
  157. children: [],
  158. },
  159. showRightFlag:false, // 右边配置显示默认详情还是配置详情
  160. menu:{ // 横向菜单
  161. button:[
  162. ]
  163. },
  164. isActive: -1,// 一级菜单点中样式
  165. isSubMenuActive: -1, // 一级菜单点中样式
  166. isSubMenuFlag: -1, // 二级菜单显示标志
  167. tempObj:{}, // 右边临时变量,作为中间值牵引关系
  168. tempSelfObj: {
  169. // 一些临时值放在这里进行判断,如果放在 tempObj,由于引用关系,menu 也会多了多余的参数
  170. },
  171. visible2: false, //素材内容 "选择素材"按钮弹框显示隐藏
  172. tableData:[], //素材内容弹框数据,
  173. menuName:'',
  174. showConfigurContent:true,
  175. nameMaxlength:0,//名称最大长度
  176. menuOptions: [{
  177. value: 'view',
  178. label: '跳转网页'
  179. }, {
  180. value: 'miniprogram',
  181. label: '跳转小程序'
  182. }, {
  183. value: 'click',
  184. label: '点击回复'
  185. }, {
  186. value: 'article_view_limited',
  187. label: '跳转图文消息'
  188. }, {
  189. value: 'scancode_push',
  190. label: '扫码直接返回结果'
  191. }, {
  192. value: 'scancode_waitmsg',
  193. label: '扫码回复'
  194. }, {
  195. value: 'pic_sysphoto',
  196. label: '系统拍照发图'
  197. }, {
  198. value: 'pic_photo_or_album',
  199. label: '拍照或者相册'
  200. }, {
  201. value: 'pic_weixin',
  202. label: '微信相册'
  203. }, {
  204. value: 'location_select',
  205. label: '选择地理位置'
  206. }],
  207. dialogNewsVisible: false,
  208. hackResetWxReplySelect: false,
  209. // 公众号账号列表
  210. accounts: [],
  211. }
  212. },
  213. created() {
  214. getSimpleAccounts().then(response => {
  215. this.accounts = response.data;
  216. // 默认选中第一个
  217. if (this.accounts.length > 0) {
  218. this.setAccountId(this.accounts[0].id);
  219. }
  220. // 加载数据
  221. this.getList();
  222. })
  223. },
  224. computed: {
  225. menuKeyLength:function() {
  226. // menuObj 的长度,当长度小于 3 才显示一级菜单的加号
  227. return this.menu.button.length;
  228. }
  229. },
  230. methods: {
  231. // ======================== 列表查询 ========================
  232. /** 设置账号编号 */
  233. setAccountId(accountId) {
  234. this.accountId = accountId;
  235. // this.uploadData.accountId = accountId;
  236. },
  237. getList() {
  238. this.loading = false;
  239. getMenuList(this.accountId).then(response => {
  240. this.menuList = this.handleTree(response.data, "id");
  241. console.log(this.menuList)
  242. }).finally(() => {
  243. this.loading = false;
  244. })
  245. },
  246. /** 搜索按钮操作 */
  247. handleQuery() {
  248. // 默认选中第一个
  249. if (this.accountId) {
  250. this.setAccountId(this.accountId)
  251. }
  252. this.getList()
  253. },
  254. /** 重置按钮操作 */
  255. resetQuery() {
  256. this.resetForm('queryForm')
  257. // 默认选中第一个
  258. if (this.accounts.length > 0) {
  259. this.setAccountId(this.accounts[0].id)
  260. }
  261. this.handleQuery()
  262. },
  263. // TODO 芋艿:未归类
  264. deleteTempObj(){
  265. this.$delete(this.tempObj,'repName')
  266. this.$delete(this.tempObj,'repUrl')
  267. this.$delete(this.tempObj,'content')
  268. },
  269. openMaterial(){
  270. this.dialogNewsVisible = true
  271. },
  272. selectMaterial(item){
  273. if(item.content.articles.length>1){
  274. this.$alert('您选择的是多图文,将默认跳转第一篇', '提示', {
  275. confirmButtonText: '确定'
  276. })
  277. }
  278. this.dialogNewsVisible = false
  279. this.tempObj.article_id = item.articleId
  280. this.tempObj.mediaName = item.name
  281. this.tempObj.url = item.url
  282. item.mediaType = this.tempObj.mediaType
  283. item.content.articles = item.content.articles.slice(0,1)
  284. this.tempObj.content = item.content
  285. },
  286. handleClick(tab, event){
  287. this.tempObj.mediaType = tab.name
  288. },
  289. saveAndReleaseFun(){
  290. this.$confirm('确定要保证并发布该菜单吗?', '提示', {
  291. confirmButtonText: '确定',
  292. cancelButtonText: '取消',
  293. type: 'warning'
  294. }).then(() => {
  295. this.loading = true
  296. saveAndRelease({
  297. strWxMenu:this.menu
  298. }).then(response => {
  299. this.loading = false
  300. if(response.code == 200){
  301. this.$message({
  302. showClose: true,
  303. message: '发布成功',
  304. type: 'success'
  305. })
  306. }else{
  307. this.$message.error(response.data.msg)
  308. }
  309. }).catch(() => {
  310. this.loading = false
  311. })
  312. }).catch(() => {
  313. })
  314. },
  315. // 一级菜单点击事件
  316. menuClick(i, item){
  317. this.hackResetWxReplySelect = false//销毁组件
  318. this.$nextTick(() => {
  319. this.hackResetWxReplySelect = true//重建组件
  320. })
  321. this.showRightFlag = true;//右边菜单
  322. this.tempObj = item;//这个如果放在顶部,flag会没有。因为重新赋值了。
  323. this.tempSelfObj.grand = "1";//表示一级菜单
  324. this.tempSelfObj.index = i;//表示一级菜单索引
  325. this.isActive = i; //一级菜单选中样式
  326. this.isSubMenuFlag = i; //二级菜单显示标志
  327. this.isSubMenuActive = -1; //二级菜单去除选中样式
  328. this.nameMaxlength = 4
  329. if(item.sub_button && item.sub_button.length > 0){
  330. this.showConfigurContent = false
  331. }else{
  332. this.showConfigurContent = true
  333. }
  334. },
  335. // 二级菜单点击事件
  336. subMenuClick(subItem, index, k){
  337. this.hackResetWxReplySelect = false//销毁组件
  338. this.$nextTick(() => {
  339. this.hackResetWxReplySelect = true//重建组件
  340. })
  341. this.showRightFlag = true;//右边菜单
  342. this.tempObj = subItem;//将点击的数据放到临时变量,对象有引用作用
  343. this.tempSelfObj.grand = "2";//表示二级菜单
  344. this.tempSelfObj.index = index;//表示一级菜单索引
  345. this.tempSelfObj.secondIndex = k;//表示二级菜单索引
  346. this.isSubMenuActive = index + "" + k; //二级菜单选中样式
  347. this.isActive = -1;//一级菜单去除样式
  348. this.showConfigurContent = true;
  349. this.nameMaxlength = 7
  350. },
  351. // 添加横向一级菜单
  352. addMenu(){
  353. let menuKeyLength = this.menuKeyLength
  354. let addButton = {
  355. name: "菜单名称",
  356. sub_button: []
  357. }
  358. this.$set(this.menu.button,menuKeyLength,addButton)
  359. this.menuClick(this.menuKeyLength-1, addButton)
  360. },
  361. // 添加横向二级菜单
  362. addSubMenu(i,item){
  363. if(!item.sub_button||item.sub_button.length<=0){
  364. this.$set( item, 'sub_button',[])
  365. this.$delete( item, 'type')
  366. this.$delete( item, 'pagepath')
  367. this.$delete( item, 'url')
  368. this.$delete( item, 'key')
  369. this.$delete( item, 'article_id')
  370. this.$delete( item, 'textContent')
  371. this.showConfigurContent = false
  372. }
  373. let subMenuKeyLength = item.sub_button.length;//获取二级菜单key长度
  374. let addButton = {
  375. name: "子菜单名称"
  376. }
  377. this.$set(item.sub_button,subMenuKeyLength,addButton);
  378. this.subMenuClick(item.sub_button[subMenuKeyLength], i, subMenuKeyLength)
  379. },
  380. //删除当前菜单
  381. deleteMenu(obj){
  382. let _this = this;
  383. this.$confirm('确定要删除吗?', '提示', {
  384. confirmButtonText: '确定',
  385. cancelButtonText: '取消',
  386. type: 'warning'
  387. }).then(() => {
  388. _this.deleteData();// 删除菜单数据
  389. _this.tempObj = {};
  390. _this.showRightFlag = false;
  391. this.isActive = -1;
  392. this.isSubMenuActive = -1;
  393. }).catch(() => {
  394. });
  395. },
  396. // 删除菜单数据
  397. deleteData(){
  398. // 一级菜单的删除方法
  399. if(this.tempSelfObj.grand == "1"){
  400. this.menu.button.splice(this.tempSelfObj.index,1);
  401. }
  402. // 二级菜单的删除方法
  403. if(this.tempSelfObj.grand == "2"){
  404. this.menu.button[this.tempSelfObj.index].sub_button.splice(this.tempSelfObj.secondIndex, 1);
  405. }
  406. this.$message({
  407. type: 'success',
  408. message: '删除成功!'
  409. });
  410. }
  411. },
  412. }
  413. </script>
  414. <!--本组件样式-->
  415. <style lang="less" scoped="scoped">
  416. /* 公共颜色变量 */
  417. .clearfix{*zoom:1;}
  418. .clearfix::after{content: "";display: table; clear: both;}
  419. div{
  420. text-align: left;
  421. }
  422. .weixin-hd{
  423. color: #fff;
  424. text-align: center;
  425. position: relative;
  426. bottom: 426px;
  427. left:0px;
  428. width: 300px;
  429. height:64px;
  430. background: transparent url(assets/menu_head.png) no-repeat 0 0;
  431. background-position: 0 0;
  432. background-size: 100%
  433. }
  434. .weixin-title{
  435. color:#fff;
  436. font-size:14px;
  437. width:100%;
  438. text-align: center;
  439. position:absolute;
  440. top: 33px;
  441. left: 0px;
  442. }
  443. .weixin-menu{
  444. background: transparent url(assets/menu_foot.png) no-repeat 0 0;
  445. padding-left: 43px;
  446. font-size: 12px
  447. }
  448. .menu_option{
  449. width: 40%!important;
  450. }
  451. .public-account-management{
  452. min-width: 1200px;
  453. width: 1200px;
  454. margin: 0 auto;
  455. .left{
  456. float: left;
  457. display: inline-block;
  458. width: 350px;
  459. height: 715px;
  460. background: url("assets/iphone_backImg.png") no-repeat;
  461. background-size: 100% auto;
  462. padding: 518px 25px 88px;
  463. position: relative;
  464. box-sizing: border-box;
  465. /*第一级菜单*/
  466. .menu_main{
  467. .menu_bottom{
  468. position: relative;
  469. float: left;
  470. display: inline-block;
  471. box-sizing: border-box;
  472. width: 85.5px;
  473. text-align: center;
  474. border: 1px solid #ebedee;
  475. background-color: #fff;
  476. cursor: pointer;
  477. &.menu_addicon{
  478. height: 46px;
  479. line-height: 46px;
  480. }
  481. .menu_item{
  482. height: 44px;
  483. line-height: 44px;
  484. text-align: center;
  485. box-sizing: border-box;
  486. width: 100%;
  487. &.active{
  488. border: 1px solid #2bb673;
  489. }
  490. }
  491. .menu_subItem{
  492. height: 44px;
  493. line-height: 44px;
  494. text-align: center;
  495. box-sizing: border-box;
  496. &.active{
  497. border: 1px solid #2bb673;
  498. }
  499. }
  500. }
  501. i{
  502. color:#2bb673;
  503. }
  504. /*第二级菜单*/
  505. .submenu{
  506. position: absolute;
  507. width: 85.5px;
  508. bottom: 45px;
  509. .subtitle{
  510. background-color: #fff;
  511. box-sizing: border-box;
  512. }
  513. }
  514. }
  515. .save_div{
  516. margin-top: 15px;
  517. text-align: center;
  518. .save_btn{
  519. bottom: 20px;
  520. left: 100px;
  521. }
  522. }
  523. }
  524. /*右边菜单内容*/
  525. .right{
  526. float: left;
  527. width: 63%;
  528. background-color: #e8e7e7;
  529. padding: 20px;
  530. margin-left: 20px;
  531. -webkit-box-sizing: border-box;
  532. box-sizing: border-box;
  533. .configure_page{
  534. .delete_btn{
  535. text-align: right;
  536. margin-bottom: 15px;
  537. }
  538. .menu_content{
  539. margin-top: 20px;
  540. }
  541. .configur_content{
  542. margin-top: 20px;
  543. background-color: #fff;
  544. padding: 20px 10px;
  545. border-radius: 5px
  546. }
  547. .blue{
  548. color:#29b6f6;
  549. margin-top: 10px;
  550. }
  551. .applet{
  552. margin-bottom: 20px;
  553. span{
  554. width: 20%;
  555. }
  556. }
  557. .material{
  558. .input_width{
  559. width: 30%;
  560. }
  561. .el-textarea{
  562. width: 80%
  563. }
  564. }
  565. }
  566. }
  567. }
  568. </style>
  569. <!--修改UI框架样式-->
  570. <!--<style lang="less" scoped>-->
  571. <!-- .public-account-management{-->
  572. <!-- .el-input{-->
  573. <!-- width: 70%;-->
  574. <!-- margin-right: 2%;-->
  575. <!-- }-->
  576. <!-- }-->
  577. <!--</style>-->
  578. <!--素材样式-->
  579. <style lang="scss" scoped>
  580. .pagination{
  581. text-align: right;
  582. margin-right: 25px;
  583. }
  584. .select-item{
  585. width: 280px;
  586. padding: 10px;
  587. margin: 0 auto 10px auto;
  588. border: 1px solid #eaeaea;
  589. }
  590. .select-item2{
  591. padding: 10px;
  592. margin: 0 auto 10px auto;
  593. border: 1px solid #eaeaea;
  594. }
  595. .ope-row{
  596. padding-top: 10px;
  597. text-align: center;
  598. }
  599. .item-name{
  600. font-size: 12px;
  601. overflow: hidden;
  602. text-overflow:ellipsis;
  603. white-space: nowrap;
  604. text-align: center;
  605. }
  606. </style>