人人商城

service-post.html 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. {template 'common/header-gw'}
  2. {template 'extension/service-tabs'}
  3. <style type="text/css">
  4. .help-block em{display:inline-block;width:10em;font-weight:bold;font-style:normal;}
  5. .panel>.list-group .list-group-item {margin-left:0px; margin-right:0;}
  6. </style>
  7. <script>
  8. require(['angular.sanitize', 'bootstrap', 'underscore', 'util'], function(angular, $, _, util){
  9. angular.module('app', ['ngSanitize']).controller('replyForm', function($scope, $http){
  10. $scope.reply = {
  11. advSetting: false,
  12. advTrigger: false,
  13. entry: {php echo json_encode($reply)}
  14. };
  15. $scope.trigger = {};
  16. $scope.trigger.descriptions = {};
  17. $scope.trigger.descriptions.contains = '用户进行交谈时,对话中包含上述关键字就执行这条规则。';
  18. $scope.trigger.descriptions.regexp = '用户进行交谈时,对话内容符合述关键字中定义的模式才会执行这条规则。<br/><strong>注意:如果你不明白正则表达式的工作方式,请不要使用正则匹配</strong> <br/><strong>注意:正则匹配使用MySQL的匹配引擎,请使用MySQL的正则语法</strong> <br /><strong>示例: </strong><br/><em>^微信</em>匹配以“微信”开头的语句<br /><em>微信$</em>匹配以“微信”结尾的语句<br /><em>^微信$</em>匹配等同“微信”的语句<br /><em>微信</em>匹配包含“微信”的语句<br /><em>[0-9\.\-]</em>匹配所有的数字,句号和减号<br /><em>^[a-zA-Z_]$</em>所有的字母和下划线<br /><em>^[[:alpha:]]{3}$</em>所有的3个字母的单词<br /><em>^a{4}$</em>aaaa<br /><em>^a{2,4}$</em>aa,aaa或aaaa<br /><em>^a{2,}$</em>匹配多于两个a的字符串';
  19. $scope.trigger.descriptions.trustee = '如果没有比这条回复优先级更高的回复被触发,那么直接使用这条回复。<br/><strong>注意:如果你不明白这个机制的工作方式,请不要使用直接接管</strong>';
  20. $scope.trigger.labels = {};
  21. $scope.trigger.labels.contains = '包含关键字';
  22. $scope.trigger.labels.regexp = '正则表达式模式';
  23. $scope.trigger.labels.trustee = '直接接管操作';
  24. $scope.trigger.active = 'contains';
  25. $scope.trigger.items = {};
  26. $scope.trigger.items.default = '';
  27. $scope.trigger.items.contains = [];
  28. $scope.trigger.items.regexp = [];
  29. $scope.trigger.items.trustee = [];
  30. if($scope.reply.entry) {
  31. $scope.reply.entry.istop = $scope.reply.entry.displayorder >= 255;
  32. $scope.reply.advSetting = $scope.reply.entry.displayorder!=0 || !$scope.reply.entry.status;
  33. if($scope.reply.entry.keywords) {
  34. angular.forEach($scope.reply.entry.keywords, function(v, k){
  35. if(v.type == '1') {
  36. this.default += (v.content + ',');
  37. }
  38. if(v.type == '2') {
  39. this.contains.push({content: v.content, label: '请输入' + $scope.trigger.labels.contains, saved: true});
  40. }
  41. if(v.type == '3') {
  42. this.regexp.push({content: v.content, label: '请输入' + $scope.trigger.labels.regexp, saved: true});
  43. }
  44. if(v.type == '4') {
  45. this.trustee.push({});
  46. }
  47. }, $scope.trigger.items);
  48. if($scope.trigger.items.default.length > 1) {
  49. $scope.trigger.items.default = $scope.trigger.items.default.slice(0, $scope.trigger.items.default.length - 1);
  50. }
  51. if($scope.trigger.items.contains.length > 0 || $scope.trigger.items.regexp.length > 0 || $scope.trigger.items.trustee.length > 0) {
  52. $scope.reply.advTrigger = true;
  53. }
  54. if($scope.trigger.items.contains.length > 0) {
  55. $('a[data-toggle="tab"]').eq(0).tab('show');
  56. $scope.trigger.active = 'contains';
  57. } else if($scope.trigger.items.regexp.length > 0) {
  58. $('a[data-toggle="tab"]').eq(1).tab('show');
  59. $scope.trigger.active = 'regexp';
  60. } else if($scope.trigger.items.trustee.length > 0) {
  61. $('a[data-toggle="tab"]').eq(2).tab('show');
  62. $scope.trigger.active = 'trustee';
  63. }
  64. }
  65. }
  66. $scope.trigger.addItem = function(){
  67. var type = $scope.trigger.active;
  68. if(type != 'trustee') {
  69. $scope.trigger.items[type].push({content: '', label: '请输入' + $scope.trigger.labels[type], saved: false});
  70. } else {
  71. if($scope.trigger.items.trustee.length == 0) {
  72. $scope.trigger.items.trustee.push({});
  73. }
  74. }
  75. };
  76. $scope.trigger.saveItem = function(item){
  77. item.saved = !item.saved;
  78. };
  79. $scope.trigger.removeItem = function(item) {
  80. var type = $scope.trigger.active;
  81. $scope.trigger.items[type] = _.without($scope.trigger.items[type], item);
  82. $scope.$digest();
  83. }
  84. if($.isFunction(window.initReplyController)) {
  85. window.initReplyController($scope, $http);
  86. }
  87. $('#reply-form').submit(function(){
  88. if($.trim($(':text[name="name"]').val()) == '') {
  89. util.message('必须输入回复规则名称');
  90. return false;
  91. }
  92. var val = [];
  93. $scope.$digest();
  94. if($scope.trigger.items.default != '') {
  95. var kws = $scope.trigger.items.default.split(',');
  96. kws = _.union(kws);
  97. angular.forEach(kws, function(v){
  98. if(v != '') {
  99. val.push({type: 1, content: v});
  100. }
  101. }, val);
  102. }
  103. angular.forEach($scope.trigger.items, function(v, name){
  104. if(name != 'default' && v.length > 0) {
  105. angular.forEach(v, function(value){
  106. var o = {};
  107. switch(name) {
  108. case 'contains':
  109. o.type = 2;
  110. break;
  111. case 'regexp':
  112. o.type = 3;
  113. break;
  114. case 'trustee':
  115. o.type = 4;
  116. break;
  117. }
  118. if(name != 'trustee') {
  119. o.content = value.content;
  120. }
  121. this.push(o);
  122. }, val);
  123. }
  124. }, val);
  125. if(val.length == 0) {
  126. util.message('请输入有效的触发关键字.');
  127. return false;
  128. }
  129. $scope.$digest();
  130. val = angular.toJson(val);
  131. $(':hidden[name=keywords]').val(val);
  132. if($.isFunction(window.validateReplyForm)) {
  133. return window.validateReplyForm(this, $, _, util, $scope, $http);
  134. }
  135. return false;
  136. });
  137. $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
  138. $scope.trigger.active = e.target.hash.replace(/#/, '');
  139. $scope.$digest();
  140. })
  141. }).filter('nl2br', function($sce){
  142. return function(text) {
  143. return text ? $sce.trustAsHtml(text.replace(/\n/g, '<br/>')) : '';
  144. };
  145. }).directive('ngInvoker', function($parse){
  146. return function (scope, element, attr) {
  147. scope.$eval(attr.ngInvoker);
  148. };
  149. });
  150. angular.bootstrap(document, ['app']);
  151. });
  152. </script>
  153. <div class="clearfix ng-cloak" ng-controller="replyForm">
  154. <form id="reply-form" class="form-horizontal form" action="{php echo url('extension/service/post', array('m' => $m, 'rid' => $rid))}" method="post" enctype="multipart/form-data">
  155. <div class="page-header">
  156. <h4>{if empty($rid)}添加{else}修改{/if}常用服务 <small>服务是最常用的一类回复, 如天气预报, 笑话, 百科, 翻译等简单功能</small></h4>
  157. </div>
  158. <div class="form-group">
  159. <label class="col-xs-12 col-sm-2 col-md-2 col-lg-2 control-label">服务名称</label>
  160. <div class="col-sm-8 col-lg-8 col-xs-12">
  161. <input type="text" class="form-control" placeholder="请输入服务名称" name="name" value="{if empty($reply['name']) && !empty($_GPC['name'])}{$_GPC['name']}{else}{$reply['name']}{/if}" />
  162. <span class="help-block">
  163. <strong>选择高级设置: 将会提供一系列的高级选项供专业用户使用.</strong>
  164. </span>
  165. </div>
  166. <div class="col-sm-2 col-lg-2">
  167. <div class="checkbox">
  168. <label>
  169. <input type="checkbox" ng-model="reply.advSetting" /> 高级设置
  170. </label>
  171. </div>
  172. </div>
  173. </div>
  174. <div class="form-group" ng-show="reply.advSetting">
  175. <label class="col-xs-12 col-sm-2 col-md-2 col-lg-2 control-label">状态</label>
  176. <div class="col-sm-8 col-lg-8">
  177. <label class="radio-inline">
  178. <input type="radio" name="status" value="1" {if $reply['status'] == 1 || empty($reply['status'])} checked="checked"{/if} /> 启用
  179. </label>
  180. <label class="radio-inline">
  181. <input type="radio" name="status" value="0" {if !empty($reply) && $reply['status'] == 0} checked="checked"{/if} /> 禁用
  182. </label>
  183. <span class="help-block">您可以临时禁用这条回复.</span>
  184. </div>
  185. </div>
  186. <div class="form-group" ng-show="reply.advSetting">
  187. <label class="col-xs-12 col-sm-2 col-md-2 col-lg-2 control-label">置顶回复</label>
  188. <div class="col-sm-8 col-lg-8">
  189. <label class="radio-inline">
  190. <input type="radio" name="istop" ng-model="reply.entry.istop" ng-value="true" value="1" {if !empty($reply['displayorder']) && $reply['displayorder'] == 255} checked="checked"{/if} /> 置顶
  191. </label>
  192. <label class="radio-inline">
  193. <input type="radio" name="istop" ng-model="reply.entry.istop" ng-value="false" value="0" {if $reply['displayorder'] < 255} checked="checked"{/if} /> 普通
  194. </label>
  195. <span class="help-block">“置顶”时无论在什么情况下均能触发且使终保持最优先级</span>
  196. </div>
  197. </div>
  198. <div class="form-group" ng-show="reply.advSetting && !reply.entry.istop">
  199. <label class="col-xs-12 col-sm-2 col-md-2 col-lg-2 control-label">优先级</label>
  200. <div class="col-sm-8 col-lg-8">
  201. <input type="text" class="form-control" placeholder="输入这条回复规则优先级" name="displayorder" value="{$reply['displayorder']}">
  202. <span class="help-block">规则优先级,越大则越靠前,最大不得超过254</span>
  203. </div>
  204. </div>
  205. <div class="form-group">
  206. <label class="col-xs-12 col-sm-2 col-md-2 col-lg-2 control-label">功能介绍</label>
  207. <div class="col-sm-8 col-lg-8 col-xs-12">
  208. <input type="text" class="form-control" placeholder="请输入功能介绍" name="description" value="{$reply['description']}" />
  209. </div>
  210. </div>
  211. <div class="form-group">
  212. <label class="col-xs-12 col-sm-2 col-md-2 col-lg-2 control-label">触发关键字</label>
  213. <div class="col-sm-8 col-lg-8 col-xs-12">
  214. <input type="text" class="form-control" placeholder="请输入触发关键字" ng-model="trigger.items.default" />
  215. <input type="hidden" name="keywords"/>
  216. <span class="help-block">
  217. 当用户的对话内容符合以上的关键字定义时,会触发这个回复定义。多个关键字请使用逗号隔开. <br />
  218. <strong>选择高级触发: 将会提供一系列的高级触发方式供专业用户使用(注意: 如果你不了解, 请不要使用). </strong>
  219. </span>
  220. </div>
  221. <div class="col-sm-2 col-lg-2">
  222. <div class="checkbox">
  223. <label>
  224. <input type="checkbox" ng-model="reply.advTrigger" /> 高级触发
  225. </label>
  226. </div>
  227. </div>
  228. </div>
  229. <div class="form-group" ng-show="reply.advTrigger">
  230. <label class="col-xs-12 col-sm-2 col-md-2 col-lg-2 control-label">高级触发列表</label>
  231. <div class="col-sm-8 col-lg-8">
  232. <div class="panel panel-default tab-content">
  233. <div class="panel-heading">
  234. <ul class="nav nav-pills">
  235. <li class="active"><a href="#contains" data-toggle="tab">包含关键字</a></li>
  236. <li><a href="#regexp" data-toggle="tab">正则表达式模式匹配</a></li>
  237. <li><a href="#trustee" data-toggle="tab">直接接管</a></li>
  238. </ul>
  239. </div>
  240. <ul class="tab-pane list-group active" id="contains">
  241. <li class="list-group-item row" ng-repeat="entry in trigger.items.contains">
  242. <div class="col-xs-12 col-sm-8">
  243. <input type="text" class="form-control" ng-hide="entry.saved" placeholder="{{entry.label}}" ng-model="entry.content" />
  244. <p class="form-control-static" ng-show="entry.saved" ng-bind="entry.content"></p>
  245. </div>
  246. <div class="col-sm-4">
  247. <div class="btn-group">
  248. <a href="javascript:;" class="btn btn-default" ng-click="trigger.saveItem(entry);">{{entry.saved ? '编辑' : '保存'}}</a>
  249. <a href="javascript:;" class="btn btn-default" ng-click="trigger.removeItem(entry);">删除</a>
  250. </div>
  251. </div>
  252. </li>
  253. </ul>
  254. <ul class="tab-pane list-group" id="regexp">
  255. <li class="list-group-item row" ng-repeat="entry in trigger.items.regexp">
  256. <div class="col-xs-12 col-sm-8">
  257. <input type="text" class="form-control" ng-hide="entry.saved" placeholder="{{entry.label}}" ng-model="entry.content" />
  258. <p class="form-control-static" ng-show="entry.saved" ng-bind="entry.content"></p>
  259. </div>
  260. <div class="col-sm-4">
  261. <div class="btn-group">
  262. <a href="javascript:;" class="btn btn-default" ng-click="trigger.saveItem(entry);">{{entry.saved ? '编辑' : '保存'}}</a>
  263. <a href="javascript:;" class="btn btn-default" ng-click="trigger.removeItem(entry);">删除</a>
  264. </div>
  265. </div>
  266. </li>
  267. </ul>
  268. <ul class="tab-pane list-group" id="trustee">
  269. <li class="list-group-item row" ng-repeat="entry in trigger.items.trustee">
  270. <div class="col-xs-12 col-sm-8">
  271. <p class="form-control-static">符合优先级条件时, 这条回复将直接生效</p>
  272. </div>
  273. <div class="col-sm-4">
  274. <a href="javascript:;" class="btn btn-default" ng-click="trigger.removeItem(entry);">取消接管</a>
  275. </div>
  276. </li>
  277. </ul>
  278. <div class="panel-footer">
  279. <a href="javascript:;" class="btn btn-default" ng-click="trigger.addItem();" ng-bind="'添加' + trigger.labels[trigger.active]">添加</a>
  280. <span class="help-block" ng-bind-html="trigger.descriptions[trigger.active]"></span>
  281. </div>
  282. </div>
  283. </div>
  284. </div>
  285. <div class="form-group">
  286. <label class="col-xs-12 col-sm-2 col-md-2 col-lg-2 control-label">回复内容</label>
  287. <div class="col-sm-8 col-lg-8 col-xs-12">
  288. {php echo module_build_form($m, $rid);}
  289. </div>
  290. </div>
  291. <div class="form-group">
  292. <div class="col-sm-offset-2 col-md-offset-2 col-lg-offset-2 col-xs-12 col-sm-10 col-md-10 col-lg-10">
  293. <input name="submit" type="submit" value="提交" class="btn btn-primary" />
  294. <input type="hidden" name="token" value="{$_W['token']}" />
  295. </div>
  296. </div>
  297. </form>
  298. </div>
  299. {template 'common/footer-gw'}