TextAnalysis.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  1. <template>
  2. <div v-loading="loading" class="TextAnalysis">
  3. <HeaderPage />
  4. <div class="main">
  5. <div class="title">文本分析</div>
  6. <div class="input_main">
  7. <el-input v-model="txt" type="textarea" placeholder="请输入文本" :autosize="{ minRows: 9 }" />
  8. <div class="text_btn">
  9. <span class="left">{{ txt.length }}/1000</span>
  10. <div class="operation">
  11. <el-upload
  12. ref="upload"
  13. :action="url"
  14. accept=".txt"
  15. :limit="10"
  16. :on-exceed="handleExceed"
  17. :on-success="handleSuccess"
  18. multiple
  19. :show-file-list="false"
  20. class="btn"
  21. >
  22. <el-button>批量上传</el-button>
  23. </el-upload>
  24. <span class="btn" @click="submit">分析</span>
  25. </div>
  26. </div>
  27. </div>
  28. <div v-if="data" class="list_main">
  29. <div class="title">
  30. <span style="margin-right: 16px">文本列表:</span>
  31. </div>
  32. <div class="list">
  33. <div v-for="(item, i) in data.record_list" :key="i + 'one'">
  34. <div class="number">{{ i + 1 }}</div>
  35. <div class="txt" @click="handleJump(item)">
  36. {{ item.first_sentence }}
  37. </div>
  38. <div class="time">{{ item.create_time }}</div>
  39. <div class="analysis_status">{{ analysis_status_list[item.analysis_status] }}</div>
  40. <div
  41. v-if="item.analysis_status === 3 || item.analysis_status === 0"
  42. class="cxjx"
  43. @click="anewSubmit(item.id)"
  44. >
  45. {{ item.analysis_status === 3 ? '重新解析' : '解析' }}
  46. </div>
  47. <el-popconfirm title="确定删除这一条记录吗?" @confirm="deleteOne(item.id, i)">
  48. <img slot="reference" src="../../assets/teacherdev/delete-one.png" alt="删除" />
  49. </el-popconfirm>
  50. </div>
  51. </div>
  52. <el-pagination
  53. :current-page.sync="data.cur_page"
  54. :page-size="20"
  55. layout="prev, pager, next, jumper"
  56. :total="data.total_count"
  57. @current-change="handleCurrentChange"
  58. />
  59. </div>
  60. </div>
  61. </div>
  62. </template>
  63. <script>
  64. import {
  65. postapi,
  66. AddTextFile,
  67. GetTextAnalyseRecordInfo,
  68. PageQueryMyTextAnalyseRecordList,
  69. analyse,
  70. reparse,
  71. } from '@/api/api';
  72. import { getToken } from '@/utils/auth';
  73. import HeaderPage from '@/components/Header';
  74. export default {
  75. name: 'TextAnalysis',
  76. components: {
  77. HeaderPage,
  78. },
  79. data() {
  80. return {
  81. txt: '',
  82. loading: false,
  83. token: null,
  84. pageSize: 20,
  85. data: null,
  86. file_id_list: [],
  87. analysis_status_list: {
  88. 0: '未解析',
  89. 1: '解析中',
  90. 2: '解析成功',
  91. 3: '解析失败',
  92. },
  93. };
  94. },
  95. computed: {
  96. url() {
  97. let userInfo = JSON.parse(getToken());
  98. if (!userInfo) return `${process.env.VUE_APP_BASE_API}/GCLSFileServer/WebFileUpload`;
  99. return `${process.env.VUE_APP_BASE_API}/GCLSFileServer/WebFileUpload?AccessToken=${userInfo.access_token}&SecurityLevel=Mid"`;
  100. },
  101. },
  102. created() {
  103. let data = getToken();
  104. this.token = JSON.parse(data);
  105. this.pageQueryMyTextAnalyseRecordList();
  106. },
  107. // 方法集合
  108. methods: {
  109. // 批量上传
  110. handleSuccess(res, file, fileList) {
  111. if (res.status !== 1) {
  112. this.$message.error(res.message);
  113. return;
  114. }
  115. this.file_id_list.push(...file.response.file_info_list.map(({ file_id }) => file_id));
  116. // 通过 fileList 的 response 判断是否已全部完成上传
  117. if (fileList.every(({ response }) => response?.status)) {
  118. this.loading = true;
  119. this.$refs.upload.clearFiles();
  120. AddTextFile({
  121. file_id_list: this.file_id_list,
  122. })
  123. .then(() => {
  124. this.$message.success('上传成功');
  125. this.pageQueryMyTextAnalyseRecordList(true);
  126. })
  127. .catch((res) => {
  128. this.$message.error(res.message);
  129. })
  130. .finally(() => {
  131. this.file_id_list = [];
  132. this.loading = false;
  133. });
  134. }
  135. },
  136. handleExceed(files) {
  137. this.$message.warning(`当前限制选择 10 个文件,本次选择了 ${files.length} 个文件`);
  138. },
  139. handleJump(item) {
  140. if (item.analysis_status === 0) return this.anewSubmit(item.id);
  141. if (item.analysis_status === 1) return this.$message.warning('当前数据正在解析,请稍后');
  142. if (item.analysis_status === 2) {
  143. return this.getTextAnalyseRecordInfo(item.id).then((record) => {
  144. this.jumpResult(record);
  145. });
  146. }
  147. if (item.analysis_status === 3) return this.anewSubmit(item.id);
  148. },
  149. /**
  150. * 跳转分析结果页
  151. * @param {object} item
  152. */
  153. jumpResult(item) {
  154. if (item.analysis_status !== 2) {
  155. return this.$message.warning('当前数据解析失败,请重新解析');
  156. }
  157. window.open(
  158. this.$router.resolve({
  159. path: '/textanalysis/Result',
  160. query: {
  161. partition_key: item.partition_key,
  162. subject_words: item.subject_words,
  163. word_text_count: item.word_text_count,
  164. word_count: item.word_count,
  165. vocabulary_text_count: item.vocabulary_text_count,
  166. vocabulary_count: item.vocabulary_count,
  167. pinyin_count: item.pinyin_count,
  168. pinyin_text_count: item.pinyin_text_count,
  169. pinyin_difficulty: item.pinyin_difficulty,
  170. word_difficulty: item.word_difficulty,
  171. vocabulary_difficulty: item.vocabulary_difficulty,
  172. type: '文本分析',
  173. },
  174. }).href,
  175. '_blank',
  176. );
  177. },
  178. /**
  179. * 删除一条记录
  180. * @param {string} id
  181. * @param {number} index
  182. */
  183. deleteOne(id, index) {
  184. this.loading = true;
  185. postapi({
  186. url: '/GCLSTCServer/tools/TS/analysis/record/del',
  187. data: {
  188. id,
  189. },
  190. })
  191. .then((res) => {
  192. this.data.record_list.splice(index, 1);
  193. this.data.total_count -= 1;
  194. this.$message.success(res.msg);
  195. this.loading = false;
  196. })
  197. .catch(() => {
  198. this.loading = false;
  199. });
  200. },
  201. /**
  202. * 重新解析
  203. * @param {string} analyse_record_id
  204. */
  205. anewSubmit(analyse_record_id) {
  206. this.loading = true;
  207. reparse({ analyse_record_id })
  208. .then(({ record }) => {
  209. this.jumpResult(record);
  210. this.pageQueryMyTextAnalyseRecordList(true);
  211. })
  212. .finally(() => {
  213. this.loading = false;
  214. });
  215. },
  216. /**
  217. * 分析
  218. */
  219. submit() {
  220. if (this.txt === '') {
  221. return this.$message.warning('请先输入内容');
  222. }
  223. if (this.txt.length > 1000) {
  224. return this.$message.warning('超出字数限制');
  225. }
  226. this.loading = true;
  227. analyse({
  228. text: this.txt,
  229. })
  230. .then(({ record }) => {
  231. this.txt = '';
  232. this.jumpResult(record);
  233. this.pageQueryMyTextAnalyseRecordList(true);
  234. })
  235. .finally(() => {
  236. this.loading = false;
  237. });
  238. },
  239. /**
  240. * 获取单条文本分析记录信息
  241. * @param {string} id
  242. */
  243. getTextAnalyseRecordInfo(id) {
  244. return GetTextAnalyseRecordInfo({ id }).then(({ record }) => {
  245. return record;
  246. });
  247. },
  248. /**
  249. * 获取列表
  250. * @param {boolean} bol 是否提示
  251. */
  252. pageQueryMyTextAnalyseRecordList(bol) {
  253. this.loading = true;
  254. PageQueryMyTextAnalyseRecordList({ page_capacity: this.pageSize, cur_page: this.data?.cur_page ?? 1 })
  255. .then((data) => {
  256. this.data = data;
  257. if (bol) {
  258. this.$message.success('获取列表成功');
  259. }
  260. })
  261. .finally(() => {
  262. this.loading = false;
  263. });
  264. },
  265. handleCurrentChange(val) {
  266. this.data.cur_page = val;
  267. this.pageQueryMyTextAnalyseRecordList();
  268. },
  269. },
  270. };
  271. </script>
  272. <style lang="scss" scoped>
  273. .TextAnalysis {
  274. min-height: 100%;
  275. .main {
  276. min-height: calc(100vh - 64px - 54px - 24px);
  277. padding-top: 54px;
  278. padding-bottom: 24px;
  279. background: #f6f6f6;
  280. > div {
  281. width: 1200px;
  282. margin: 0 auto;
  283. }
  284. > .title {
  285. font-size: 30px;
  286. font-weight: 700;
  287. line-height: 43px;
  288. color: #2c2c2c;
  289. }
  290. .input_main {
  291. width: 1168px;
  292. min-height: 295px;
  293. padding: 16px;
  294. margin-top: 17px;
  295. background: #fff;
  296. border-radius: 4px;
  297. .text_btn {
  298. display: flex;
  299. align-items: center;
  300. justify-content: space-between;
  301. margin-top: 16px;
  302. .left {
  303. font-size: 14px;
  304. font-weight: 400;
  305. line-height: 26px;
  306. color: #000;
  307. }
  308. .operation {
  309. display: flex;
  310. .btn {
  311. width: 124px;
  312. height: 40px;
  313. font-size: 16px;
  314. font-weight: 500;
  315. line-height: 40px;
  316. color: #000;
  317. text-align: center;
  318. cursor: pointer;
  319. background: #ffc600;
  320. border: 1px solid rgba(0, 0, 0, 15%);
  321. border-radius: 4px;
  322. box-shadow: 0 2px 0 rgba(0, 0, 0, 4%);
  323. .el-button {
  324. color: #000;
  325. background-color: #ffc600;
  326. border-color: #ffc600;
  327. &:hover {
  328. color: #000;
  329. }
  330. }
  331. & + .btn {
  332. margin-left: 16px;
  333. }
  334. }
  335. }
  336. }
  337. }
  338. .list_main {
  339. margin-top: 37px;
  340. .title {
  341. font-size: 16px;
  342. font-weight: 400;
  343. line-height: 24px;
  344. color: #000;
  345. }
  346. .list {
  347. margin: 16px 0 22px;
  348. > div {
  349. display: flex;
  350. column-gap: 24px;
  351. align-items: center;
  352. height: 48px;
  353. padding: 0 16px;
  354. font-size: 16px;
  355. font-weight: 400;
  356. color: #000;
  357. background: #fff;
  358. border-bottom: 1px solid rgba(0, 0, 0, 8%);
  359. .number {
  360. width: 20px;
  361. text-align: right;
  362. }
  363. .txt {
  364. width: 740px;
  365. overflow: hidden;
  366. text-overflow: ellipsis;
  367. white-space: nowrap;
  368. cursor: pointer;
  369. }
  370. .time {
  371. width: 135px;
  372. }
  373. .cxjx {
  374. cursor: pointer;
  375. }
  376. .analysis_status {
  377. flex: 1;
  378. }
  379. img {
  380. width: 24px;
  381. height: 24px;
  382. cursor: pointer;
  383. }
  384. }
  385. }
  386. }
  387. }
  388. }
  389. </style>