add_keyword.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. {extend name="public/container"}
  2. {block name="head_top"}
  3. <link rel="stylesheet" type="text/css" href="{__ADMIN_PATH}css/main.css" />
  4. <script src="{__FRAME_PATH}js/bootstrap.min.js"></script>
  5. <script src="{__FRAME_PATH}js/content.min.js"></script>
  6. <script src="{__ADMIN_PATH}frame/js/ajaxfileupload.js"></script>
  7. <script src="{__PLUG_PATH}moment.js"></script>
  8. {/block}
  9. {block name="content"}
  10. <div id="app" class="row">
  11. <div ref="transfer"></div>
  12. <div class="col-sm-12">
  13. <div class="wechat-reply-wrapper">
  14. <div class="ibox-title"><p>{{msg}}</p></div>
  15. <div class="ibox-content clearfix">
  16. <div class="view-wrapper col-sm-4">
  17. <div class="mobile-header">公众号</div>
  18. <section class="view-body" style="overflow:scroll;">
  19. <div class="time-wrapper"><span class="time">9:36</span></div>
  20. <div class="view-item text-box clearfix" :class="{show:type=='text'}">
  21. <div class="avatar fl"><img src="{__ADMIN_PATH}images/head.gif" /></div>
  22. <div class="box-content fl">
  23. {{dataGroup.text.content}}
  24. </div>
  25. </div>
  26. <div class="view-item news-box" :class="{show:type=='news'}" v-if="dataGroup.news.length >0">
  27. <div class="vn-content" v-if="dataGroup.news.length ==1">
  28. <div class="vn-title">{{dataGroup.news[0].title}}</div>
  29. <div class="vn-time">{{dataGroup.news[0].date}}</div>
  30. <div class="vn-picture" :style="{backgroundImage: 'url('+dataGroup.news[0].image+')'}"></div>
  31. <div class="vn-picture-info">{{dataGroup.news[0].description}}</div>
  32. <div class="vn-more">
  33. <a :href="dataGroup.news[0].url">阅读原文</a>
  34. </div>
  35. </div>
  36. <div class="vn-content" v-else>
  37. <div class="con-item-box">
  38. <div class="vn-picture" :style="{backgroundImage: 'url('+dataGroup.news[0].image+')'}"></div>
  39. <div class="first-title">{{dataGroup.news[0].title}}</div>
  40. </div>
  41. <div class="con-item-list clearfix" v-for="(newinfos,index) in dataGroup.news" v-if="index>0">
  42. <div class="list-tit-info fl">{{newinfos.title}}</div>
  43. <div class="list-pic fr" :style="{backgroundImage: 'url('+newinfos.image+')'}"></div>
  44. </div>
  45. </div>
  46. </div>
  47. <div class="view-item text-box clearfix" :class="{show:type=='image'}">
  48. <div class="avatar fl"><img src="{__ADMIN_PATH}images/head.gif" /></div>
  49. <div class="box-content fl">
  50. <img class="picbox" :src="dataGroup.image.src" alt="" />
  51. </div>
  52. </div>
  53. </section>
  54. </div>
  55. <div class="control-wrapper col-sm-8">
  56. <section>
  57. <form action="" method="post" enctype="multipart/form-data">
  58. <div class="control-title">{{msg}}</div>
  59. <div class="control-body">
  60. <div class="form-group clearfix">
  61. <label class="col-sm-2 tips" for="">关键字</label>
  62. <div class="col-sm-10 group-item">
  63. <input style="resize: none;width: 100%;padding: 6px 12px;" v-model="keyword" type="text" name="keyword" placeholder="请输入关键字" {if condition="$key"}disabled="disabled"{/if} />
  64. </div>
  65. </div>
  66. <div class="form-group clearfix">
  67. <label class="col-sm-2 control-label tips" for="">规则状态</label>
  68. <div class="group-item col-sm-10">
  69. <div class="radio i-checks" style="display:inline;margin-left: 16px;">
  70. <label class="" style="padding-left: 0;">
  71. <input style="position: relative;top: 1px;left: 3px;" checked="checked" v-model="status" type="radio" value="1" name="status">
  72. 启用</label>
  73. </div>
  74. <div class="radio i-checks" style="display:inline;margin-left: 32px;">
  75. <label class="" style="padding-left: 0;">
  76. <input style="position: relative;top: 1px;left: 3px;" type="radio" value="0" v-model="status" name="status">
  77. 禁用
  78. </label>
  79. </div>
  80. </div>
  81. </div>
  82. <div class="form-group clearfix">
  83. <label class="col-sm-2 tips" for="">消息类型</label>
  84. <div class="col-sm-10 group-item">
  85. <select class="form-control m-b" v-model="type" name="account">
  86. <option value="text">文字消息</option>
  87. <option value="image">图片消息</option>
  88. <option value="news">图文消息</option>
  89. <option value="voice">声音消息</option>
  90. </select>
  91. </div>
  92. </div>
  93. <div class="control-main">
  94. <!-- 文字 -->
  95. <div class="control-item control-main-txt" :class="{show:type=='text'}">
  96. <div class="form-group clearfix">
  97. <label class="col-sm-2 tips" for="">规则内容</label>
  98. <div class="col-sm-10 group-item">
  99. <textarea v-model="dataGroup.text.content" name="" id="" cols="30" rows="10" placeholder="请输入内容"></textarea>
  100. </div>
  101. </div>
  102. </div>
  103. <input id="file" type="file" name="file" style="display: none;" />
  104. <!-- 图文 -->
  105. <div class="control-item control-main-news" :class="{show:type=='news'}">
  106. <div class="form-group clearfix">
  107. <label class="col-sm-2 tips" for="">选取图文</label>
  108. <div class="col-sm-10 group-item" @click="selectNews" style="cursor: pointer;"><span>选择图文消息</span></div>
  109. </div>
  110. </div>
  111. <!-- 图片 -->
  112. <div class="control-item control-main-picture" :class="{show:type=='image'}">
  113. <div class="form-group clearfix">
  114. <label class="col-sm-2 tips" for="">图片地址</label>
  115. <div class="col-sm-10 group-item">
  116. <input v-model="dataGroup.image.src" class="form-control" readonly type="text" placeholder="请上传图片"/>
  117. <span id="flag" class="file-btn" @click="uploadImg">上传</span>
  118. </div>
  119. </div>
  120. <div class="tips-info">
  121. <span>文件最大2Mb,支持bmp/png/jpeg/jpg/gif格式</span>
  122. <div class="upload-img"><img src="" alt="" /><span>上传图片</span></div>
  123. </div>
  124. </div>
  125. <!-- 音乐 -->
  126. <div class="control-item control-main-music" :class="{show:type=='voice'}">
  127. <div class="form-group clearfix">
  128. <label class="col-sm-2 tips" for="">上传声音</label>
  129. <div class="col-sm-10 group-item">
  130. <input class="form-control" type="text" readonly placeholder="请上传音乐文件或输入音乐URL地址" v-model="dataGroup.voice.src"/>
  131. <span class="file-btn" @click="uploadMusic">上传</span>
  132. </div>
  133. </div>
  134. </div>
  135. </div>
  136. </div>
  137. <div style="text-align: center;"><button type="button" class="btn btn-w-m btn-primary" @click="submit">提交</button></div>
  138. </form>
  139. </section>
  140. </div>
  141. </div>
  142. </div>
  143. </div>
  144. </div>
  145. {/block}
  146. {block name="script"}
  147. <script type="text/javascript">
  148. $eb = parent._mpApi, $upload = $('#file');
  149. $eb.mpFrame.start(function (Vue) {
  150. var $http = $eb.axios;
  151. const vm = new Vue({
  152. data: {
  153. add:'',
  154. used_key:"",
  155. keyword:"",
  156. status: 1,
  157. msg: '新建关键字回复',
  158. type: 'text',
  159. textBox: '',
  160. pic: '',
  161. dataGroup:{
  162. text:{
  163. content:''
  164. },
  165. image:{
  166. src:''
  167. },
  168. voice:{
  169. src:''
  170. },
  171. news:[]
  172. },
  173. uploadColl: function () {
  174. },
  175. uploadLink: ''
  176. },
  177. methods: {
  178. transfer:function (str){
  179. var s = "";
  180. if (str.length === 0) { return "";}
  181. s = str.replace(/&amp;/g, "&");
  182. s = s.replace(/&lt;/g, "<");
  183. s = s.replace(/&gt;/g, ">");
  184. s = s.replace(/&nbsp;/g, " ");
  185. s = s.replace(/&#39;/g, "\'");
  186. s = s.replace(/&quot;/g, "\"");
  187. return s;
  188. },
  189. submit: function(){
  190. if(!this.check()) return false;
  191. window.vm = this;
  192. $eb.axios.post("{:Url('save_keyword',array('dis'=>$dis))}",{key:this.keyword,status:this.status,data:this.dataGroup[this.type],type:this.type}).then(function(res){
  193. if(res.status == 200 && res.data.code == 200){
  194. $eb.message('success','设置成功!');
  195. setTimeout(function () {
  196. window.history.go(-1);
  197. },800);
  198. }
  199. else
  200. $eb.message('error',res.data.msg || '设置失败!');
  201. }).catch(this.returnError);
  202. },
  203. check: function(){
  204. var dataGroup = this.dataGroup;
  205. if(this.keyword.trim() == '')
  206. return this.returnError('请输入关键字');
  207. if(this.keyword.trim() == 'subscribe')
  208. return this.returnError('请重新输入关键字');
  209. if(this.keyword.trim() == 'default')
  210. return this.returnError('请重新输入关键字');
  211. switch (this.type){
  212. case 'text':
  213. if(dataGroup.text.content == '')
  214. return this.returnError('请输入文字消息内容');
  215. break;
  216. case 'image':
  217. if(dataGroup.image.src == '')
  218. return this.returnError('请上传图片');
  219. break;
  220. case 'news':
  221. if(dataGroup.news.length < 1)
  222. return this.returnError('请选择图文消息');
  223. break;
  224. case 'voice':
  225. if(dataGroup.voice.src == '')
  226. return this.returnError('请上传声音');
  227. break;
  228. }
  229. return true;
  230. },
  231. returnError:function(err){
  232. $eb.message('error',err);
  233. return false;
  234. },
  235. uploadImg: function () {
  236. var vm = this;
  237. this.uploadLink = "{:Url('upload_img')}";
  238. $('#file').attr('accept','image/*');
  239. this.uploadColl = function(pic){
  240. vm.dataGroup.image.src = vm.transfer(pic);
  241. };
  242. $('#file').trigger('click');
  243. },
  244. uploadMusic:function(){
  245. var vm = this;
  246. this.uploadLink = "{:Url('upload_file')}";
  247. $('#file').attr('accept','audio/*');
  248. this.uploadColl = function(pic){
  249. vm.dataGroup.voice.src = pic;
  250. };
  251. $('#file').trigger('click');
  252. },
  253. upload: function () {
  254. var vm = this;
  255. $('#file').on('change', function () {
  256. $.ajaxFileUpload({
  257. url: vm.uploadLink,
  258. type: 'post',
  259. secureuri: false, //一般设置为false
  260. data:{'file':'file'},
  261. fileElementId: 'file', // 上传文件的id、name属性名
  262. dataType: 'json', //返回值类型,一般设置为json、application/json
  263. success: function (data, status) {
  264. if(data.code == 200){
  265. vm.uploadColl && vm.uploadColl(data.data);
  266. $eb.message('success','上传成功!');
  267. }else{
  268. $eb.message('error',data.msg);
  269. }
  270. vm.upload();
  271. },
  272. error: function (data, status, e) {
  273. $eb.message('success','上传失败!');
  274. vm.upload();
  275. }
  276. });
  277. });
  278. },
  279. selectNews:function(){
  280. var vm = this,i;
  281. parent._selectNews$eb = function(data){
  282. var newsList = [];
  283. data.new.map(function(news){
  284. newsList.push({
  285. title:news.title,
  286. description:news.synopsis,
  287. url:news.url,
  288. image:news.image_input,
  289. date:moment(news.add_time*1000).format('M月D日'),
  290. id:news.id
  291. });
  292. });
  293. vm.dataGroup.news = newsList;
  294. delete parent._selectNews$eb;
  295. $eb.closeModalFrame(i);
  296. };
  297. i = $eb.createModalFrame('选择图文消息',"{:Url('admin/wechat.wechatNewsCategory/select',['callback'=>'_selectNews$eb','type'=>1])}",{w:975});
  298. }
  299. },
  300. mounted: function () {
  301. window.vm = this;
  302. this.used_key = "{$key}";
  303. this.upload();
  304. var res= <?php echo json_encode($replay_arr); ?>;
  305. if(res.id > 0){
  306. window.vm.type = res.type;
  307. window.vm.status = res.status;
  308. if(res.type == 'image') {
  309. window.vm.dataGroup.image.src = res.data.src;
  310. }else if(res.type == 'text'){
  311. window.vm.dataGroup.text.content = res.data.content;
  312. }else if(res.type == 'voice'){
  313. window.vm.dataGroup.voice.src = res.data.src;
  314. }else if(res.type == 'news'){
  315. window.vm.dataGroup.news = res.data;
  316. }
  317. if(window.vm.used_key){
  318. window.vm.keyword = res.key;
  319. }
  320. }
  321. }
  322. });
  323. vm.$mount(document.getElementById('app'));
  324. });
  325. </script>
  326. {/block}