CheckPinyin.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528
  1. <template>
  2. <div class="check-article">
  3. <div class="main">
  4. <div class="main-top">
  5. <div style="display: flex">
  6. <b>校对拼音</b>
  7. </div>
  8. <!-- <div class="btn-box">
  9. <el-button type="primary" @click="savePinyin">保存</el-button>
  10. </div> -->
  11. </div>
  12. <div class="article">
  13. <el-form>
  14. <el-form-item label="标注方式">
  15. <el-radio-group v-model="data.pinyin_type" @change="getArticleData">
  16. <el-radio label="pinyin">拼音</el-radio>
  17. <el-radio label="tone">声调</el-radio>
  18. </el-radio-group>
  19. </el-form-item>
  20. </el-form>
  21. <div v-for="(item, index) in indexArr" :key="index + 'paragraph'" class="paragraph">
  22. <div v-for="(items, indexs) in item" :key="indexs + 'words'" class="sentence-box">
  23. <div
  24. class="sentence"
  25. :style="{
  26. marginRight: items.marginRight ? '8px' : '',
  27. color: activeIndex === index + '_' + items.sentenceIndex + '_' + items.wordIndex ? '#F2555A' : '',
  28. }"
  29. @click="selectItem(items, index)"
  30. >
  31. <span class="pinyin">{{ items.pinyin }}</span>
  32. <span
  33. class="words"
  34. :class="[/^[0-9]*$/.test(items.text)] ? (/^[\u4e00-\u9fa5]/.test(items.text) ? 'hanzi' : 'en') : ''"
  35. >
  36. {{ items.text }}
  37. </span>
  38. </div>
  39. </div>
  40. </div>
  41. </div>
  42. </div>
  43. <el-dialog
  44. v-if="dialogFlag"
  45. :visible.sync="dialogFlag"
  46. :show-close="false"
  47. :close-on-click-modal="false"
  48. :modal-append-to-body="false"
  49. :modal="false"
  50. width="250px"
  51. class="login-dialog"
  52. >
  53. <div class="check-box">
  54. <div class="content">
  55. <div class="words-box">
  56. <span class="pinyin">
  57. {{ itemActive.pinyin }}
  58. </span>
  59. <span class="words">
  60. {{ itemActive.text }}
  61. </span>
  62. </div>
  63. </div>
  64. <!-- <el-input v-model="checkPinyinInput" type="text" class="checkPinyinInput" /> -->
  65. <el-select
  66. v-model="checkPinyinInput"
  67. placeholder="请选择"
  68. filterable
  69. allow-create
  70. default-first-option
  71. class="checkPinyinInput"
  72. >
  73. <el-option v-for="item in pinyinList" :key="item.pinyin" :value="item.pinyin.replace(/,/g, '')">
  74. <span style="float: left">{{ item.pinyin.replace(/,/g, '') }}</span>
  75. <span style="float: right; font-size: 13px; color: #8492a6">{{
  76. item.storage_type === 1 ? '机构库' : item.storage_type === 2 ? '全域库' : '个人库'
  77. }}</span>
  78. </el-option>
  79. </el-select>
  80. <p class="tips">
  81. 一到四声分别用数字1-4表示。拼音间用空格隔开,儿化音用_代替空格,如“骨朵儿”输入“gu1 duo3_er”。
  82. </p>
  83. <div class="btn-box">
  84. <el-button type="info" size="small" @click="cancleDialog">取消</el-button>
  85. <el-button type="primary" size="small" @click="surePinyin">保存</el-button>
  86. </div>
  87. </div>
  88. </el-dialog>
  89. </div>
  90. </template>
  91. <script>
  92. import { toolGetWordPinyinCorrectionList } from '@/api/pinyinCorrection';
  93. export default {
  94. components: {},
  95. props: ['data'],
  96. data() {
  97. return {
  98. loading: false,
  99. id: '',
  100. ArticelData: null,
  101. indexArr: [], // 索引数组
  102. activeIndex: null,
  103. itemActive: null,
  104. dialogFlag: false,
  105. checkPinyinInput: '',
  106. oldInput: '',
  107. tableData: [
  108. ['ā', 'á', 'ǎ', 'à', 'a'],
  109. ['ō', 'ó', 'ǒ', 'ò', 'o'],
  110. ['ē', 'é', 'ě', 'è', 'e'],
  111. ['ī', 'í', 'ǐ', 'ì', 'i'],
  112. ['ū', 'ú', 'ǔ', 'ù', 'u'],
  113. ['ǖ', 'ǘ', 'ǚ', 'ǜ', 'ü'],
  114. ['Ā', 'Á', 'Â', 'À', 'A'],
  115. ['Ō', 'Ó', 'Ô', 'Ò', 'O'],
  116. ['Ē', 'É', 'Ê', 'È', 'E'],
  117. ['Ī', 'Í', 'Î', 'Ì', 'I'],
  118. ['Ū', 'Ú', 'Û', 'Ù', 'U'],
  119. ['n', 'ń', 'ň', 'ǹ', 'n'],
  120. ['m̄', 'ḿ', 'm', 'm̀', 'm'],
  121. ],
  122. toneList: [' ', 'ˉ', 'ˊ', 'ˇ', 'ˋ'],
  123. pinyinList: [], // 拼音校正列表
  124. };
  125. },
  126. // 生命周期 - 创建完成(可以访问当前this实例)
  127. created() {
  128. this.getArticleData();
  129. },
  130. methods: {
  131. // 获取分析结果
  132. getArticleData() {
  133. this.loading = true;
  134. let newdata = [];
  135. this.data.detail.forEach((item) => {
  136. if (item.wordsList && item.wordsList.length !== 0) {
  137. newdata.push(item);
  138. }
  139. });
  140. // this.ArticelData = JSON.parse(JSON.stringify(newdata));
  141. let saveArr = [];
  142. let arr = [];
  143. let saveIndex = 0;
  144. // 添加索引
  145. newdata.forEach((item, index) => {
  146. arr.push([]);
  147. item.wordsList.forEach((items, indexs) => {
  148. items.forEach((itemss, indexss) => {
  149. let pinyin =
  150. this.data.pinyin_type === 'pinyin'
  151. ? this.data.property.is_first_sentence_first_hz_pinyin_first_char_upper_case === 'true' && indexss === 0
  152. ? itemss.pinyin_up
  153. : itemss.pinyin
  154. : itemss.pinyin_tone;
  155. let obj = {
  156. text: itemss.chs,
  157. pinyin,
  158. paraIndex: item.paraIndex,
  159. sentenceIndex: indexs,
  160. wordIndex: indexss,
  161. marginRight: true,
  162. saveIndex,
  163. };
  164. arr[index].push(obj);
  165. let saveObj = {
  166. word: itemss.chs,
  167. pinyin,
  168. // pinyin_lt: itemss.pinyin_lt?itemss.pinyin_lt:''
  169. };
  170. saveArr.push(saveObj);
  171. saveIndex++;
  172. });
  173. });
  174. });
  175. this.indexArr = arr;
  176. this.ArticelData = saveArr;
  177. this.loading = false;
  178. },
  179. selectItem(item, index) {
  180. this.activeIndex = `${index}_${item.sentenceIndex}_${item.wordIndex}`;
  181. this.itemActive = item;
  182. this.pinyinList = [];
  183. toolGetWordPinyinCorrectionList({
  184. word: item.text,
  185. })
  186. .then((res) => {
  187. if (res.status === 1) {
  188. this.pinyinList = res.pinyin_correction_list;
  189. }
  190. this.dialogFlag = true;
  191. })
  192. .catch(() => {
  193. this.dialogFlag = true;
  194. });
  195. this.checkPinyinInput = '';
  196. },
  197. cancleDialog() {
  198. this.activeIndex = null;
  199. this.itemActive = null;
  200. this.checkPinyinInput = '';
  201. this.oldInput = '';
  202. this.dialogFlag = false;
  203. },
  204. surePinyin() {
  205. this.oldInput = JSON.parse(JSON.stringify(this.checkPinyinInput.trim()));
  206. this.handleReplaceTone(this.checkPinyinInput.trim());
  207. },
  208. handleReplaceTone(e) {
  209. let _this = this;
  210. _this.$nextTick(() => {
  211. let value = e;
  212. _this.resArr = [];
  213. if (value) {
  214. let valueArr = [];
  215. value.replace(/\s+/g, ' ');
  216. valueArr = value.split(' ');
  217. // let reg = /\s+/g;
  218. // valueArr = value.split(reg);
  219. valueArr.forEach((item, index) => {
  220. if (this.data.pinyin_type === 'tone') {
  221. this.resArr.push([
  222. {
  223. con: this.toneList[Number(item)],
  224. },
  225. ]);
  226. } else {
  227. this.handleValue(item);
  228. }
  229. });
  230. let str = '';
  231. setTimeout(() => {
  232. _this.resArr.forEach((item) => {
  233. str += ' ';
  234. item.forEach((sItem) => {
  235. if (sItem.number && sItem.con) {
  236. let number = Number(sItem.number);
  237. let con = sItem.con;
  238. let word = _this.addTone(number, con);
  239. str += word;
  240. } else if (sItem.number) {
  241. str += sItem.number;
  242. } else if (sItem.con) {
  243. str += ` ${sItem.con} `;
  244. }
  245. });
  246. });
  247. this.checkPinyinInput = str.trim();
  248. this.ArticelData[this.itemActive.saveIndex].pinyin = this.checkPinyinInput
  249. .replace(/\s+/g, ' ')
  250. .split(/\s+/)
  251. .join(',');
  252. this.itemActive.pinyin = this.checkPinyinInput.replace(/\s+/g, '');
  253. this.savePinyin();
  254. }, 10);
  255. }
  256. });
  257. },
  258. handleValue(valItem) {
  259. let reg = /\d/;
  260. let reg2 = /[A-Za-z]+\d/g;
  261. let numList = [];
  262. let valArr = valItem.split('');
  263. if (reg2.test(valItem)) {
  264. for (let i = 0; i < valArr.length; i++) {
  265. let item = valItem[i];
  266. if (reg.test(item)) {
  267. let numIndex = numList.length == 0 ? 0 : numList[numList.length - 1].index;
  268. let con = valItem.substring(numIndex, i);
  269. con = con.replace(/\d/g, '');
  270. let obj = {
  271. index: i,
  272. number: item,
  273. con,
  274. isTran: true,
  275. };
  276. numList.push(obj);
  277. }
  278. }
  279. } else {
  280. numList = [];
  281. }
  282. if (numList.length == 0) {
  283. this.resArr.push([{ con: valItem }]);
  284. } else {
  285. this.resArr.push(numList);
  286. }
  287. },
  288. addTone(number, con) {
  289. let _this = this;
  290. let zmList = ['a', 'o', 'e', 'i', 'u', 'v', 'A', 'O', 'E', 'I', 'U', 'n', 'm'];
  291. if (number) {
  292. for (let i = 0; i < zmList.length; i++) {
  293. let zm = zmList[i];
  294. if (con.indexOf(zm) > -1) {
  295. let zm2 = _this.tableData[i][number - 1];
  296. if (con.indexOf('iu') > -1) {
  297. zm2 = _this.tableData[4][number - 1];
  298. con = con.replace('u', zm2);
  299. } else if (con.indexOf('ui') > -1) {
  300. zm2 = _this.tableData[3][number - 1];
  301. con = con.replace('i', zm2);
  302. } else if (
  303. con.indexOf('yv') > -1 ||
  304. con.indexOf('jv') > -1 ||
  305. con.indexOf('qv') > -1 ||
  306. con.indexOf('xv') > -1
  307. ) {
  308. zm2 = _this.tableData[4][number - 1];
  309. con = con.replace('v', zm2);
  310. } else {
  311. con = con.replace(zm, zm2);
  312. }
  313. break;
  314. }
  315. }
  316. }
  317. return con;
  318. },
  319. savePinyin() {
  320. this.$emit(
  321. 'savePinyin',
  322. this.itemActive.paraIndex,
  323. this.itemActive.sentenceIndex,
  324. this.itemActive.wordIndex,
  325. this.itemActive.pinyin,
  326. );
  327. this.$message.success('保存成功');
  328. this.activeIndex = null;
  329. // this.itemActive = null;
  330. this.checkPinyinInput = '';
  331. this.oldInput = '';
  332. this.dialogFlag = false;
  333. },
  334. },
  335. };
  336. </script>
  337. <style lang="scss" scoped>
  338. .check-article {
  339. min-height: 100%;
  340. background: #f6f6f6;
  341. .wheader {
  342. background: #fff;
  343. }
  344. .el-button {
  345. padding: 5px 16px;
  346. font-size: 14px;
  347. font-weight: 400;
  348. line-height: 22px;
  349. color: #4e5969;
  350. background: #f2f3f5;
  351. border: 1px solid #f2f3f5;
  352. border-radius: 2px;
  353. &.el-button--primary {
  354. color: #fff;
  355. background: #165dff;
  356. border: 1px solid #165dff;
  357. }
  358. }
  359. .main {
  360. background: #fff;
  361. &-top {
  362. position: relative;
  363. display: flex;
  364. align-items: center;
  365. justify-content: space-between;
  366. margin-bottom: 24px;
  367. b {
  368. margin-left: 16px;
  369. font-size: 24px;
  370. font-weight: 500;
  371. line-height: 34px;
  372. color: #000;
  373. }
  374. }
  375. .go-back {
  376. display: flex;
  377. align-items: center;
  378. width: 60px;
  379. padding: 5px 8px;
  380. font-size: 14px;
  381. font-weight: 400;
  382. line-height: 22px;
  383. color: #333;
  384. cursor: pointer;
  385. background: #fff;
  386. border: 1px solid #d9d9d9;
  387. border-radius: 4px;
  388. box-shadow: 0 2px 0 0 rgba(0, 0, 0, 2%);
  389. .el-icon-arrow-left {
  390. margin-right: 8px;
  391. font-size: 16px;
  392. }
  393. }
  394. .article {
  395. padding: 8px;
  396. background: #fcfcfc;
  397. border: 1px solid rgba(0, 0, 0, 8%);
  398. border-radius: 2px;
  399. }
  400. .paragraph {
  401. display: flex;
  402. flex-flow: wrap;
  403. width: 100%;
  404. margin-bottom: 24px;
  405. text-align: center;
  406. .sentence-box {
  407. display: flex;
  408. flex-flow: wrap;
  409. float: left;
  410. .sentence {
  411. margin-top: 8px;
  412. color: #000;
  413. text-align: center;
  414. cursor: pointer;
  415. .words {
  416. display: block;
  417. font-size: 20px;
  418. font-weight: 400;
  419. line-height: 28px;
  420. }
  421. .pinyin {
  422. display: block;
  423. height: 14px;
  424. font-family: 'League';
  425. font-size: 14px;
  426. font-weight: 400;
  427. line-height: 1;
  428. }
  429. }
  430. }
  431. }
  432. }
  433. }
  434. .check-box {
  435. padding: 24px;
  436. background: #fff;
  437. border-radius: 4px;
  438. box-shadow: 0 4px 4px 0 rgba(0, 0, 0, 25%);
  439. .content {
  440. display: flex;
  441. align-items: center;
  442. justify-content: center;
  443. .words-box {
  444. color: #000;
  445. text-align: center;
  446. .words {
  447. display: block;
  448. font-size: 28px;
  449. font-weight: 400;
  450. line-height: 40px;
  451. }
  452. .pinyin {
  453. display: block;
  454. height: 20px;
  455. font-family: 'League';
  456. font-size: 20px;
  457. font-weight: 400;
  458. line-height: 1;
  459. }
  460. }
  461. }
  462. .checkPinyinInput {
  463. margin: 16px 0 8px;
  464. }
  465. .tips {
  466. margin: 0 0 24px;
  467. font-size: 12px;
  468. font-weight: 400;
  469. line-height: 18px;
  470. color: #a0a0a0;
  471. }
  472. .btn-box {
  473. text-align: right;
  474. .el-button {
  475. padding: 2px 12px;
  476. font-size: 12px;
  477. line-height: 20px;
  478. }
  479. }
  480. }
  481. </style>
  482. <style lang="scss">
  483. .check-article {
  484. .login-dialog {
  485. .el-dialog__header {
  486. padding: 0;
  487. }
  488. .el-dialog__body {
  489. padding: 0;
  490. }
  491. .el-input__inner {
  492. text-align: center;
  493. background: #f3f3f3;
  494. }
  495. }
  496. }
  497. </style>