BehaviorInfo.cshtml 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502
  1. @using WePlatform.Configuration
  2. @using WePlatform.Authorization
  3. @using WePlatform.Views.Shared.Modals
  4. @using WePlatform.Views.Shared.SearchForm
  5. @using WePlatform.Views.Shared.Table
  6. @{
  7. ViewBag.Title = "行为规则库管理";
  8. string activeMenu = PermissionNames.PagesResourceMgBehaviorMg; //The menu item will be active for this page.
  9. string category = ViewBag.Category, role = ViewBag.Role, knowledge = ViewBag.Knowledge, environment = ViewBag.Environment;
  10. ViewBag.ActiveMenu = activeMenu;
  11. var searchForm = new SearchFormViewModel(new List<SearchItem>()
  12. {
  13. new SearchItem("behaviorName","行为名称"),
  14. //new SearchItem("sceneCategory","场景类别").SetSelectItem(category,isTree:true)
  15. });
  16. var table = new TableViewModel(IwbConsts.ApiAppUrl + "Behavior/GetAll", activeMenu, searchForm)
  17. .SetFields(new List<FieldItem>()
  18. {
  19. new FieldItem("id", "编码"),
  20. new FieldItem("behaviorName", "行为名称"),
  21. new FieldItem("sceneCategoryName", "类别名称",isSort:false),
  22. new FieldItem("behaviorTag", "行为标签"),
  23. new FieldItem("behaviorRoleNames", "角色名称",isSort:false),
  24. new FieldItem("ruleKeyword", "行为关键字"),
  25. });
  26. }
  27. @section css{
  28. <link href="~/Content/Libs/jstree/themes/proton/style.min.css" rel="stylesheet" />
  29. }
  30. <div class="row">
  31. <div class="col-sm-3">
  32. <div class="iwb-tree-box">
  33. <div class="box-header">场景类别</div>
  34. <div class="scroll box-body">
  35. <div id="sc-tree"></div>
  36. </div>
  37. </div>
  38. </div>
  39. <div class="col-sm-9">
  40. @Html.Partial("Table/_Table", table)
  41. </div>
  42. </div>
  43. @section modal{
  44. @{
  45. var baseInput = new ModalBodyViewModel(new List<Input>()
  46. {
  47. new InputHide("id"),
  48. new Input("behaviorName", "行为名称"),
  49. new Input("sceneCategory", "场景类别").SetSelectOptions(category),
  50. //new Input("sceneCategory", "场景类别").SetSelectOptions(category,isAddBlank:false),
  51. new Input("behaviorTag", "行为标签").SetNotRequired(),
  52. new InputTextarea("description", "行为规则"),
  53. //new Input("ruleKeyword", "行为关键字").SetNotRequired(),
  54. });
  55. }
  56. <!--Main Modal-->
  57. <section>
  58. <div class="modal fade show" id="modal" tabindex="-1" aria-modal="true">
  59. <div class="modal-dialog modal-lg" style="margin-top: 190.5px;">
  60. <div class="modal-content">
  61. @Html.Partial("Modals/_ModalHeader", new ModalHeaderViewModel("行为"))
  62. <div class="modal-body" style="padding: 0">
  63. <form class="form-horizontal " id="form" novalidate="novalidate" style="padding: 0">
  64. <div class="card card-primary card-outline card-outline-tabs" style="margin-bottom: 0; border-top: 0; ">
  65. <div class="card-header p-0 border-bottom-0">
  66. <ul class="nav nav-tabs" id="behavior-tab" role="tablist">
  67. <li class="nav-item">
  68. <a class="nav-link active" id="tab-base" data-toggle="pill" href="#tab-content-base" role="tab">基础信息</a>
  69. </li>
  70. <li class="nav-item">
  71. <a class="nav-link" data-toggle="pill" href="#tab-content-keyword" role="tab">行为关键字</a>
  72. </li>
  73. <li class="nav-item">
  74. <a class="nav-link" data-toggle="pill" href="#tab-content-role" role="tab">行为角色</a>
  75. </li>
  76. <li class="nav-item">
  77. <a class="nav-link" data-toggle="pill" href="#tab-content-knowledge" role="tab">行为知识</a>
  78. </li>
  79. <li class="nav-item">
  80. <a class="nav-link" data-toggle="pill" href="#tab-content-environment" role="tab">行为资源</a>
  81. </li>
  82. </ul>
  83. </div>
  84. <div class="card-body">
  85. <div class="tab-content" id="custom-tabs-four-tabContent">
  86. <div class="tab-pane fade show active" id="tab-content-base" role="tabpanel">
  87. @Html.Partial("Modals/_ModalInput", baseInput)
  88. </div>
  89. <div class="tab-pane fade" id="tab-content-role" role="tabpanel">
  90. <div class="form-group row">
  91. <label class=" iwb-label iwb-label-sm iwb-label-required" for="sceneCategoryEx">场景类别</label>
  92. <div class="">
  93. <div class="input-group input-group-sm">
  94. <select class="form-control required" id="sceneCategoryEx" name="sceneCategoryEx" placeholder="请选择场景类别..." style="width: 100%">@(Html.Raw(category))</select>
  95. </div>
  96. </div>
  97. </div>
  98. <div class="dynamic-box" style="margin: 0 10px;">
  99. <div class="row iwb-dynamic-box">
  100. <div class="dynamic-label col-sm-10">
  101. <label class="iwb-label">角色名称</label>
  102. </div>
  103. <div class="dynamic-control col-sm-2">
  104. <label class="iwb-label">增加/删除</label>
  105. </div>
  106. </div>
  107. <div class="row iwb-dynamic-box">
  108. <div class="col-sm-10">
  109. <div class="input-group input-group-sm">
  110. <select class="form-control" name="behaviorRoleNo" style="width: 100%">
  111. @(Html.Raw(role))
  112. </select>
  113. </div>
  114. </div>
  115. <div class="col-sm-2">
  116. <button class="btn btn-sm btn-block btn-add" type="button" onclick="AddDynamicBox(this)">增加</button>
  117. </div>
  118. </div>
  119. </div>
  120. </div>
  121. <div class="tab-pane fade" id="tab-content-keyword" role="tabpanel">
  122. <div class="dynamic-box">
  123. <div class="row iwb-dynamic-box">
  124. <div class="dynamic-label col-sm-7">
  125. <label class="iwb-label">关键字<small>(多个以,分隔)</small></label>
  126. </div>
  127. <div class="dynamic-label col-sm-3">
  128. <label class="iwb-label">权重</label>
  129. </div>
  130. <div class="dynamic-control col-sm-2">
  131. <label class="iwb-label">增加/删除</label>
  132. </div>
  133. </div>
  134. <div class="row iwb-dynamic-box keywords">
  135. <div class="col-sm-7">
  136. <div class="input-group input-group-sm">
  137. <input class="form-control required" name="keyword" onchange="KeyWordChange(this)" placeholder="请输入关键字" style="width: 100%" />
  138. </div>
  139. </div>
  140. <div class="col-sm-3">
  141. <div class="input-group input-group-sm">
  142. <input class="form-control number required" type="number" min="0" max="100" name="weight" placeholder="请输入关键字的权重" style="width: 100%" />
  143. </div>
  144. </div>
  145. <div class="col-sm-2">
  146. <button class="btn btn-sm btn-block btn-add" type="button" onclick="AddDynamicBox(this)">增加</button>
  147. </div>
  148. </div>
  149. </div>
  150. </div>
  151. <div class="tab-pane fade" id="tab-content-knowledge" role="tabpanel">
  152. <div class="dynamic-box" style="margin: 0 10px;">
  153. <div class="row iwb-dynamic-box">
  154. <div class="dynamic-label col-sm-10">
  155. <label class="iwb-label">知识信息</label>
  156. </div>
  157. <div class="dynamic-control col-sm-2">
  158. <label class="iwb-label">增加/删除</label>
  159. </div>
  160. </div>
  161. <div class="row iwb-dynamic-box">
  162. <div class="col-sm-10">
  163. <div class="input-group input-group-sm">
  164. <select class="form-control" name="knowledgeNo" style="width: 100%">
  165. @(Html.Raw(knowledge))
  166. </select>
  167. </div>
  168. </div>
  169. <div class="col-sm-2">
  170. <button class="btn btn-sm btn-block btn-add" type="button" onclick="AddDynamicBox(this)">增加</button>
  171. </div>
  172. </div>
  173. </div>
  174. </div>
  175. <div class="tab-pane fade" id="tab-content-environment" role="tabpanel">
  176. <div class="dynamic-box">
  177. <div class="row iwb-dynamic-box">
  178. <div class="dynamic-label col-sm-10">
  179. <label class="iwb-label">环境资源</label>
  180. </div>
  181. <div class="dynamic-control col-sm-2">
  182. <label class="iwb-label">增加/删除</label>
  183. </div>
  184. </div>
  185. <div class="row iwb-dynamic-box ">
  186. <div class="col-sm-10">
  187. <div class="input-group input-group-sm">
  188. <select class="form-control" name="environment" style="width: 100%">
  189. @(Html.Raw(environment))
  190. </select>
  191. </div>
  192. </div>
  193. <div class="col-sm-2">
  194. <button class="btn btn-sm btn-block btn-add" type="button" onclick="AddDynamicBox(this)">增加</button>
  195. </div>
  196. </div>
  197. </div>
  198. </div>
  199. </div>
  200. </div>
  201. </div>
  202. </form>
  203. </div>
  204. @Html.Partial("Modals/_ModalFooter", "0")
  205. </div>
  206. </div>
  207. </div>
  208. </section>
  209. }
  210. <div class="col-12 col-sm-6">
  211. </div>
  212. @section scripts
  213. {
  214. <script src="~/Content/Libs/select2/js/select2.js"></script>
  215. <script src="~/Content/Libs/jstree/jstree.min.js"></script>
  216. <script type="text/javascript">
  217. var $table, cuScNo = '';
  218. $(function () {
  219. OverlayScrollbar($('.scroll'));
  220. InitScTree();
  221. //根据场景类别拉去场景角色
  222. $('#modal #sceneCategory').on('change.reBehavior', function () {
  223. $('#modal #sceneCategoryEx').val($(this).val()).select2tree();
  224. $('#modal #sceneCategoryEx').trigger("change");
  225. });
  226. $('#modal #sceneCategoryEx').on('change.reRole', function () {
  227. $('#modal #tab-content-role .iwb-dynamic-box-delete').remove();
  228. var no = $(this).val(), $role = $('#modal #tab-content-role .iwb-dynamic-box').eq(1).find('.form-control[name="behaviorRoleNo"]');
  229. $('#modal #sceneCategory').val(no).select2tree();
  230. if (no) {
  231. $.iwbAjax4({
  232. url: abp.appUrl + "query/GetBehaviorRoleSelectStrByCategory?no=" + no,
  233. async: false,
  234. success: function (res) {
  235. $role.html(res).select2();
  236. }
  237. });
  238. } else {
  239. $role.html('<option value="" selected>请选择行为角色...</option>').select2();
  240. }
  241. });
  242. $table = LoadTable({
  243. searchFun: TableSearchFun
  244. });
  245. var funs = window.iwbfuns || { none: function () { console.log("No type"); } };
  246. funs["btnCreate"] = function (url) {
  247. Reset();
  248. BtnCreate({
  249. url: url,
  250. dataFun: GetBehaviorData,
  251. data: { id: "", sceneCategory: "" },
  252. select2tree: "sceneCategory,sceneCategoryEx"
  253. });
  254. }
  255. funs["btnUpdate"] = function (url) {
  256. var row = $table.bootstrapTable("getSelections")[0];
  257. if (row) {
  258. Reset();
  259. row.sceneCategoryEx = row.sceneCategory;
  260. BtnUpdate({
  261. url: url,
  262. dataFun: GetBehaviorData,
  263. disabled: "",
  264. select2tree: "sceneCategory,sceneCategoryEx",
  265. shownAfter: function () {
  266. $('#modal #sceneCategoryEx').trigger("change");
  267. ParseRoles(row.behaviorRoleNos);
  268. ParseKnowledges(row.knowledgeNos);
  269. ParseKeywords(row.keywords);
  270. }
  271. }, row);
  272. }
  273. };
  274. });
  275. function KeyWordChange(that) {
  276. var word = $(that).val();
  277. var reg = /[`~!@@#$%^&*()_\-+=<>?:"{}|.\/;'\\\[\]·~!@@#¥%……&*()——\-+={}|《》?:“”【】、;‘',。、]/im;
  278. if (reg.test(word)) {
  279. abp.message.warn("关键字不能有特殊字符!");
  280. $(that).val('');
  281. }
  282. }
  283. function InitScTree() {
  284. $('#sc-tree')
  285. .jstree({
  286. 'core': {
  287. 'data': GetNode,
  288. 'strings': {
  289. 'Loading ...': '请稍后...'
  290. },
  291. 'force_text': true,
  292. 'check_callback': true,
  293. 'themes': {
  294. 'name': 'proton',
  295. 'responsive': true,
  296. 'variant': 'large'
  297. }
  298. },
  299. 'plugins': ['wholerow'] // 'state',
  300. }).on('ready.jstree',function(e, data) {
  301. //console.log('000', e, data);
  302. var inst = data.instance,
  303. obj = inst.get_node('@(IwbConsts.SceneCategoryRootNo)');
  304. inst.open_node(obj);
  305. inst.select_node(obj);
  306. cuScNo = '';
  307. RefreshTable();
  308. }).on('activate_node.jstree',function(e, data) {
  309. //console.log('111',data);
  310. cuScNo = data.node.id == '@(IwbConsts.SceneCategoryRootNo)' ? "" : data.node.id;
  311. RefreshTable();
  312. });
  313. }
  314. function GetNode(node, callback) {
  315. $.iwbAjax4({
  316. url: abp.appUrl + 'Query/GetChildSceneCategory',
  317. data: { id: node.id },
  318. success: function(res) {
  319. if (callback) {
  320. callback.call(this, res);
  321. } else {
  322. $("#sc-tree").html("暂无数据!");
  323. }
  324. }
  325. });
  326. }
  327. function TableSearchFun(sl) {
  328. sl.push({
  329. KeyWords: cuScNo,
  330. KeyField: 'sceneCategory',
  331. FieldType: '0',
  332. ExpType: '0'
  333. });
  334. }
  335. </script>
  336. <script>
  337. //自定义获取提交数据
  338. function GetBehaviorData() {
  339. var data = $.formSerialize($('#modal form'));
  340. data.ruleKeyword = FormatterKeyword();
  341. var roles = [], knowledges = [], environments = [];
  342. $('#modal #tab-content-role .iwb-dynamic-box').find('.form-control[name="behaviorRoleNo"]').each(
  343. function () {
  344. var v = $(this).val();
  345. if (v && roles.indexOf(v) == -1) {
  346. roles.push(v);
  347. }
  348. });
  349. $('#modal #tab-content-knowledge .iwb-dynamic-box').find('.form-control[name="knowledgeNo"]').each(
  350. function () {
  351. var v = $(this).val();
  352. if (v && knowledges.indexOf(v) == -1) {
  353. knowledges.push(v);
  354. }
  355. });
  356. $('#modal #tab-content-environment .iwb-dynamic-box').find('.form-control[name="environment"]').each(
  357. function () {
  358. if ($(this).val()) {
  359. environments.push($(this).val());
  360. }
  361. });
  362. data.behaviorRoleNos = roles;
  363. data.knowledgeNos = knowledges;
  364. data.environResourceNos = environments;
  365. data.keyword = "";
  366. data.weight = "";
  367. console.log(data);
  368. return data;
  369. }
  370. //解析知识角色
  371. function ParseRoles(nos) {
  372. if (!nos) {
  373. return;
  374. }
  375. var noArr = nos.split(",");
  376. for (var i = 0; i < noArr.length; i++) {
  377. var no = noArr[i];
  378. var $that = i === 0 ? $('#modal #tab-content-role .iwb-dynamic-box').eq(1) : AddDynamicBox($('#modal #tab-content-role .iwb-dynamic-box').eq(1).find('.btn-add'));
  379. $that.find('.form-control[name="behaviorRoleNo"]').val(no).select2();
  380. }
  381. }
  382. //解析知识信息
  383. function ParseKnowledges(nos) {
  384. if (!nos) {
  385. return;
  386. }
  387. var noArr = nos;//.split(",");
  388. for (var i = 0; i < noArr.length; i++) {
  389. var no = noArr[i];
  390. var $that = i === 0 ? $('#modal #tab-content-knowledge .iwb-dynamic-box').eq(1) : AddDynamicBox($('#modal #tab-content-knowledge .iwb-dynamic-box').eq(1).find('.btn-add'));
  391. $that.find('.form-control[name="knowledgeNo"]').val(no).select2();
  392. }
  393. }
  394. //解析环境资源
  395. function ParseEnvironments(nos) {
  396. if (!nos || nos.length <= 0) {
  397. return;
  398. }
  399. var noArr = nos;//.split(",");
  400. for (var i = 0; i < noArr.length; i++) {
  401. var no = noArr[i];
  402. var $that = i === 0 ? $('#modal #tab-content-environment .iwb-dynamic-box').eq(1) : AddDynamicBox($('#modal #tab-content-environment .iwb-dynamic-box').eq(1).find('.btn-add'));
  403. $that.find('.form-control[name="environment"]').val(no).select2();
  404. }
  405. }
  406. function ParseKeywords(words) {
  407. if (!words || words.length <= 0) {
  408. return;
  409. }
  410. console.log(words);
  411. for (var i = 0; i < words.length; i++) {
  412. var keywords = words[i];
  413. var $that = i === 0 ? $('#modal #tab-content-keyword .iwb-dynamic-box').eq(1) : AddDynamicBox($('#modal #tab-content-keyword .iwb-dynamic-box').eq(1).find('.btn-add'));
  414. $that.find('.form-control[name="keyword"]').val(keywords.keyword);
  415. $that.find('.form-control[name="weight"]').val(keywords.weight);
  416. }
  417. }
  418. //格式化关键字
  419. function FormatterKeyword() {
  420. var str = "";
  421. $('#tab-content-keyword .keywords').each(function () {
  422. var $that = $(this);
  423. var word = $that.find('input[name="keyword"]').val();
  424. //var reg = /[`~!@@#$%^&*()_\-+=<>?:"{}|,.\/;'\\\[\]·~!@@#¥%……&*()——\-+={}|《》?:“”【】、;‘',。、]/im;
  425. //if (reg.test(word)) {
  426. //}
  427. var weight = $that.find('input[name="weight"]').val();
  428. if (word && weight) {
  429. str += (str === "" ? "" : ",") + "[" + word + "]:" + weight;
  430. }
  431. });
  432. return "[" + str + "]";
  433. }
  434. //复位modal
  435. function Reset() {
  436. $('#modal .iwb-dynamic-box-delete').remove();
  437. $('#behavior-tab li').eq(0).find('a').tab('show');
  438. }
  439. </script>
  440. <!--格式化-->
  441. <script id="formatter-script" type="text/javascript">
  442. function TypeFormatter(v) {
  443. var name = $('#hid-type option[value="' + v + '"]').text();
  444. switch (v) {
  445. case 0:
  446. return '<span class="label label-danger">' + name + '</span>';
  447. default:
  448. return '<span class="label label-info">' + name + '</span>';
  449. }
  450. }
  451. </script>
  452. }
  453. <section style="display: none">
  454. <select id="hid-type">
  455. <option value=""></option>
  456. </select>
  457. @*@Html.DropDownList("hid-type", type)*@
  458. </section>