TextAnalysis.vue 11 KB

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