ciyunindex.html 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Access-Control-Allow-Origin" content="*">
  5. <meta charset="utf-8" />
  6. <title>词云</title>
  7. <link rel="stylesheet" href="./layui/css/layui.css">
  8. <script src="./js/jquery-1.11.3.js"></script>
  9. <script type="text/javascript" src="./js/saveSvgAsPng.js"></script>
  10. <script type="text/javascript" src="./layer/layer.js"></script>
  11. <script type="text/javascript" src="./layui/layui.js"></script>
  12. <link rel="stylesheet" href="./css/common.css">
  13. <link rel="stylesheet" href="./css/jiaocai.css">
  14. <script src="../config.js"></script>
  15. <style type="text/css">
  16. #stop:hover {
  17. text-decoration: underline;
  18. color: #FF0000;
  19. }
  20. .shadow {
  21. position: absolute;
  22. width: 100%;
  23. height: 100%;
  24. left: 0;
  25. top: 0;
  26. background: rgba(0, 0, 0, 0.3);
  27. }
  28. .stop_word_table {
  29. width: 413px;
  30. position: fixed;
  31. top: 5%;
  32. left: 37%;
  33. background: #FFFFFF;
  34. border: 1px solid rgba(0, 0, 0, 0.1);
  35. padding: 24px;
  36. }
  37. .stop_word_table .title {
  38. display: flex;
  39. justify-content: space-between;
  40. align-items: center;
  41. font-weight: bold;
  42. font-size: 16px;
  43. color: #000000;
  44. padding-bottom: 16px;
  45. border-bottom: 1px solid rgba(0, 0, 0, 0.06);
  46. }
  47. .stop_word_table .title img {
  48. width: 24px;
  49. height: 24px;
  50. cursor: pointer;
  51. }
  52. .stop_word_table .top {
  53. display: flex;
  54. align-items: center;
  55. margin-top: 16px;
  56. }
  57. .stop_word_table .top input {
  58. width: 278px;
  59. height: 40px;
  60. border: 1px solid #000000;
  61. outline: none;
  62. }
  63. .stop_word_table .top button {
  64. width: 87px;
  65. height: 40px;
  66. background: #000000;
  67. text-align: center;
  68. font-weight: bold;
  69. font-size: 16px;
  70. line-height: 40px;
  71. color: #ffffff;
  72. cursor: pointer;
  73. border: none;
  74. }
  75. .stop_word_table .main {
  76. margin-top: 16px;
  77. max-height: 340px;
  78. overflow: hidden;
  79. overflow-y: scroll;
  80. }
  81. .stop_word_table .one {
  82. display: flex;
  83. justify-content: space-between;
  84. font-size: 16px;
  85. color: #000000;
  86. height: 34px;
  87. line-height: 34px;
  88. padding: 0 8px;
  89. }
  90. .stop_word_table .right span {
  91. cursor: pointer;
  92. }
  93. .stop_word_table .main> :nth-child(2n) {
  94. background: #ffffff;
  95. }
  96. .stop_word_table .main> :nth-child(2n-1) {
  97. background: #f8f8f8;
  98. }
  99. .stop_word_table .bottom {
  100. display: flex;
  101. justify-content: space-between;
  102. margin-top: 16px;
  103. }
  104. .stop_word_table .bottom button {
  105. width: 173.5px;
  106. height: 48px;
  107. font-weight: bold;
  108. font-size: 16px;
  109. border: none;
  110. cursor: pointer;
  111. }
  112. .stop_word_table .bottom .close {
  113. background: #ebebeb;
  114. color: #000000;
  115. }
  116. .stop_word_table .bottom .add {
  117. background: #000000;
  118. color: #ffffff;
  119. }
  120. </style>
  121. </head>
  122. <body>
  123. <div class="wrap">
  124. <div class="content">
  125. <div class="content-inner" style="padding: 0;">
  126. <div class="cloudDiv">
  127. <div class="cloud-copyright">Copyright © Jason Davies</div>
  128. <div class="cloud-con-div" id="cloudDiv"></div>
  129. </div>
  130. <form id="form">
  131. <div class="cloud-box">
  132. <!-- <div class="cloud-rule clear">
  133. <div class="rule-item fl">
  134. <p class="fl">规则:</p>
  135. <input type="text" hidden="" id="rule" value="1">
  136. <div class="rule-radio rule fl">
  137. <div name="radio" class="radio-con fl ruleType radio-active" value='1'><i
  138. class="radio-icon fl"></i>主题性
  139. </div>
  140. <div name="radio" class="radio-con fl ruleType" value='2'><i
  141. class="radio-icon fl"></i>频次</div>
  142. </div>
  143. </div>
  144. <div class="rule-item fl">
  145. <p class="fl">数据类型:</p>
  146. <input type="text" hidden="" id="dataType" value="Word">
  147. <select name="selectDataType" class="selectOp fl" id="dataTypeSel">
  148. <option value="Word">Word</option>
  149. <option value="Lemma">Lemma</option>
  150. </select>
  151. </div>
  152. <div class="rule-item fl">
  153. <div class="checkbox-con fl biglittle" style="margin-right: 0px;"><i
  154. class="checkbox-icon fl"></i></div>
  155. <div class="checkbox-con fl stopWordList"><span id="biglittle"
  156. style="color: #0079FF;">区分大小写</span></div>
  157. </div>
  158. </div> -->
  159. <div class="cloud-rule clear" style="border:0;">
  160. <div class="rule-item fl">
  161. <p class="fl">样式:</p>
  162. <input type="text" hidden="" id="spiral" value="archimedean">
  163. <div class="rule-radio styleType fl">
  164. <div name="radio" class="radio-con radio-active fl" value='archimedean'><i
  165. class="radio-icon fl"></i>螺线
  166. </div>
  167. <div name="radio" class="radio-con fl" value='rectangular'><i
  168. class="radio-icon fl"></i>矩形</div>
  169. </div>
  170. </div>
  171. <div class="rule-item fl">
  172. <p class="fl">字体:</p>
  173. <input type="radio" hidden="" id="font" value="impact">
  174. <select name="selectFont" class="selectOp fl" id="fontSel">
  175. <option value="Impact">Impact</option>
  176. <option value="Georgia">Georgia</option>
  177. <option value="Arial">Arial</option>
  178. <option value="Constantia">Constantia</option>
  179. <option value="Century">Century</option>
  180. <option value="Berlin Sans FB">Berlin Sans FB</option>
  181. <option value="Cooper Black">Cooper Black</option>
  182. <option value="Elephant">Elephant</option>
  183. </select>
  184. </div>
  185. <div class="rule-item fl">
  186. <p class="fl">文字方向:</p>
  187. <input type="text" hidden="" id="fontdir" value="1">
  188. <div class="rule-radio fontDriect fl">
  189. <div name="orientations" class="radio-con radio-active fl" value='1'><i
  190. class="radio-icon fl"></i>水平
  191. </div>
  192. <div name="orientations" class="radio-con fl" value='2'><i
  193. class="radio-icon fl"></i>垂直</div>
  194. <div name="orientations" class="radio-con fl" value='3'><i
  195. class="radio-icon fl"></i>垂直和水平</div>
  196. </div>
  197. </div>
  198. <div id="angles" style="float: left" hidden="">
  199. <p>
  200. <input type="number" id="angle-count" value="5" min="1"><label for="angle-count">
  201. <font style="vertical-align: inherit;"></font>
  202. </label>
  203. <font style="vertical-align: inherit;"><label for="angle-from">
  204. <font style="vertical-align: inherit;">来自的</font>
  205. </label><label for="angle-count">
  206. <font style="vertical-align: inherit;">方向</font>
  207. </label></font><label for="angle-from">
  208. <font style="vertical-align: inherit;"></font>
  209. </label><input type="number" id="angle-from" value="0" min="-90" max="90">
  210. <font style="vertical-align: inherit;">
  211. <font style="vertical-align: inherit;">°
  212. </font>
  213. </font><label for="angle-to">
  214. <font style="vertical-align: inherit;">
  215. <font style="vertical-align: inherit;">到</font>
  216. </font>
  217. </label><input type="number" id="angle-to" value="0" min="-90" max="90">
  218. <font style="vertical-align: inherit;">
  219. <font style="vertical-align: inherit;"> °
  220. </font>
  221. </font>
  222. </p>
  223. </div>
  224. <div class="rule-item fl">
  225. <p class="fl">缩放:</p>
  226. <input type="text" hidden="" id="scale" value="sqrt">
  227. <div class="rule-radio scaleSel fl">
  228. <div name="radio" class="radio-con fl" value="log"><i class="radio-icon fl"></i>log
  229. n</div>
  230. <div name="radio" class="radio-con radio-active fl" value="sqrt"><i
  231. class="radio-icon fl"></i>✓n</div>
  232. <div name="radio" class="radio-con fl" value="linear"><i class="radio-icon fl"></i>n
  233. </div>
  234. </div>
  235. </div>
  236. <div class="rule-item fl">
  237. <p class="fl">下载:</p>
  238. <div class="download-type fl">
  239. <span class="dType" id="download-svg">SVG</span>
  240. <span class="line2">|</span>
  241. <span class="dType" id="download-png">PNG</span>
  242. </div>
  243. </div>
  244. <div class="rule-item fl">
  245. <!-- <div class="checkbox-con checkbox-active fl hide"><i class="checkbox-icon fl"></i>区分大小写 -->
  246. <!-- </div> -->
  247. <div class="checkbox-con fl stop" style="margin-right: 0px;"><i
  248. class="checkbox-icon fl"></i></div>
  249. <div class="checkbox-con fl stopWordList"><span id="stop"
  250. style="color: #0079FF;">停用词表</span></div>
  251. </div>
  252. </div>
  253. <textarea rows="" cols="" id="text" name="text" hidden=""></textarea>
  254. </div>
  255. <div class="cloud-footer">
  256. <button class="produce" type="submit" id="go">生成</button>
  257. </div>
  258. </form>
  259. </div>
  260. </div>
  261. <div class="shadow" id="shadow" style="display: none;">
  262. <div class="stop_word_table" id="wordTable">
  263. <div class="title">
  264. <span>停用词表</span>
  265. <img id="closeWord" src="./img/close.png" alt="">
  266. </div>
  267. <div class="top">
  268. <input type="" name="" value="" id="wordContent" />
  269. <button id="seekWordBtn">检索</button>
  270. </div>
  271. <p style="text-align: right; margin-top: 16px; font-size: 16px; color: #000000">
  272. 共
  273. <span id="allwordnumber"></span>
  274. 词
  275. </p>
  276. <div class="main" id="stop_word_table">
  277. <!-- <div class="one">
  278. <div>{{ item }}</div>
  279. <div class="right">
  280. <span style="margin-right: 24px" @click="edit(item)">编辑</span>
  281. <span @click="deleteOne(item, i)">删除</span>
  282. </div>
  283. </div> -->
  284. </div>
  285. <div class="bottom">
  286. <button class="close" id="emptyWord">清空</button>
  287. <button class="add" id="addWord">添加</button>
  288. </div>
  289. </div>
  290. <div class="stop_word_table" id="addwordDom" style="display: none;">
  291. <div class="title">
  292. <span>添加</span>
  293. <img id="closeWordadd" src="./img/close.png" alt="">
  294. </div>
  295. <div class="top">
  296. <input style="width: 100%;" type="" name="" value="" id="addwordContent" />
  297. </div>
  298. <div class="bottom">
  299. <button class="close" id="canceladd">取消</button>
  300. <button class="add" id="addSubmit">确定</button>
  301. </div>
  302. </div>
  303. <div class="stop_word_table" id="editwordDom" style="display: none;">
  304. <div class="title">
  305. <span>添加</span>
  306. <img id="closeWordedit" src="./img/close.png" alt="">
  307. </div>
  308. <div class="top">
  309. <input style="width: 100%;" type="" name="" value="" id="editwordContent" />
  310. </div>
  311. <div class="bottom">
  312. <button class="close" id="canceledit">取消</button>
  313. <button class="add" id="editSubmit">确定</button>
  314. </div>
  315. </div>
  316. </div>
  317. </div>
  318. <script src="./js/d3.min.js"></script>
  319. <script src="./js/cloud.min.js"></script>
  320. <script type="text/javascript">
  321. var stopWordList = null;
  322. var oldstopWordList = [];
  323. $(function () {
  324. initStopWords();
  325. jiekouData();
  326. })
  327. let query = location.href.split("?");
  328. let arr = query[1].split("&");
  329. var partitionKey = null;
  330. var searchType = null;
  331. arr.forEach((item) => {
  332. if (item.split("=")[0] == "partitionKey") {
  333. partitionKey = item.split("=")[1];
  334. }
  335. if (item.split("=")[0] == "searchType") {
  336. searchType = item.split("=")[1];
  337. }
  338. });
  339. function getdata(stopWordStatus) {
  340. let data = {
  341. searchType: searchType * 1,
  342. partitionKey: partitionKey * 1,
  343. stopWordStatus: stopWordStatus,
  344. }
  345. $.ajax({
  346. url: window.g.BASE_URL + "/GCLSTCServer/tools/TS/glossary/ciyun",
  347. // url: "/i21st-newspaper-management-test/api/article/detail/wordCloud",
  348. data: JSON.stringify(data),
  349. contentType: "application/json",
  350. dataType: "json",
  351. type: "post",
  352. success: function (res) {
  353. let str = ''
  354. res.data.result.forEach(item => {
  355. str += item.word + " "
  356. })
  357. ciyunData = res.data.result
  358. text = str
  359. $("#text").val(text);
  360. $("#go").trigger("click");
  361. }
  362. })
  363. }
  364. function initContent() {
  365. var dataType = $("#dataType").val();
  366. var ruleType = $("#rule").val();
  367. var fileId = "${fileId}";
  368. // $.ajax({
  369. // url: "${ctx}/bc/textKeyWords/wordCloud",
  370. // data: { "fileId": fileId, "ruleType": ruleType },
  371. // dataType: "JSON",
  372. // Type: "POST",
  373. // success: function (data) {
  374. let data = {
  375. count: 0,
  376. flag: true,
  377. jsonObject: null,
  378. listStr: [{
  379. frequency: 3,
  380. level: "L1",
  381. posStr: "[\"noun\"]",
  382. rate: "2762.15",
  383. word: "mine",
  384. }, {
  385. frequency: 2,
  386. level: "L0",
  387. posStr: "[\"adj\"]",
  388. rate: "996.51",
  389. word: "nice",
  390. }, {
  391. frequency: 3,
  392. level: "L0",
  393. posStr: "[\"noun\"]",
  394. rate: "340.09",
  395. word: "house",
  396. }, {
  397. frequency: 2,
  398. level: "L0",
  399. posStr: "[\"noun\"]",
  400. rate: "251.11",
  401. word: "friend",
  402. }],
  403. message: null,
  404. objects: null,
  405. userList: null,
  406. arr: ['5', '6', 'I', 'I', 'I', 'I', 'I', 'I', 'I', 'a', 'Hi', 'Is', 'It', 'My', 'am', 'is', 'I', 'I', 'I', 'I', 'I', 'I', 'I', 'my', 'my', 'my', 'my', 'my', 'my', 'Are', 'She', 'are', 'big', 'you', 'you', 'you', 'you', 'you', 'They', 'This', 'mine', 'mine', 'mine', 'name', 'nice', 'tall', 'than', 'than', 'than', 'than', 'than', 'than', 'than', 'than', 'than', 'than', 'very', 'very', 'very', 'very', 'you', 'you', 'you', 'you', 'you', 'Giant', 'Kendo', 'These', 'funny', 'house', 'house', 'house', 'nicer', 'think', 'think', 'three', 'yours', 'yours', 'yours', 'bigger', 'meters', 'school', 'school', 'taller', 'friends', 'funnier', 'teacher', 'teacher', 'younger', 'friendly', 'nineteen', 'friendlier', 'qinpeng']
  407. }
  408. if (data.flag) {
  409. var $stop = $(".stop");
  410. var stopFlag = $stop.hasClass("checkbox-active"); //选择了停用
  411. // if (!stopFlag) {
  412. // stopWordLists = null;
  413. // }
  414. // if (ruleType == 1) {
  415. // var themeList = data.listStr;
  416. // text = themeDeal(themeList, stopWordLists);
  417. // } else {
  418. // var object = data.jsonObject;
  419. // var words = "";
  420. // if (dataType == "Word") {
  421. // words = object['wordList'];
  422. // } else {
  423. // words = object['lemmaList'];
  424. // }
  425. let str = ''
  426. data.arr.forEach(item => {
  427. str += item + " "
  428. })
  429. // text = replaceStop(words, stopWordLists);
  430. // }
  431. text = str
  432. $("#text").val(text);
  433. $("#go").trigger("click");
  434. } else {
  435. layer.alert(data.message);
  436. }
  437. // }, error: function (jqXHR, textStatus, errorThrown) {
  438. // if (jqXHR.status == 401) {
  439. // var url = jqXHR.responseText;
  440. // layer.alert('会话已过期,请重新登陆。', function (index) {
  441. // layer.close(index);
  442. // location.reload();
  443. // });
  444. // } else {
  445. // layer.alert("网络异常,请稍后重试。(" + errorThrown + ")");
  446. // }
  447. // }
  448. // })
  449. }
  450. function initStopWords() {
  451. $.ajax({
  452. url: window.g.BASE_URL + "/GCLSTCServer/tools/TS/stop/word/list",
  453. // url: "/i21st-newspaper-management-test/api/user/stopVocab/get",
  454. data: JSON.stringify({}),
  455. contentType: "application/json;charset=UTF-8",
  456. dataType: "json",
  457. type: "post",
  458. success: function (data) {
  459. let arr = []
  460. data.data.result.forEach(item => {
  461. arr.push(item.word)
  462. })
  463. oldstopWordList = JSON.parse(JSON.stringify(arr))
  464. stopWordList = JSON.parse(JSON.stringify(arr))
  465. $("#allwordnumber").text(oldstopWordList.length)
  466. changeWordData()
  467. }, error: function (jqXHR, textStatus, errorThrown) {
  468. if (jqXHR.status == 401) {
  469. var url = jqXHR.responseText;
  470. layer.alert('会话已过期,请重新登陆。', function (index) {
  471. layer.close(index);
  472. location.reload();
  473. });
  474. } else {
  475. layer.alert("网络异常,请稍后重试。(" + errorThrown + ")");
  476. }
  477. }
  478. });
  479. }
  480. $(".rule div").click(function () {
  481. $(".rule div").removeClass("radio-active");
  482. $(this).addClass("radio-active");
  483. $("#rule").attr("value", $(this).attr("value"))
  484. initContent();
  485. })
  486. $(".styleType div").click(function () {
  487. $(".styleType div").removeClass("radio-active");
  488. $(this).addClass("radio-active");
  489. $("#spiral").attr("value", $(this).attr("value"));
  490. $("#go").trigger("click");
  491. })
  492. $(".fontDriect div").click(function () {
  493. $(".fontDriect div").removeClass("radio-active");
  494. $(this).addClass("radio-active");
  495. var value = $(this).attr("value");
  496. if (value == 1) {
  497. $("#angle-from").val(0);
  498. $("#angle-to").val(0);
  499. $("#angle-count").val(1);
  500. inChange();
  501. $("#go").click();
  502. $("#angles svg").remove();
  503. } else if (value == 2) {
  504. $("#angle-from").val(90)
  505. $("#angle-to").val(90)
  506. $("#angle-count").val(1);
  507. inChange();
  508. $("#go").click();
  509. $("#angles svg").remove();
  510. } else if (value == 3) {
  511. $("#angle-from").val(0)
  512. $("#angle-to").val(90)
  513. $("#angle-count").val(2);
  514. inChange();
  515. $("#go").click();
  516. $("#angles svg").remove();
  517. }
  518. })
  519. $(".scaleSel div").click(function () {
  520. $(".scaleSel div").removeClass("radio-active");
  521. $(this).addClass("radio-active");
  522. var value = $(this).attr("value");
  523. $("#scale").attr("value", value);
  524. $("#go").trigger("click");
  525. })
  526. $("#fontSel").change(function () {
  527. var value = $(this).children('option:selected').val();
  528. $("#font").attr("value", value);
  529. $("#go").trigger("click");
  530. })
  531. $("#download-png").click(function () {
  532. var el = d3.select("#cloudDiv").node().children[0];
  533. saveSvgAsPng(el, "词云.png");
  534. })
  535. // $(".stopWordList").click(function () {
  536. // var openy = layer.open({
  537. // title: '停用词表'
  538. // , title: false
  539. // , content: '${ctx}/bc/textKeyWords/stopWordListHtml?fileId=${fileId}'
  540. // , area: ['440px', '595px']
  541. // , type: 2
  542. // , closeBtn: 0
  543. // });
  544. // initStopWords();
  545. // })
  546. $("#dataTypeSel").change(function () {
  547. var selvalue = $(this).children('option:selected').val();
  548. // var ruleVlue = $("#rule").attr("value");
  549. // $("#dataType").attr("value", selvalue);
  550. // initContent();
  551. jiekouData()
  552. });
  553. $(".stop").click(function () {
  554. var $stop = $(".stop");
  555. if ($stop.hasClass("checkbox-active")) {
  556. $stop.removeClass("checkbox-active");
  557. } else {
  558. $stop.addClass("checkbox-active");
  559. }
  560. jiekouData()
  561. })
  562. $(".biglittle").click(function () {
  563. var $stop = $(".biglittle");
  564. if ($stop.hasClass("checkbox-active")) {
  565. $stop.removeClass("checkbox-active");
  566. } else {
  567. $stop.addClass("checkbox-active");
  568. }
  569. jiekouData()
  570. })
  571. function jiekouData() {
  572. var $biglittle = $(".biglittle");
  573. var $stop = $(".stop");
  574. let isSelectCaseSensitive = false
  575. let isSelectLemma = false
  576. let stopWordStatus = false
  577. if ($biglittle.hasClass("checkbox-active")) {
  578. isSelectCaseSensitive = true
  579. }
  580. else {
  581. isSelectCaseSensitive = false
  582. }
  583. if ($stop.hasClass("checkbox-active")) {
  584. stopWordStatus = 1
  585. }
  586. else {
  587. stopWordStatus = 0
  588. }
  589. var selvalue = $("#dataTypeSel").children('option:selected').val();
  590. if (selvalue == 'Lemma') {
  591. isSelectLemma = true;
  592. } else {
  593. isSelectLemma = false;
  594. }
  595. getdata(stopWordStatus)
  596. }
  597. function replaceStop(words, stopWordList) {
  598. var text = "";
  599. var wordListLow = new Array();
  600. if (stopWordList != null) {
  601. for (var i = 0; i < stopWordList.length; i++) {
  602. wordListLow.push(stopWordList[i].toLowerCase());
  603. }
  604. }
  605. for (var i = 0; i < words.length; i++) {
  606. var wordList = words[i];
  607. var word = wordList[0];
  608. var count = wordList[1];
  609. if (wordListLow.indexOf(word) < 0) {
  610. for (var j = 0; j < count; j++) {
  611. text += word + " ";
  612. }
  613. }
  614. }
  615. return text;
  616. }
  617. function themeDeal(theme, stopWordList) {
  618. var text = "";
  619. var wordListLow = new Array();
  620. if (stopWordList != null) {
  621. for (var i = 0; i < stopWordList.length; i++) {
  622. wordListLow.push(stopWordList[i].toLowerCase());
  623. }
  624. }
  625. for (var i = 0; i < theme.length; i++) {
  626. var themeWord = theme[i];
  627. var word = themeWord['word'];
  628. var flag = false;
  629. if (wordListLow.indexOf(word.toLowerCase()) > -1) {
  630. flag = true;
  631. }
  632. if (!flag) {
  633. var rate = Math.round(themeWord['rate']);
  634. for (var j = 0; j < rate; j++) {
  635. text += word + " ";
  636. }
  637. }
  638. }
  639. return text;
  640. }
  641. // 停用词表
  642. $("#stop").click(function () {
  643. $("#shadow").show()
  644. changeWordData()
  645. })
  646. // 处理词表数据
  647. var editOldVal = ""
  648. function changeWordData(msg, arr) {
  649. if (arr) {
  650. stopWordList = JSON.parse(JSON.stringify(arr));
  651. } else {
  652. stopWordList = JSON.parse(JSON.stringify(oldstopWordList));
  653. }
  654. $("#stop_word_table").empty()
  655. for (let i = 0; i < stopWordList.length; i++) {
  656. let node = ` <div class="one">
  657. <div>${stopWordList[i]}</div>
  658. <div class="right">
  659. <span style="margin-right: 24px" id="edit${i}" @click="edit(item)">编辑</span>
  660. <span @click="deleteOne(item, i)" id="delete${i}">删除</span>
  661. </div>
  662. </div>`
  663. $("#stop_word_table").append(node)
  664. $(`#edit${i}`).click(function () {
  665. $("#editwordDom").show()
  666. $("#wordTable").hide()
  667. $("#editwordContent").val(stopWordList[i])
  668. editOldVal = stopWordList[i]
  669. })
  670. $(`#delete${i}`).click(function () {
  671. oldstopWordList.forEach((item, i) => {
  672. if (stopWordList[i] == item) {
  673. oldstopWordList.splice(i, 1)
  674. }
  675. })
  676. updatawordData()
  677. })
  678. }
  679. if (msg) {
  680. layer.msg("成功")
  681. }
  682. }
  683. function updatawordData() {
  684. let userStopVocab = JSON.parse(JSON.stringify(oldstopWordList));
  685. $.ajax({
  686. url: window.g.BASE_URL + "/GCLSTCServer/tools/TS/stop/word/save",
  687. // url: "/i21st-newspaper-management-test/api/user/stopVocab/update",
  688. data: JSON.stringify({ tenantId: "", wordList: userStopVocab }),
  689. contentType: "application/json;charset=UTF-8",
  690. dataType: "json",
  691. type: "post",
  692. success: function (data) {
  693. let val = $("#wordContent").val()
  694. if (val != "") {
  695. $("#seekWordBtn").click()
  696. } else {
  697. changeWordData("msg")
  698. }
  699. }, error: function (jqXHR, textStatus, errorThrown) {
  700. if (jqXHR.status == 401) {
  701. var url = jqXHR.responseText;
  702. layer.alert('会话已过期,请重新登陆。', function (index) {
  703. layer.close(index);
  704. location.reload();
  705. });
  706. } else {
  707. layer.alert("网络异常,请稍后重试。(" + errorThrown + ")");
  708. }
  709. }
  710. })
  711. }
  712. // 搜索
  713. $("#seekWordBtn").click(function () {
  714. let val = $("#wordContent").val()
  715. let arr = []
  716. if (val == "") {
  717. stopWordList = JSON.parse(JSON.stringify(oldstopWordList))
  718. changeWordData("msg")
  719. } else {
  720. oldstopWordList.forEach((item, i) => {
  721. if (item.indexOf(val) != -1) {
  722. arr.push(item);
  723. }
  724. })
  725. // stopWordList = JSON.parse(JSON.stringify(arr))
  726. changeWordData("msg", arr)
  727. }
  728. })
  729. // 清空
  730. $("#emptyWord").click(function () {
  731. oldstopWordList = []
  732. updatawordData()
  733. })
  734. // 关闭
  735. $("#closeWord").click(function () {
  736. $("#shadow").hide()
  737. })
  738. // 新增 addWord
  739. $("#addWord").click(function () {
  740. $("#addwordDom").show()
  741. $("#wordTable").hide()
  742. $("#addwordContent").val("")
  743. })
  744. // 确定新增 addSubmit
  745. $("#addSubmit").click(function () {
  746. let val = $("#addwordContent").val()
  747. if (val == '') {
  748. layer.msg("请输入内容")
  749. return
  750. } else {
  751. let flag = false;
  752. oldstopWordList.forEach(item => {
  753. if (item == val) {
  754. flag = true
  755. }
  756. })
  757. if (flag) {
  758. layer.msg("该词已经存在,请勿重复添加")
  759. return
  760. }
  761. oldstopWordList.unshift(val)
  762. stopWordList.unshift(val)
  763. $("#wordTable").show()
  764. $("#addwordDom").hide()
  765. updatawordData()
  766. }
  767. })
  768. // 确定修改
  769. $('#editSubmit').click(function () {
  770. let val = $("#editwordContent").val()
  771. if (val == '') {
  772. layer.msg("请输入内容")
  773. return
  774. } else {
  775. let flag = false;
  776. oldstopWordList.forEach(item => {
  777. if (item == val) {
  778. flag = true
  779. }
  780. })
  781. if (flag) {
  782. layer.msg("该词已经存在,请勿重复添加")
  783. return
  784. }
  785. let arr = JSON.parse(JSON.stringify(oldstopWordList))
  786. let index = null
  787. arr.forEach((item, i) => {
  788. if (item == editOldVal) {
  789. index = i
  790. }
  791. })
  792. arr[index] = val
  793. oldstopWordList = JSON.parse(JSON.stringify(arr))
  794. stopWordList = JSON.parse(JSON.stringify(arr))
  795. $("#wordTable").show()
  796. $("#editwordDom").hide()
  797. updatawordData()
  798. }
  799. })
  800. // 关闭新增词
  801. $("#closeWordadd").click(function () {
  802. $("#wordTable").show()
  803. $("#addwordDom").hide()
  804. })
  805. $("#canceladd").click(function () {
  806. $("#wordTable").show()
  807. $("#addwordDom").hide()
  808. })
  809. // 关闭编辑
  810. $("#closeWordedit").click(function () {
  811. $("#wordTable").show()
  812. $("#editwordDom").hide()
  813. })
  814. $("#canceledit").click(function () {
  815. $("#wordTable").show()
  816. $("#editwordDom").hide()
  817. })
  818. </script>
  819. </body>
  820. </html>