menu_api.html 68 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523
  1. <script>
  2. let obj;
  3. let mId;
  4. let tempObj;
  5. let button;
  6. let objp;
  7. let objs;
  8. let ix;
  9. let menu = '<div class="custom-menu-view__menu"><div class="text-ellipsis"></div></div>';
  10. let customBtns = $('.custom-menu-view__footer__right');
  11. let setMenuText;
  12. let colIndex;//一级菜单列数;
  13. let radios;
  14. let delClick;
  15. //添加菜单按钮
  16. let customEl = '<div class="custom-menu-view__menu"><div class="text-ellipsis">新建菜单</div></div>'
  17. let customUl = '<ul class="custom-menu-view__menu__sub"><li class="custom-menu-view__menu__sub__add"><div class="text-ellipsis"><i class="glyphicon glyphicon-plus text-info"></i></div></li></ul>';
  18. let customLi = '<li class="custom-menu-view__menu__sub__add"><div class="text-ellipsis">新建子菜单</div></li>';
  19. //一级菜单对象
  20. function parents(param) {
  21. this.name = param;
  22. this.sub_button = [];
  23. }
  24. //二级菜单对象
  25. function subs(param) {
  26. this.name = param;
  27. }
  28. //显示第一级菜单
  29. function showMenu() {
  30. if (button.length == 1) {
  31. appendMenu(button.length);
  32. showBtn();
  33. $('.custom-menu-view__menu').css({
  34. width: '50%',
  35. });
  36. }
  37. if (button.length == 2) {
  38. appendMenu(button.length);
  39. showBtn();
  40. $('.custom-menu-view__menu').css({
  41. width: '33.3333%',
  42. });
  43. }
  44. if (button.length == 3) {
  45. appendMenu(button.length);
  46. showBtn();
  47. $('.custom-menu-view__menu').css({
  48. width: '33.3333%',
  49. });
  50. }
  51. for (var b = 0; b < button.length; b++) {
  52. $('.custom-menu-view__menu')[b].setAttribute('alt', b);
  53. }
  54. }
  55. //显示子菜单
  56. function showBtn() {
  57. for (var i = 0; i < button.length; i++) {
  58. var text = button[i].name;
  59. var list = document.createElement('ul');
  60. list.className = "custom-menu-view__menu__sub";
  61. $('.custom-menu-view__menu')[i].childNodes[0].innerHTML = text;
  62. $('.custom-menu-view__menu')[i].appendChild(list);
  63. for (var j = 0; j < button[i].sub_button.length; j++) {
  64. var text = button[i].sub_button[j].name;
  65. var li = document.createElement("li");
  66. var tt = document.createTextNode(text);
  67. var div = document.createElement('div');
  68. li.className = 'custom-menu-view__menu__sub__add';
  69. li.id = 'sub_' + i + '_' + j;//设置二级菜单id
  70. div.className = "text-ellipsis";
  71. div.appendChild(tt);
  72. li.appendChild(div);
  73. $('.custom-menu-view__menu__sub')[i].appendChild(li);
  74. }
  75. var ulBtnL = button[i].sub_button.length;
  76. var iLi = document.createElement("li");
  77. var ii = document.createElement('i');
  78. var iDiv = document.createElement("div");
  79. ii.className = "glyphicon glyphicon-plus text-info";
  80. iDiv.className = "text-ellipsis";
  81. iLi.className = 'custom-menu-view__menu__sub__add';
  82. iDiv.appendChild(ii);
  83. iLi.appendChild(iDiv);
  84. if (ulBtnL < 5) {
  85. $('.custom-menu-view__menu__sub')[i].appendChild(iLi);
  86. }
  87. }
  88. }
  89. //显示添加的菜单
  90. function appendMenu(num) {
  91. var menuDiv = document.createElement('div');
  92. var mDiv = document.createElement('div');
  93. var mi = document.createElement('i');
  94. mi.className = 'glyphicon glyphicon-plus text-info iBtn';
  95. mDiv.className = 'text-ellipsis';
  96. menuDiv.className = 'custom-menu-view__menu';
  97. mDiv.appendChild(mi);
  98. menuDiv.appendChild(mDiv);
  99. switch (num) {
  100. case 1:
  101. customBtns.append(menu);
  102. customBtns.append(menuDiv);
  103. break;
  104. case 2:
  105. customBtns.append(menu);
  106. customBtns.append(menu);
  107. customBtns.append(menuDiv);
  108. break;
  109. case 3:
  110. customBtns.append(menu);
  111. customBtns.append(menu);
  112. customBtns.append(menu);
  113. break;
  114. }
  115. }
  116. //初始化菜单按钮
  117. function addMenu() {
  118. var menuI = '<div class="custom-menu-view__menu"><div class="text-ellipsis"><i class="glyphicon glyphicon-plus text-info iBtn"></i></div></div>';
  119. var sortIndex = true;
  120. customBtns.append(menuI);
  121. var customFirstBtns = $('.custom-menu-view__menu');
  122. var firstBtnsLength = customFirstBtns.length;
  123. if (firstBtnsLength <= 1) {
  124. customFirstBtns.css({
  125. width: '100%',
  126. })
  127. }
  128. }
  129. function setSubText() {
  130. var actived = $('.custom-menu-view__menu__sub__add').hasClass('subbutton__actived');
  131. var activedTxt = $('.subbutton__actived').text();
  132. if (actived) {
  133. setInput(activedTxt);
  134. updateTit(activedTxt);
  135. radios[0].checked = true;
  136. $('#editMsg').show();
  137. $('#editPage').hide();
  138. $('.msg-context__item').show();
  139. $('.msg-template').hide();
  140. }
  141. }
  142. //对新添加二级菜单添加id
  143. function setLiId() {
  144. var prev = $('.custom-menu-view__menu')[colIndex].getElementsByTagName('i')[0].parentNode.parentNode.previousSibling;
  145. var divText = prev.childNodes[0].innerHTML;
  146. if (typeof (button[colIndex].sub_button) == "undefined") {
  147. var sub_button = {"sub_button": []};
  148. button[colIndex].append(sub_button);
  149. }
  150. button[colIndex].sub_button.push(new subs(divText));
  151. var id = button[colIndex].sub_button.length - 1;
  152. prev.setAttribute('id', 'sub_' + colIndex + '_' + id);
  153. $('.custom-menu-view__footer__right').find('.subbutton__actived').removeClass('subbutton__actived');
  154. $('.custom-menu-view__menu').eq(colIndex).find('i').parent().parent().prev().addClass('subbutton__actived');
  155. }
  156. //设置右边input的value
  157. function setInput(val) {
  158. $('input[name="custom_input_title"]').val(val);
  159. }
  160. //实时更新右侧顶部标题
  161. function updateTit(text) {
  162. $('#cm-tit').html(text);
  163. }
  164. function sortable(m, sortIndex) {
  165. if (sortIndex) {
  166. Sortable.create(document.getElementById('menuStage_2_' + m), {
  167. animation: 300, //动画参数
  168. disabled: false,
  169. });
  170. } else {
  171. var el = document.getElementById('menuStage_2_' + m);
  172. var sortable = Sortable.create(el, {
  173. disabled: true,
  174. });
  175. sortable.destroy();
  176. }
  177. }
  178. //type为click时添加删除按钮元素
  179. function delElement() {
  180. var msgTemp = $('.msg-template');
  181. var delEl = '<span class="msg-panel__del del-tuwen">删除</span>';
  182. msgTemp.append(delEl);
  183. if (msgTemp.find('span').length == 0) {
  184. msgTemp.append(delEl);
  185. }
  186. };
  187. //保存
  188. function saveAjax() {
  189. $.ajax({
  190. url: baseURL + '/admin/wechat/addWeixinMenu',
  191. type: "POST",
  192. data: JSON.stringify({
  193. "menu": obj.menu,//先将对象转换为字符串再传给后台
  194. "app_id": $("#appIdcode").val()
  195. }),
  196. contentType: "application/json",
  197. dataType: "json",
  198. success: function (res) {
  199. if (res.code > 0) {
  200. layer.msg("创建成功!");
  201. } else {
  202. layer.alert(res.msg);
  203. }
  204. }
  205. });
  206. }
  207. //删除菜单
  208. function deleteMenu() {
  209. layer.confirm('谨慎操作',{btn: ['确定', '取消'], title: "提示"}, function () {
  210. $.ajax({
  211. url: baseURL + '/admin/wechat/menuDel',
  212. type: "POST",
  213. data: {"appid": $("#appIdcode").val()},
  214. contentType: "application/json",
  215. dataType: "json",
  216. success: function (res) {
  217. if (res.code > 0) {
  218. layer.msg("删除成功!");
  219. obj = {
  220. "menu": {button: []}
  221. };
  222. $('.custom-menu-view__menu').remove();
  223. menuCreate(obj);
  224. $(".msg-tab_item").removeClass('on');
  225. $("#imgtextLi").addClass("on");
  226. } else {
  227. layer.alert(data.msg);
  228. }
  229. }
  230. })
  231. });
  232. }
  233. // 创建菜单
  234. function menuCreate(obj) {
  235. $('.iBtn').parent().unbind("click");
  236. $('.reminder').unbind("click");
  237. $('.text-ellipsis').unbind("click");
  238. $('li>.text-ellipsis>i').unbind("click");
  239. $('input[name="url"]').unbind("keyup");
  240. $('input[name="custom_input_title"]').unbind("keyup");
  241. $('.msg-panel__tab>li').unbind("click");
  242. $('#selectModal .modal-body .panel').unbind("click");
  243. $('#selectModal .ensure').unbind("click");
  244. $('#delMenu').unbind("click");
  245. $('#saveBtns').unbind("click");
  246. customBtns.unbind("click");
  247. mId = null;
  248. tempObj = {};//存储HTML对象
  249. if (typeof(obj.menu) != "undefined") {
  250. button = obj.menu.button;//一级菜单
  251. } else {
  252. button = [];
  253. }
  254. //显示异常
  255. if (obj.errcode) {
  256. $('#abnormalModal').modal('show');
  257. }
  258. objp = new parents();
  259. objs = new subs();
  260. if (typeof (button) != "undefined") {
  261. ix = button.length;//一级菜单数量
  262. } else {
  263. ix = 0;
  264. }
  265. if (typeof (button) != "undefined" && button.length > 0) {
  266. showMenu();
  267. //$('.cm-edit-before').hide();
  268. $('.cm-edit-after').hide();
  269. } else {
  270. addMenu();
  271. $('.cm-edit-before').siblings().hide();
  272. }
  273. $('.custom-menu-view__footer__right').off('click').on('click', ".iBtn", function () {
  274. var dom = $(this).parent(".text-ellipsis");
  275. if ($(dom).siblings("ul").length == 0) {
  276. ix = $('.custom-menu-view__menu[alt]').length;
  277. var num = $('.custom-menu-view__footer__right').find('.custom-menu-view__menu').length;
  278. var ulNum = $(dom).parents('.custom-menu-view__menu').prev().find('.custom-menu-view__menu__sub').length;
  279. ix++;
  280. if (ix < 4) {
  281. $(dom).parent().before(customEl);
  282. $(dom).parent().prev().append(customUl);
  283. $('.custom-menu-view__footer__right').find('.subbutton__actived').removeClass('subbutton__actived');
  284. $(dom).parent().prev().addClass('subbutton__actived');
  285. //一级菜单列数
  286. var buttonIndex = $(dom).parents('.custom-menu-view__menu').index() - 1;
  287. $('.custom-menu-view__menu').eq(buttonIndex).on('click', (function (buttonIndex) {
  288. var txt = $('.custom-menu-view__menu').eq(buttonIndex).text();
  289. setMenuText(txt);
  290. })(buttonIndex));
  291. if (ix == 1) {
  292. $('.custom-menu-view__menu').css({
  293. width: '50%'
  294. });
  295. $('.custom-menu-view__menu')[ix - 1].setAttribute('alt', ix - 1);
  296. }
  297. if (ix == 2) {
  298. $('.custom-menu-view__menu').css({
  299. width: '33.3333%'
  300. });
  301. $('.custom-menu-view__menu')[ix - 1].setAttribute('alt', ix - 1);
  302. }
  303. var divText = $(dom).parent().prev().find('.text-ellipsis').text();
  304. button.push(new parents(divText));
  305. }
  306. if (ix == 3) {
  307. $(dom).parents('.custom-menu-view__menu').remove();
  308. $(dom).parent().append(customUl);
  309. var index = ix - 1
  310. if ($(".custom-menu-view__menu").eq(ix - 1).children(".text-ellipsis").children(".iBtn").length == 0) {
  311. $('.custom-menu-view__menu')[ix - 1].setAttribute('alt', ix - 1);
  312. }
  313. }
  314. $('.cm-edit-after').show().siblings().hide();
  315. }
  316. });
  317. setMenuText = function (value) {
  318. setInput(value);
  319. updateTit(value);
  320. radios[0].checked = true;
  321. $('#editMsg').show();
  322. $('#editPage').hide();
  323. $('.msg-context__item').show();
  324. $('.msg-template').hide();
  325. }
  326. //添加子菜单
  327. customBtns.on('click', 'li>.text-ellipsis>i', function () {
  328. //绑定删除事件
  329. $('.msg-panel__del').on('click', delClick);
  330. colIndex = $(this).parents('.custom-menu-view__menu').prevAll().length;
  331. var liNum = $(this).parents('.custom-menu-view__menu').find('li').length;
  332. // if (liNum <= 1) {
  333. // // $('#reminderModal').modal('show');
  334. // } else {
  335. if (liNum < 6) {
  336. $(this).parent().parent().before(customLi);
  337. setLiId();
  338. }
  339. if (liNum == 5) {
  340. $(this).parents('li').remove();
  341. }
  342. // }
  343. $('#radioGroup').show();
  344. setSubText()
  345. });
  346. //确定添加子菜单事件
  347. $('.reminder').click(function () {
  348. var ul = $('.custom-menu-view__menu')[colIndex].getElementsByTagName('ul')[0];
  349. var li = document.createElement('li');
  350. var div = document.createElement('div');
  351. var Text = document.createTextNode('新建子菜单');
  352. li.className = "custom-menu-view__menu__sub__add";
  353. div.className = "text-ellipsis";
  354. div.appendChild(Text);
  355. li.appendChild(div);
  356. ul.insertBefore(li, ul.childNodes[0]);
  357. setLiId();
  358. delete button[colIndex].type;
  359. delete button[colIndex].media_id;
  360. delete button[colIndex].url;
  361. $('#reminderModal').modal('hide');
  362. setSubText();
  363. });
  364. imageText();
  365. //点击菜单
  366. customBtns.on('click', '.text-ellipsis', function () {
  367. $('.cm-edit-after').show().siblings().hide();
  368. if ($(this).parent().attr('id') || $(this).parent().attr('alt')) {
  369. $(this).parents('.custom-menu-view__footer__right').find('.subbutton__actived').removeClass('subbutton__actived');
  370. $(this).parent().addClass('subbutton__actived');
  371. }
  372. //一级菜单列数
  373. var buttonIndex = $(this).parents('.custom-menu-view__menu').prevAll().length;
  374. if ($('.msg-context__item').is(':hidden')) {
  375. $('.msg-template').show();
  376. } else if ($('.msg-context__item').is(':visible')) {
  377. $('.msg-template').hide();
  378. }
  379. //点击在一级菜单上
  380. if ($(this).parent().attr('alt')) {
  381. if ($('.custom-menu-view__menu').hasClass('subbutton__actived')) {
  382. var current = $('.subbutton__actived');
  383. var alt = current.attr('alt');
  384. var lis = current.find('ul>li');
  385. setInput(button[buttonIndex].name);
  386. updateTit(button[buttonIndex].name);
  387. if (lis.length > 1) {
  388. $('#editMsg').hide();
  389. $('#editPage').hide();
  390. $('#radioGroup').hide();
  391. } else {
  392. if (button[buttonIndex].type == 'media_id') {
  393. radios[0].checked = true;
  394. switch (button[buttonIndex].ctype) {
  395. case 'image':
  396. $("#imgLi").trigger('click');
  397. break;
  398. case 'voice':
  399. $("#voice").trigger('click');
  400. break;
  401. case 'video':
  402. $("#video").trigger('click');
  403. break;
  404. default:
  405. $("#imgtextLi").trigger("click");
  406. }
  407. $('#editMsg').show();
  408. $('#editPage').hide();
  409. $('#radioGroup').show();
  410. //拿key换取mediaId
  411. subKey = button[buttonIndex].media_id;
  412. $('.msg-template').html($('#' + subKey).html());
  413. delElement();
  414. //绑定删除事件
  415. $('.msg-panel__del').on('click', delClick);
  416. $('.msg-template').html(tempObj[button[buttonIndex].media_id]);
  417. } else if (button[buttonIndex].type == 'view') {
  418. $('input[name="url"]').val(button[buttonIndex].url);
  419. radios[1].checked = true;
  420. $('#editMsg').hide();
  421. $('#editPage').show();
  422. $('#radioGroup').show();
  423. } else if (!button[buttonIndex].type) {
  424. radios[0].checked = true;
  425. $('#editMsg').show();
  426. $('#editPage').hide();
  427. $('#radioGroup').show();
  428. }
  429. if (button[buttonIndex].media_id) {
  430. $('.msg-context__item').hide();
  431. $('.msg-template').show();
  432. } else {
  433. $('.msg-context__item').show();
  434. $('.msg-template').hide();
  435. }
  436. }
  437. }
  438. }
  439. //点击在二级菜单上
  440. if ($(this).parent().attr('id')) {
  441. var subIndex = $(this).parent("li").prevAll().length;
  442. var subText = button[buttonIndex].sub_button[subIndex].name;
  443. var subUrl = button[buttonIndex].sub_button[subIndex].url;
  444. var subType = button[buttonIndex].sub_button[subIndex].type;
  445. var subKey = button[buttonIndex].sub_button[subIndex].media_id;
  446. if ($('.custom-menu-view__menu__sub__add').hasClass('subbutton__actived')) {
  447. setInput(subText);
  448. updateTit(subText);
  449. $('#radioGroup').show();
  450. if (subType == 'media_id') {
  451. radios[0].checked = true;
  452. switch (button[buttonIndex].sub_button[subIndex].ctype) {
  453. case 'image':
  454. $("#imgLi").trigger('click');
  455. break;
  456. case 'voice':
  457. $("#voice").trigger('click');
  458. break;
  459. case 'video':
  460. $("#video").trigger('click');
  461. break;
  462. default:
  463. $("#imgtextLi").trigger("click");
  464. }
  465. $('#editMsg').show();
  466. $('#editPage').hide();
  467. //拿key换取图文消息
  468. $('.msg-template').html($('#' + subKey).html());
  469. delElement();
  470. //绑定删除事件
  471. $('.msg-panel__del').on('click', delClick);
  472. $('.msg-template').html(tempObj[subKey]);
  473. } else if (subType == 'view') {
  474. radios[1].checked = true;
  475. $('#editMsg').hide();
  476. $('#editPage').show();
  477. $('input[name="url"]').val(subUrl);
  478. } else if (!subType) {
  479. radios[0].checked = true;
  480. $('#editMsg').show();
  481. $('#editPage').hide();
  482. $('input[name="url"]').val('');
  483. }
  484. if (subKey) {
  485. $('.msg-context__item').hide();
  486. $('.msg-template').show();
  487. } else {
  488. $('.msg-context__item').show();
  489. $('.msg-template').hide();
  490. }
  491. }
  492. }
  493. //绑定删除事件
  494. $('.msg-panel__del').on('click', delClick);
  495. });
  496. //保存右侧菜单名称
  497. $('input[name="custom_input_title"]').keyup(function () {
  498. var val = $(this).val();
  499. var current = $('.subbutton__actived');
  500. if ($('.custom-menu-view__menu__sub__add').hasClass('subbutton__actived')) {
  501. var sub_row = $(".subbutton__actived").parents('.custom-menu-view__menu').prevAll().length;
  502. var sub_col = $('.subbutton__actived').prevAll().length;
  503. button[sub_row].sub_button[sub_col].name = val;
  504. current.find('.text-ellipsis').text(val);
  505. updateTit(val);
  506. } else if ($('.custom-menu-view__menu').hasClass('subbutton__actived')) {
  507. var alt = current.attr('alt');
  508. button[alt].name = val;
  509. current.children('.text-ellipsis').text(val);
  510. updateTit(val)
  511. }
  512. });
  513. //保存右侧跳转页面的url
  514. $('input[name="url"]').keyup(function () {
  515. var val = $(this).val();
  516. var current = $('.subbutton__actived');
  517. if ($('.custom-menu-view__menu__sub__add').hasClass('subbutton__actived')) {
  518. var sub_row = $(".subbutton__actived").parents('.custom-menu-view__menu').prevAll().length;
  519. var sub_col = $('.subbutton__actived').prevAll().length;
  520. button[sub_row].sub_button[sub_col].url = val;
  521. button[sub_row].sub_button[sub_col].type = 'view';
  522. if (button[sub_row].sub_button[sub_col].url == '') {
  523. delete button[sub_row].sub_button[sub_col].url;
  524. }
  525. } else if ($('.custom-menu-view__menu').hasClass('subbutton__actived')) {
  526. var alt = current.attr('alt');
  527. button[alt].url = val;
  528. button[alt].type = 'view';
  529. if (button[alt].url == '') {
  530. delete button[alt].url;
  531. }
  532. }
  533. });
  534. //tab切换
  535. $('.msg-panel__tab>li').click(function () {
  536. $('.msg-panel__tab>li').eq($(this).index()).addClass('on').siblings().removeClass('on');
  537. $('.msg-panel__context').eq($(this).index()).removeClass('hide').siblings().addClass('hide')
  538. });
  539. //菜单内容跳转
  540. radios = document.getElementsByName("radioBtn");
  541. for (var n = 0; n < radios.length; n++) {
  542. radios[n].index = n;
  543. radios[n].onchange = function () {
  544. if (radios[this.index].checked == true) {
  545. if (radios[this.index].value == 'link') {
  546. $('#editMsg').hide();
  547. $('#editPage').show();
  548. } else {
  549. $('#editMsg').show();
  550. $('#editPage').hide();
  551. }
  552. }
  553. };
  554. }
  555. delClick = function () {
  556. $('.msg-template').empty();
  557. $('.msg-context__item').show();
  558. $('.mask-bg').hide();
  559. var current = $('.subbutton__actived');
  560. if ($('.custom-menu-view__menu__sub__add').hasClass('subbutton__actived')) {
  561. var sub_col = $(".subbutton__actived").prevAll().length;
  562. var sub_row = $(".subbutton__actived").parents('.custom-menu-view__menu').prevAll().length;
  563. delete button[sub_row].sub_button[sub_col].media_id;
  564. delete button[sub_row].sub_button[sub_col].type;
  565. } else if ($('.custom-menu-view__menu').hasClass('subbutton__actived')) {
  566. var alt = $(".subbutton__actived").prevAll().length;
  567. delete button[alt].media_id;
  568. delete button[alt].type;
  569. }
  570. };
  571. //删除菜单按钮
  572. $('#delMenu').click(function () {
  573. var is_Actived = $('.custom-menu-view__menu').hasClass('subbutton__actived');//一级菜单选择项
  574. var is_actived = $('.custom-menu-view__menu__sub__add').hasClass('subbutton__actived');//二级菜单选中项
  575. var rowIndex = 0;
  576. var colIndex = 0;
  577. var liLength = $(".subbutton__actived").parents('.custom-menu-view__menu__sub');
  578. if (is_Actived) {
  579. rowIndex = $(".subbutton__actived").prevAll().length;
  580. $('.subbutton__actived').remove();
  581. button.splice(rowIndex, 1);
  582. let buttonLength = $(".custom-menu-view__menu:last[alt]").length;
  583. let isTrue = $(".custom-menu-view__menu .text-ellipsis .iBtn");
  584. if (buttonLength == 1) {
  585. $(".custom-menu-view__menu").css("width", '33.3333%');
  586. } else if (buttonLength == 0) {
  587. $(".custom-menu-view__menu").css("width", '50%');
  588. }
  589. if ($(".custom-menu-view__footer__right").children().length == 1) {
  590. $(".custom-menu-view__menu").css("width", '100%');
  591. }
  592. let divHtml = '<div class="custom-menu-view__menu"><div class="text-ellipsis"><i class="glyphicon glyphicon-plus text-info iBtn"></i></div></div>';
  593. if (!isTrue.length && isTrue.length == 0) {
  594. $(".custom-menu-view__footer__right").last().append(divHtml);
  595. }
  596. } else if (is_actived) {
  597. rowIndex = $(".subbutton__actived").parents('.custom-menu-view__menu').prevAll().length;
  598. colIndex = $('.subbutton__actived').prevAll().length;
  599. $('.subbutton__actived').remove();
  600. button[rowIndex].sub_button.splice(colIndex, 1);
  601. /* if (colIndex == 0) {
  602. delete button[rowIndex].sub_button;
  603. }*/
  604. var l = $(liLength).find('li').length;
  605. var add_button = $(liLength).find("i");
  606. if (l < 5) {
  607. if (!add_button.length) {
  608. let liHtml = '<li class="custom-menu-view__menu__sub__add"><div class="text-ellipsis"><i class="glyphicon glyphicon-plus text-info"></i></div></li>';
  609. $(liLength).find("li:last").after(liHtml);
  610. }
  611. }
  612. }
  613. //清除右边数据
  614. $('.cm-edit-before').show().siblings().hide();
  615. updateTit('');
  616. setInput('');
  617. $('input[name="url"]').val('');
  618. $('.msg-template').children().remove();
  619. $('.msg-context__item').show();
  620. })
  621. //保存自定义菜单
  622. $('#saveBtns').click(function () {
  623. let url = null;
  624. let strRegex = '(https?|ftp|file)://[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]';
  625. let re = new RegExp(strRegex);
  626. let flag;
  627. for (let i = 0; i < button.length; i++) {
  628. if (button[i].sub_button.length) {
  629. //判断是否有子元素
  630. for (let j = 0; j < button[i].sub_button.length; j++) {
  631. //二级菜单
  632. if (button[i].sub_button[j].hasOwnProperty('url')) {
  633. url = button[i].sub_button[j].url;
  634. if (!re.test(url)) {
  635. layer.msg("请输入正确的url地址!");
  636. flag = false;
  637. }
  638. } else if (button[i].sub_button[j].hasOwnProperty('media_id')) {
  639. flag = true;
  640. } else {
  641. flag = false;
  642. layer.msg("菜单内容不能为空!");
  643. }
  644. }
  645. } else {
  646. //一级菜单 url
  647. if (button[i].hasOwnProperty('url')) {
  648. flag = true;
  649. url = button[i].url;
  650. if (!re.test(url)) {
  651. layer.msg("请输入正确的url地址!");
  652. flag = false;
  653. }
  654. } else if (button[i].hasOwnProperty('media_id')) {
  655. // media_id;
  656. flag = true;
  657. } else {
  658. flag = false;
  659. layer.msg("菜单内容不能为空!");
  660. }
  661. }
  662. }
  663. if (flag) {
  664. saveAjax();
  665. }
  666. });
  667. }
  668. // 图文消息
  669. function imageText() {
  670. let appid = $("#appIdcode").val();
  671. $.ajax({
  672. url: baseURL + '/admin/wechat/getMaterialByType',
  673. type: 'POST',
  674. data: {'appid': appid,type:'news'},
  675. dataType: "json",
  676. cache: false,
  677. async: false,
  678. success: function (responseStr) {
  679. $("#imgTextAdd").empty();
  680. let html = '';
  681. for (let i = 0; i < responseStr.data.length; i++) {
  682. let divHtml1 = '';
  683. let divHtml2 = '';
  684. if (i % 3 == 0) {
  685. html += '<div style="display: flex;">';
  686. }
  687. let imgUrl = responseStr.data[i].groupList[0].cover;
  688. html += '<div id=' + responseStr.data[i].media_id + ' class="col-xs-4">' +
  689. '<div class="panel panel-default">' +
  690. '<div class=" newmodul">' +
  691. '<div class="panel-heading msg-date">' +
  692. '<div class=" weui-panel weui-panel_access">' +
  693. '<div class="weui-panel__hd" style="height: 200px;background-image:url(' + imgUrl + ');background-size: 100% 100%;">' +
  694. '<span class="newtitle">' + responseStr.data[i].groupList[0].title + '</span>' +
  695. '</div>';
  696. let circle = '';
  697. if (responseStr.data[i].groupList.length > 1) {
  698. html += '<div class="weui-panel__bd">';
  699. for (let j = 1; j < responseStr.data[i].groupList.length; j++) {
  700. circle = circle +
  701. '<a href="javascript:void(0);" class="weui-media-box weui-media-box_appmsg">' +
  702. '<div class="weui-media-box__bd">' +
  703. '<h4 class="weui-media-box__title">' + responseStr.data[i].groupList[j].title + '</h4>' +
  704. '</div>' +
  705. '<div class="weui-media-box__hd">' +
  706. '<img class="weui-media-box__thumb" src="' + responseStr.data[i].groupList[j].cover + '" alt="">' +
  707. '</div>' +
  708. '</a>'
  709. }
  710. html += circle + '</div>';
  711. }
  712. html += '</div></div></div><div class="mask-bg"><div class="mask-icon"><i class="icon-ok"></i></div></div></div></div>';
  713. if (i % 3 == 2) {
  714. html += '</div>'
  715. }
  716. }
  717. $("#imgTextAdd").append(html);
  718. modalAddClick();
  719. },
  720. error: function (responseStr) {
  721. layer.alert("出错啦");
  722. }
  723. });
  724. let delHtml = '<span class="msg-panel__del del-tuwen">删除</span>';
  725. if ($(".subbutton__actived").attr('alt')) {
  726. let row = $(".subbutton__actived").prevAll().length;
  727. if (button[row].ctype != null) {
  728. $('.msg-template').empty();
  729. $('.msg-context__item').css("display", "block");
  730. $('.mask-bg').hide();
  731. } else if (typeof (button[row].ctype) == 'undefined') {
  732. $('.msg-template').empty();
  733. $('.msg-context__item').css("display", "block");
  734. } else {
  735. var subKey = button[row].media_id;
  736. if (typeof (subKey) == 'undefined') {
  737. $('.msg-template').empty();
  738. $('.msg-context__item').css("display", "block");
  739. $('.mask-bg').hide();
  740. } else {
  741. $('.msg-template').html($('#' + subKey).html());
  742. $('.msg-template').append(delHtml);
  743. //绑定删除事件
  744. $('.msg-panel__del').on('click', delClick);
  745. $('.msg-context__item').css("display", "none");
  746. }
  747. }
  748. } else if ($(".subbutton__actived").attr('id')) {
  749. let row = $(".subbutton__actived").parents('.custom-menu-view__menu').prevAll().length;
  750. let clo = $(".subbutton__actived").prevAll().length;
  751. if (typeof (button[row].sub_button[clo].ctype) == 'undefined') {
  752. $('.msg-template').empty();
  753. $('.msg-context__item').css("display", "block");
  754. } else if (button[row].sub_button[clo].ctype != null) {
  755. $('.msg-template').empty();
  756. $('.msg-context__item').css("display", "block");
  757. $('.mask-bg').hide();
  758. } else {
  759. var subKey = button[row].sub_button[clo].media_id;
  760. if (typeof (subKey) == 'undefined') {
  761. $('.msg-template').empty();
  762. $('.msg-context__item').css("display", "block");
  763. $('.mask-bg').hide();
  764. } else {
  765. $('.msg-template').html($('#' + subKey).html());
  766. $('.msg-template').append(delHtml);
  767. //绑定删除事件
  768. $('.msg-panel__del').on('click', delClick);
  769. $('.msg-context__item').css("display", "none");
  770. }
  771. }
  772. }
  773. }
  774. //图片
  775. function picture() {
  776. // let responseStr = [{
  777. // "materialId": null,
  778. // "mediaId": "5iDtROEQOkUtgnfeqz4pYHZDtiZlnGS-54z-4H8ykCw",
  779. // "url": "img/t.png",
  780. // "type": null,
  781. // "urlExpireTime": null,
  782. // "createTime": null,
  783. // "modifyTime": null,
  784. // "createUserId": null,
  785. // "modifyUserId": null,
  786. // "description": null,
  787. // "appId": null,
  788. // "expireType": null,
  789. // "voiceType": null,
  790. // "title": null,
  791. // "duration": null
  792. // }, {
  793. // "materialId": null,
  794. // "mediaId": "5iDtROEQOkUtgnfeqz4pYFpNwEd0c0Fh-qf0t_nhuJI",
  795. // "url": "img/t.png",
  796. // "type": null,
  797. // "urlExpireTime": null,
  798. // "createTime": null,
  799. // "modifyTime": null,
  800. // "createUserId": null,
  801. // "modifyUserId": null,
  802. // "description": null,
  803. // "appId": null,
  804. // "expireType": null,
  805. // "voiceType": null,
  806. // "title": null,
  807. // "duration": null
  808. // }, {
  809. // "materialId": null,
  810. // "mediaId": "5iDtROEQOkUtgnfeqz4pYH730XMtOP0GDkHZK14u06Q",
  811. // "url": "img/t.png",
  812. // "type": null,
  813. // "urlExpireTime": null,
  814. // "createTime": null,
  815. // "modifyTime": null,
  816. // "createUserId": null,
  817. // "modifyUserId": null,
  818. // "description": null,
  819. // "appId": null,
  820. // "expireType": null,
  821. // "voiceType": null,
  822. // "title": null,
  823. // "duration": null
  824. // }, {
  825. // "materialId": null,
  826. // "mediaId": "5iDtROEQOkUtgnfeqz4pYNCVVCs3RPcU2KcfkO97lao",
  827. // "url": "img/t.png",
  828. // "type": null,
  829. // "urlExpireTime": null,
  830. // "createTime": null,
  831. // "modifyTime": null,
  832. // "createUserId": null,
  833. // "modifyUserId": null,
  834. // "description": null,
  835. // "appId": null,
  836. // "expireType": null,
  837. // "voiceType": null,
  838. // "title": null,
  839. // "duration": null
  840. // }, {
  841. // "materialId": null,
  842. // "mediaId": "5iDtROEQOkUtgnfeqz4pYNI0i2m9i7niS4oXAbh878k",
  843. // "url": "img/t.png",
  844. // "type": null,
  845. // "urlExpireTime": null,
  846. // "createTime": null,
  847. // "modifyTime": null,
  848. // "createUserId": null,
  849. // "modifyUserId": null,
  850. // "description": null,
  851. // "appId": null,
  852. // "expireType": null,
  853. // "voiceType": null,
  854. // "title": null,
  855. // "duration": null
  856. // }, {
  857. // "materialId": null,
  858. // "mediaId": "5iDtROEQOkUtgnfeqz4pYNeYXGRAE3-cN92Zv56lzi4",
  859. // "url": "img/t.png",
  860. // "type": null,
  861. // "urlExpireTime": null,
  862. // "createTime": null,
  863. // "modifyTime": null,
  864. // "createUserId": null,
  865. // "modifyUserId": null,
  866. // "description": null,
  867. // "appId": null,
  868. // "expireType": null,
  869. // "voiceType": null,
  870. // "title": null,
  871. // "duration": null
  872. // }, {
  873. // "materialId": null,
  874. // "mediaId": "5iDtROEQOkUtgnfeqz4pYPSc3ObOPTZSTix_VcWVXOY",
  875. // "url": "img/t.png",
  876. // "type": null,
  877. // "urlExpireTime": null,
  878. // "createTime": null,
  879. // "modifyTime": null,
  880. // "createUserId": null,
  881. // "modifyUserId": null,
  882. // "description": null,
  883. // "appId": null,
  884. // "expireType": null,
  885. // "voiceType": null,
  886. // "title": null,
  887. // "duration": null
  888. // }];
  889. var appid = $("#appIdcode").val();
  890. $.ajax({
  891. url: baseURL + '/admin/wechat/getMaterialByType',
  892. type: 'POST',
  893. data: {appid: appid,type:'image'},
  894. dataType: "json",
  895. cache: false,
  896. async: false,
  897. success: function (responseStr) {
  898. responseStr = responseStr.data;
  899. var imgHtml = '';
  900. for (let i = 0; i < responseStr.length; i++) {
  901. if (i % 3 == 0) {
  902. imgHtml += '<div style="display: flex;">'
  903. }
  904. imgHtml += '<div id=' + responseStr[i].media_id+ ' class="col-xs-4">'
  905. + '<div class="panel panel-default">'
  906. + '<div class="panel-body">'
  907. + '<div class="msg-img"><img src=' + responseStr[i].media_url+ ' alt=""></div>'
  908. + '</div>'
  909. + '<div class="mask-bg"><div class="mask-icon"><i class="icon-ok"></i></div></div>'
  910. + '</div>'
  911. + '</div>';
  912. if (i % 3 == 2) {
  913. imgHtml += '</div>'
  914. }
  915. }
  916. ;
  917. $("#imgTextAdd").append(imgHtml);
  918. modalAddClick();
  919. },
  920. error: function (responseStr) {
  921. layer.alert("出错啦");
  922. }
  923. });
  924. let delHtml = '<span class="msg-panel__del del-tuwen">删除</span>';
  925. if ($(".subbutton__actived").attr('alt')) {
  926. let row = $(".subbutton__actived").prevAll().length;
  927. if (button[row].ctype != 'image') {
  928. $('.msg-template').empty();
  929. $('.msg-context__item').css("display", "block");
  930. $('.mask-bg').hide();
  931. } else {
  932. var subKey = button[row].media_id;
  933. if (typeof (subKey) == 'undefined') {
  934. $('.msg-template').empty();
  935. $('.msg-context__item').css("display", "block");
  936. $('.mask-bg').hide();
  937. } else {
  938. $('.msg-template').html($('#' + subKey).html());
  939. $('.msg-template').append(delHtml);
  940. //绑定删除事件
  941. $('.msg-panel__del').on('click', delClick);
  942. $('.msg-context__item').css("display", "none");
  943. }
  944. }
  945. } else if ($(".subbutton__actived").attr('id')) {
  946. let row = $(".subbutton__actived").parents('.custom-menu-view__menu').prevAll().length;
  947. let clo = $(".subbutton__actived").prevAll().length;
  948. if (typeof (button[row].sub_button[clo].ctype) == 'undefined') {
  949. $('.msg-template').empty();
  950. $('.msg-context__item').css("display", "block");
  951. } else if (button[row].sub_button[clo].ctype != 'image') {
  952. $('.msg-template').empty();
  953. $('.msg-context__item').css("display", "block");
  954. $('.mask-bg').hide();
  955. } else {
  956. var subKey = button[row].sub_button[clo].media_id;
  957. if (typeof (subKey) == 'undefined') {
  958. $('.msg-template').empty();
  959. $('.msg-context__item').css("display", "block");
  960. $('.mask-bg').hide();
  961. } else {
  962. $('.msg-template').html($('#' + subKey).html());
  963. $('.msg-template').append(delHtml);
  964. //绑定删除事件
  965. $('.msg-panel__del').on('click', delClick);
  966. $('.msg-context__item').css("display", "none");
  967. }
  968. }
  969. }
  970. }
  971. // 语音
  972. function voice() {
  973. // let responseStr = [{
  974. // "materialId": null,
  975. // "mediaId": "5iDtROEQOkUtgnfeqz4pYGQrFMcl2U3gezrZ6fR4hV4",
  976. // "url": "#",
  977. // "type": null,
  978. // "urlExpireTime": null,
  979. // "createTime": "2019-06-14 09:46:40",
  980. // "modifyTime": null,
  981. // "createUserId": null,
  982. // "modifyUserId": null,
  983. // "description": null,
  984. // "appId": null,
  985. // "expireType": null,
  986. // "voiceType": null,
  987. // "title": "music",
  988. // "duration": 36
  989. // }];
  990. var appid = $("#appIdcode").val();
  991. $.ajax({
  992. url: baseURL + '/admin/wechat/getMaterialByType',
  993. type: 'POST',
  994. data: {appid: appid,'type':'voice'},
  995. dataType: "json",
  996. cache: false,
  997. async: false,
  998. success: function (responseStr) {
  999. var responseStr = responseStr.data;
  1000. $("#imgTextAdd").empty();
  1001. for (var i = 0; i < responseStr.length; i++) {
  1002. let voice = '<div id=' + responseStr[i].media_id+ ' class="col-xs-4">' +
  1003. ' <div class="panel panel-default">' +
  1004. ' <div class="panel-body"><div class="wx-audio-content jg" >' +
  1005. ' <audio muted class="wx-audio-content" src=\"' + responseStr[i].media_url + '\" loop="true"></audio>' +
  1006. ' <div class="wx-audio-left">\n' +
  1007. ' <img class="wx-audio-state" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFQAAABUCAMAAAArteDzAAAAaVBMVEUAAAAarRkarRkarRkarRkarRkarRkarRkarRkarRkarRkarRkarRkarRkarRkarRkarRkarRkarRkarRkarRkarRkarRkarRkarRkarRkarRkarRkarRkarRkarRkarRkarRkarRkarRlIa6J1AAAAInRSTlMA9wYa38QR7ZJnMK1IIqBsO3fXDbSGQudZz5fKpV0rfbpRlHIjYQAAA35JREFUWMPFWduyqjAMDS0tgtwEFBGv/P9Hntmh3cWDTYsMs/Oio3SRy0qapuCU7PXIRdUGQxCFncgfrwzWCb/l4TCTML/xbxFlIQariEJ+AZnkwUBKkCdLIZvBQ5olsPw61Uhc4vTOa4Ca39P4IqYWXH2dyw5mWXUs2ez/8liZVx6YD2bW6wXRzmpesov0U70HxW5azTBmpD1xqJW9uUzfaS0Lp1ms0Nru6Nfv9WPSi8lahT2BKoWyvARPKZUPhLRiduq9ckHaKds6y5pa6XmARXJQutaEP4MzLJTzyJfmk193I2YKiyUdUXcf+OnCdKPO+JqNvxO2kx4YNcr+c2jvjpE7Wv27W4uRS/C1jFEu3mpdhJyX34PWISY3ByNj/SxhhZRjfZ0UMkUJt3Bxx08rJU2xbFB16YEZDiG3JSy6sHlXNPbCHIbOVpHiN1VzjBLzKOCkmxjGKld6B4oNbjkiqi3rkJeBNN8jBj7SUEaxyGgnjE1OkS0mHkUAgd5X/qWF80mWR7PaOY0410GrnHHXVHpSqlZII521RzeXqtpkTkgEEitIiwF1YeLDJgQnIldbgAx5wMBj5z4br+aWB5GdGbxUxGjUp6ESLmxhJsaMFzx+Pi5+VIpN6bTUlcvPfw/InXlvjO5MjsdE/ucg6DjxRlEJY4Wb0J1IlnR0ZoXGEHF/6l1I68d+vj3ho9xH0mO+cjumNiMxvg/tTOWYcIAkqCl+XjRbtH7CHv4aCQrIQIui3TCxNPyN1BMXfhQFFxCgJ/yzmYAaTpGgEZpPoOq60GJctfkRaX5IBApRVTNTm/TvnYHqCEoh6kMzUCuNxnUUpVzkB/2+/Pc5iTpT5PdNUx78FrMT6kymqbugmEpxNZU4JXaph7v0GbOGxJQ3SZU+ryINSWT8iAt6skg7txPD1wCJN/rrQG0nZuNzo54nHQOnNj6zRTtRj5Pe5klu0d7NBGTThvFENhNE20NQS5BtD9GgUdQqyQZtaSuZ4bIr1fUGcmHTCz1SRpJNL9GeE3xNHe35/CDhRj04DhLzI48b9eI48mxxONvyGLn+wGtsLTY5mm87RFg/7jhNxh3bD2aANWtHSFsOu7Yfy60fIG4/6lw/lN14fOwedJdWXxKD7m1H8u7LAwZMZsn88mCDa46/v5DZ6OoIhcf7dg7Y7mPalb7XcVEwDEFU+V3H/QOplcP+ctPpgwAAAABJRU5ErkJggg==" />\n' +
  1008. ' </div>' +
  1009. ' <div class="wx-audio-right">' +
  1010. ' <div><p class="wx-audio-title">' + responseStr[i].title + '</p>' +
  1011. ' <p class="wx-audio-disc">' + responseStr[i].create_time + '</p>' +
  1012. ' <p class="wx-audio-disc">00:' + responseStr[i].duration?responseStr[i].duration:0 + '</p></div>' +
  1013. ' </div></div>' +
  1014. ' </div><div class="mask-bg"><div class="mask-icon"><i class="icon-ok"></i></div></div></div>';
  1015. $("#imgTextAdd").append(voice);
  1016. }
  1017. modalAddClick();
  1018. },
  1019. error: function (responseStr) {
  1020. layer.alert("出错啦");
  1021. }
  1022. });
  1023. let delHtml = '<span class="msg-panel__del del-tuwen">删除</span>';
  1024. if ($(".subbutton__actived").attr('alt')) {
  1025. let row = $(".subbutton__actived").prevAll().length;
  1026. if (button[row].ctype != 'voice') {
  1027. $('.msg-template').empty();
  1028. $('.msg-context__item').css("display", "block");
  1029. $('.mask-bg').hide();
  1030. } else {
  1031. var subKey = button[row].media_id;
  1032. if (typeof (subKey) == 'undefined') {
  1033. $('.msg-template').empty();
  1034. $('.msg-context__item').css("display", "block");
  1035. $('.mask-bg').hide();
  1036. } else {
  1037. $('.msg-template').html($('#' + subKey).html());
  1038. $('.msg-template').append(delHtml);
  1039. //绑定删除事件
  1040. $('.msg-panel__del').on('click', delClick);
  1041. $('.msg-context__item').css("display", "none");
  1042. }
  1043. }
  1044. } else if ($(".subbutton__actived").attr('id')) {
  1045. let row = $(".subbutton__actived").parents('.custom-menu-view__menu').prevAll().length;
  1046. let clo = $(".subbutton__actived").prevAll().length;
  1047. if (typeof (button[row].sub_button[clo].ctype) == 'undefined') {
  1048. $('.msg-template').empty();
  1049. $('.msg-context__item').css("display", "block");
  1050. } else if (button[row].sub_button[clo].ctype != 'voice') {
  1051. $('.msg-template').empty();
  1052. $('.msg-context__item').css("display", "block");
  1053. $('.mask-bg').hide();
  1054. } else {
  1055. var subKey = button[row].sub_button[clo].media_id;
  1056. if (typeof (subKey) == 'undefined') {
  1057. $('.msg-template').empty();
  1058. $('.msg-context__item').css("display", "block");
  1059. $('.mask-bg').hide();
  1060. } else {
  1061. $('.msg-template').html($('#' + subKey).html());
  1062. $('.msg-template').append(delHtml);
  1063. //绑定删除事件
  1064. $('.msg-panel__del').on('click', delClick);
  1065. $('.msg-context__item').css("display", "none");
  1066. }
  1067. }
  1068. }
  1069. }
  1070. // 视频
  1071. function video1() {
  1072. var appid = $("#appIdcode").val();
  1073. $.ajax({
  1074. url: baseURL + '/admin/wechat/getMaterialByType',
  1075. type: 'POST',
  1076. data: {appid: appid,type:'video'},
  1077. dataType: "json",
  1078. cache: false,
  1079. async: false,
  1080. success: function (responseStr) {
  1081. responseStr = responseStr.data;
  1082. $("#imgTextAdd").empty();
  1083. for (var i = 0; i < responseStr.length; i++) {
  1084. let voice = '<div id=' + responseStr[i].media_id + ' class="col-xs-4">' +
  1085. ' <div class="panel panel-default">' +
  1086. ' <div class="panel-body"><div class="wx-audio-content jg" >' +
  1087. ' <audio muted class="wx-audio-content" src=\"' + responseStr[i].media_url + '\" loop="true"></audio>' +
  1088. ' <div class="wx-audio-left">\n' +
  1089. ' <img class="wx-audio-state" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFQAAABUCAMAAAArteDzAAAAaVBMVEUAAAAarRkarRkarRkarRkarRkarRkarRkarRkarRkarRkarRkarRkarRkarRkarRkarRkarRkarRkarRkarRkarRkarRkarRkarRkarRkarRkarRkarRkarRkarRkarRkarRkarRkarRlIa6J1AAAAInRSTlMA9wYa38QR7ZJnMK1IIqBsO3fXDbSGQudZz5fKpV0rfbpRlHIjYQAAA35JREFUWMPFWduyqjAMDS0tgtwEFBGv/P9Hntmh3cWDTYsMs/Oio3SRy0qapuCU7PXIRdUGQxCFncgfrwzWCb/l4TCTML/xbxFlIQariEJ+AZnkwUBKkCdLIZvBQ5olsPw61Uhc4vTOa4Ca39P4IqYWXH2dyw5mWXUs2ez/8liZVx6YD2bW6wXRzmpesov0U70HxW5azTBmpD1xqJW9uUzfaS0Lp1ms0Nru6Nfv9WPSi8lahT2BKoWyvARPKZUPhLRiduq9ckHaKds6y5pa6XmARXJQutaEP4MzLJTzyJfmk193I2YKiyUdUXcf+OnCdKPO+JqNvxO2kx4YNcr+c2jvjpE7Wv27W4uRS/C1jFEu3mpdhJyX34PWISY3ByNj/SxhhZRjfZ0UMkUJt3Bxx08rJU2xbFB16YEZDiG3JSy6sHlXNPbCHIbOVpHiN1VzjBLzKOCkmxjGKld6B4oNbjkiqi3rkJeBNN8jBj7SUEaxyGgnjE1OkS0mHkUAgd5X/qWF80mWR7PaOY0410GrnHHXVHpSqlZII521RzeXqtpkTkgEEitIiwF1YeLDJgQnIldbgAx5wMBj5z4br+aWB5GdGbxUxGjUp6ESLmxhJsaMFzx+Pi5+VIpN6bTUlcvPfw/InXlvjO5MjsdE/ucg6DjxRlEJY4Wb0J1IlnR0ZoXGEHF/6l1I68d+vj3ho9xH0mO+cjumNiMxvg/tTOWYcIAkqCl+XjRbtH7CHv4aCQrIQIui3TCxNPyN1BMXfhQFFxCgJ/yzmYAaTpGgEZpPoOq60GJctfkRaX5IBApRVTNTm/TvnYHqCEoh6kMzUCuNxnUUpVzkB/2+/Pc5iTpT5PdNUx78FrMT6kymqbugmEpxNZU4JXaph7v0GbOGxJQ3SZU+ryINSWT8iAt6skg7txPD1wCJN/rrQG0nZuNzo54nHQOnNj6zRTtRj5Pe5klu0d7NBGTThvFENhNE20NQS5BtD9GgUdQqyQZtaSuZ4bIr1fUGcmHTCz1SRpJNL9GeE3xNHe35/CDhRj04DhLzI48b9eI48mxxONvyGLn+wGtsLTY5mm87RFg/7jhNxh3bD2aANWtHSFsOu7Yfy60fIG4/6lw/lN14fOwedJdWXxKD7m1H8u7LAwZMZsn88mCDa46/v5DZ6OoIhcf7dg7Y7mPalb7XcVEwDEFU+V3H/QOplcP+ctPpgwAAAABJRU5ErkJggg==" />\n' +
  1090. ' </div>' +
  1091. ' <div class="wx-audio-right">' +
  1092. ' <div><p class="wx-audio-title">' + responseStr[i].file_name + '</p>' +
  1093. ' <p class="wx-audio-disc">' + responseStr[i].create_time + '</p>' +
  1094. ' <p class="wx-audio-disc">00:' + responseStr[i].duration?responseStr[i].duration:'' + '</p></div>' +
  1095. ' </div></div>' +
  1096. ' </div><div class="mask-bg"><div class="mask-icon"><i class="icon-ok"></i></div></div></div>';
  1097. $("#imgTextAdd").append(voice);
  1098. }
  1099. $("#imgTextAdd").append(voice);
  1100. modalAddClick();
  1101. },
  1102. error: function (responseStr) {
  1103. layer.alert("出错啦");
  1104. }
  1105. });
  1106. let delHtml = '<span class="msg-panel__del del-tuwen">删除</span>';
  1107. if ($(".subbutton__actived").attr('alt')) {
  1108. let row = $(".subbutton__actived").prevAll().length;
  1109. if (button[row].ctype != 'video') {
  1110. $('.msg-template').empty();
  1111. $('.msg-context__item').css("display", "block");
  1112. $('.mask-bg').hide();
  1113. } else {
  1114. var subKey = button[row].media_id;
  1115. if (typeof (subKey) == 'undefined') {
  1116. $('.msg-template').empty();
  1117. $('.msg-context__item').css("display", "block");
  1118. $('.mask-bg').hide();
  1119. } else {
  1120. $('.msg-template').html($('#' + subKey).html());
  1121. $('.msg-template').append(delHtml);
  1122. //绑定删除事件
  1123. $('.msg-panel__del').on('click', delClick);
  1124. $('.msg-context__item').css("display", "none");
  1125. }
  1126. }
  1127. } else if ($(".subbutton__actived").attr('id')) {
  1128. let row = $(".subbutton__actived").parents('.custom-menu-view__menu').prevAll().length;
  1129. let clo = $(".subbutton__actived").prevAll().length;
  1130. if (typeof (button[row].sub_button[clo].ctype) == 'undefined') {
  1131. $('.msg-template').empty();
  1132. $('.msg-context__item').css("display", "block");
  1133. } else if (button[row].sub_button[clo].ctype != 'video') {
  1134. $('.msg-template').empty();
  1135. $('.msg-context__item').css("display", "block");
  1136. $('.mask-bg').hide();
  1137. } else {
  1138. var subKey = button[row].sub_button[clo].media_id;
  1139. if (typeof (subKey) == 'undefined') {
  1140. $('.msg-template').empty();
  1141. $('.msg-context__item').css("display", "block");
  1142. $('.mask-bg').hide();
  1143. } else {
  1144. $('.msg-template').html($('#' + subKey).html());
  1145. $('.msg-template').append(delHtml);
  1146. //绑定删除事件
  1147. $('.msg-panel__del').on('click', delClick);
  1148. $('.msg-context__item').css("display", "none");
  1149. }
  1150. }
  1151. }
  1152. }
  1153. // 添加素材
  1154. $('.msg-panel-add').click(function () {
  1155. var index = layer.open({
  1156. type: 2,
  1157. content: '{:url("materialAdd")}',
  1158. area: ['800px', '100%'],
  1159. anim: 2,
  1160. maxmin: true,
  1161. });
  1162. layer.full(index);
  1163. })
  1164. // 选择素材
  1165. function modalAddClick() {
  1166. $(".msg-panel_select").on('click', function () {
  1167. if ($("li").hasClass("msg-tab_item on")) {
  1168. let dom = $("#clickUl").find(".on").attr('id');
  1169. switch (dom) {
  1170. case 'imgtextLi':
  1171. $(".modal-title1").text('选择图文消息');
  1172. break;
  1173. case 'imgLi':
  1174. $(".modal-title1").text('选择图片消息');
  1175. break;
  1176. case 'voice':
  1177. $(".modal-title1").text('选择语音消息');
  1178. break;
  1179. case 'video':
  1180. $(".modal-title1").text('选择视频消息');
  1181. break;
  1182. }
  1183. }
  1184. });
  1185. //id为selectModal弹框选中遮罩层
  1186. $('#selectModal .modal-body .panel').click(function () {
  1187. $(this).find('.mask-bg').show();
  1188. $(this).parent().siblings().find('.mask-bg').hide();
  1189. mId = $(this).parent().attr('id');
  1190. });
  1191. //id为selectModal弹框确定按钮事件
  1192. $('#selectModal .ensure').on('click', function () {
  1193. var msgTemp = $('.msg-template');
  1194. var delEl = '<span class="msg-panel__del del-tuwen">删除</span>';
  1195. if (mId != null) {
  1196. msgTemp.html($('#' + mId).html());
  1197. delElement();
  1198. msgTemp.find('.mask-bg').hide();
  1199. msgTemp.siblings().hide();
  1200. msgTemp.show();
  1201. tempObj[mId] = msgTemp.html();
  1202. //绑定删除事件
  1203. $('.msg-panel__del').on('click', delClick);
  1204. var current = $('.subbutton__actived').prevAll().length;
  1205. var input_name = $('input[name="custom_input_title"]');
  1206. if ($('.custom-menu-view__menu__sub__add').hasClass('subbutton__actived')) {
  1207. var sub_col = $(".subbutton__actived").prevAll().length;
  1208. var sub_row = $(".subbutton__actived").parents('.custom-menu-view__menu').prevAll().length;
  1209. button[sub_row].sub_button[sub_col].name = input_name.val();
  1210. button[sub_row].sub_button[sub_col].media_id = mId;
  1211. button[sub_row].sub_button[sub_col].type = 'media_id';
  1212. if ($("li").hasClass("msg-tab_item on")) {
  1213. let dom = $("#clickUl").find(".on").attr('id');
  1214. switch (dom) {
  1215. case 'imgtextLi':
  1216. button[sub_row].sub_button[sub_col].ctype = null;
  1217. break;
  1218. case 'imgLi':
  1219. button[sub_row].sub_button[sub_col].ctype = 'image';
  1220. break;
  1221. case 'voice':
  1222. button[sub_row].sub_button[sub_col].ctype = 'voice';
  1223. break;
  1224. case 'video':
  1225. button[sub_row].sub_button[sub_col].ctype = 'video';
  1226. break;
  1227. }
  1228. }
  1229. } else if ($('.custom-menu-view__menu').hasClass('subbutton__actived')) {
  1230. button[current].name = input_name.val();
  1231. button[current].media_id = mId;
  1232. button[current].type = 'media_id';
  1233. if ($("li").hasClass("msg-tab_item on")) {
  1234. let dom = $("#clickUl").find(".on").attr('id');
  1235. switch (dom) {
  1236. case 'imgtextLi':
  1237. button[current].ctype = null;
  1238. break;
  1239. case 'imgLi':
  1240. button[current].ctype = 'image';
  1241. break;
  1242. case 'voice':
  1243. button[current].ctype = 'voice';
  1244. break;
  1245. case 'video':
  1246. button[current].ctype = 'video';
  1247. break;
  1248. }
  1249. }
  1250. }
  1251. }
  1252. $('#selectModal').modal('hide');
  1253. });
  1254. }
  1255. //更换公众号
  1256. function appIdChange() {
  1257. var app_id = $("#appIdcode").val();
  1258. $.ajax({
  1259. url: baseURL + '/admin/wechat/changeApp',
  1260. type: "POST",
  1261. data: {app_id:app_id}, // 以json字符串方式传递
  1262. cache: true,
  1263. async: true,
  1264. success: function (res) {
  1265. if (res.data.button.length > 0) {
  1266. obj = {
  1267. "menu":res.data,
  1268. };
  1269. $('.custom-menu-view__menu').remove();
  1270. //清除右边数据
  1271. $('.cm-edit-before').show().siblings().hide();
  1272. menuCreate(obj);
  1273. } else {
  1274. obj = {
  1275. "menu": res.data,
  1276. };
  1277. $('.custom-menu-view__menu').remove();
  1278. menuCreate(obj);
  1279. //清除右边数据
  1280. $('.cm-edit-before').show().siblings().hide();
  1281. }
  1282. },
  1283. error: function (res) {
  1284. layer.msg('请求失败');
  1285. }
  1286. });
  1287. // // 数据格式
  1288. // // obj = {
  1289. // // "menu": {button: []}
  1290. // // };
  1291. // $('.custom-menu-view__menu').remove();
  1292. //
  1293. // //清除右边数据
  1294. // $('.cm-edit-before').show().siblings().hide();
  1295. // menuCreate(obj);
  1296. }
  1297. // 初始化公众号
  1298. $(function () {
  1299. $.ajax({
  1300. url: baseURL + '/admin/wechat/getWxAccount',
  1301. type: "POST",
  1302. data: null, // 以json字符串方式传递
  1303. cache: true,
  1304. async: true,
  1305. success: function (data) {
  1306. data = JSON.parse(data);
  1307. var str = "";
  1308. for (var i = 0; i < data.length; i++) {
  1309. str += "<option value='" + data[i].app_id + "'>" + data[i].wxname + "</option>";
  1310. }
  1311. if (data.length >= 0) {
  1312. $(".custom-menu-view__title").text(data[0].wxname);
  1313. }
  1314. $('#appIdcode').html(str);
  1315. appIdChange();
  1316. },
  1317. error: function (data) {
  1318. }
  1319. });
  1320. $("#appIdcode").on("change", function (e) {
  1321. // e 的话就是一个对象 然后需要什么就 “e.参数” 形式 进行获取
  1322. appIdChange();
  1323. imageText();
  1324. $(".custom-menu-view__title").text(' ');
  1325. $(".custom-menu-view__title").text($("#appIdcode").find("option:selected").text());
  1326. })
  1327. })
  1328. //同步
  1329. $('#synchroBtns').click(function () {
  1330. layer.msg("同步成功!");
  1331. $.ajax({
  1332. url: baseURL + '/admin/wechat/updataWechatMenu',
  1333. type: "POST",
  1334. data: {
  1335. "appId": $("#appIdcode").val()
  1336. },
  1337. contentType: "application/json",
  1338. dataType: "json",
  1339. success: function (res) {
  1340. if (res.code > 0) {
  1341. layer.msg("同步成功!");
  1342. } else {
  1343. layer.msg(res.msg);
  1344. }
  1345. },
  1346. error: function (res) {
  1347. layer.msg('网络错误');
  1348. }
  1349. });
  1350. });
  1351. //预览
  1352. $(function () {
  1353. // 预览点击
  1354. $("#showPhone").on('click', function () {
  1355. $("#mobileDiv").css('display', "block");
  1356. $(".mask").css('display', "block");
  1357. //公众号名
  1358. $(".nickname").text(' ');
  1359. $(".nickname").text($("#appIdcode").find("option:selected").text());
  1360. $("#viewList").empty();
  1361. $("#viewShow").empty();
  1362. $(".cm-edit-after").css('display', 'none');
  1363. $(".cm-edit-before").css('display', 'block');
  1364. $(".subbutton__actived").removeClass('subbutton__actived');
  1365. //遍历按钮
  1366. let html
  1367. for (let i = 0; i < obj.menu.button.length; i++) {
  1368. html = '<li class="pre_menu_item grid_item size1of' + obj.menu.button.length + ' jsViewLi " id="menu_' + i + '">' +
  1369. '<a href="javascript:void(0);" class="jsView pre_menu_link" title="' + obj.menu.button[i].name + '" draggable="false" ' +
  1370. 'media_id="' + obj.menu.button[i].media_id + '" ctype="' + obj.menu.button[i].ctype + '" type="' + obj.menu.button[i].type + '">';
  1371. if (obj.menu.button[i].sub_button.length) {
  1372. html += '<i class="icon_menu_dot"></i>';
  1373. }
  1374. html += obj.menu.button[i].name + '</a>';
  1375. let htmlDiv = '';
  1376. if (obj.menu.button[i].sub_button.length) {
  1377. htmlDiv += '<div class="sub_pre_menu_box jsSubViewDiv" style="display:none">' +
  1378. '<ul class="sub_pre_menu_list">';
  1379. for (let j = 0; j < obj.menu.button[i].sub_button.length; j++) {
  1380. htmlDiv += '<li id="subMenu_menu_0_' + j + '">' +
  1381. '<a href="javascript:void(0);" class="jsSubView" title="' + obj.menu.button[i].sub_button[j].name + '" draggable="false" ' +
  1382. 'media_id="' + obj.menu.button[i].sub_button[j].media_id + '" ctype="' + obj.menu.button[i].sub_button[j].ctype + '" type="' + obj.menu.button[i].sub_button[j].type + '">' +
  1383. obj.menu.button[i].sub_button[j].name +
  1384. '</a>' +
  1385. '</li>';
  1386. }
  1387. htmlDiv += '</ul>' +
  1388. '<i class="arrow arrow_out"></i>' +
  1389. '<i class="arrow arrow_in"></i>' +
  1390. '</div>';
  1391. }
  1392. html += htmlDiv + '</li>';
  1393. $("#viewList").append(html);
  1394. }
  1395. $(".jsViewLi").off('click').on('click', function () {
  1396. switch ($(this).find('.jsSubViewDiv').css('display')) {
  1397. case 'none':
  1398. $('.jsSubViewDiv').css('display', 'none');
  1399. $(this).find('.jsSubViewDiv').css('display', 'block');
  1400. break;
  1401. case 'block':
  1402. $('.jsSubViewDiv').css('display', 'none');
  1403. $(this).find('.jsSubViewDiv').css('display', 'none');
  1404. break;
  1405. }
  1406. })
  1407. $("#viewList").off('click').on('click', 'li', function () {
  1408. switch ($(this).children('a').attr('type')) {
  1409. case 'media_id':
  1410. let media_id = $(this).children('a').attr('media_id');
  1411. switch ($(this).children('a').attr('ctype')) {
  1412. // $('#' + mId).html()
  1413. case 'null':
  1414. imageText();
  1415. $("#viewShow").append('<li class="show_item">' + $('#' + media_id).html() + '</li>');
  1416. $('.mobile_preview_bd').scrollTop($('#viewShow')[0].scrollHeight);
  1417. break;
  1418. case 'image':
  1419. picture();
  1420. $("#viewShow").append('<li class="show_item">' + $('#' + media_id).html() + '</li>');
  1421. $('.mobile_preview_bd').scrollTop($('#viewShow')[0].scrollHeight);
  1422. break;
  1423. case 'voice':
  1424. voice();
  1425. $("#viewShow").append('<li class="show_item">' + $('#' + media_id).html() + '</li>');
  1426. $('.mobile_preview_bd').scrollTop($('#viewShow')[0].scrollHeight);
  1427. break;
  1428. case 'video':
  1429. video1();
  1430. $("#viewShow").append('<li class="show_item">' + $('#' + media_id).html() + '</li>');
  1431. $('.mobile_preview_bd').scrollTop($('#viewShow')[0].scrollHeight);
  1432. break;
  1433. }
  1434. break;
  1435. case 'view': //根据当前点击li判断上级ul是否一级菜单
  1436. if ($(this).parent('ul').hasClass('sub_pre_menu_list')) {
  1437. //代表二级菜单
  1438. let row = $(this).parents('.pre_menu_item').prevAll().length;
  1439. let col = $(this).prevAll().length;
  1440. $(this).children('a').attr('href', button[row].sub_button[col].url);
  1441. $(this).children('a').attr('target', '_blank');
  1442. } else if ($(this).parent('ul').hasClass('pre_menu_list')) {
  1443. //代表一级菜单
  1444. let row = $(this).prevAll().length;
  1445. $(this).children('a').attr('href', button[row].url);
  1446. $(this).children('a').attr('target', '_blank');
  1447. }
  1448. break;
  1449. }
  1450. });
  1451. })
  1452. // 退出预览
  1453. $(".mobile_preview_closed").on('click', function () {
  1454. $("#mobileDiv").css('display', "none");
  1455. $(".mask").css('display', "none");
  1456. })
  1457. })
  1458. </script>