CheckPinyin.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530
  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. if (item.type === 'notice') return;
  148. item.wordsList.forEach((items, indexs) => {
  149. items.forEach((itemss, indexss) => {
  150. let pinyin =
  151. this.data.pinyin_type === 'pinyin'
  152. ? this.data.property.is_first_sentence_first_hz_pinyin_first_char_upper_case === 'true' && indexss === 0
  153. ? itemss.pinyin_up
  154. : itemss.pinyin
  155. : itemss.pinyin_tone;
  156. let obj = {
  157. text: itemss.chs,
  158. pinyin,
  159. paraIndex: item.paraIndex,
  160. sentenceIndex: indexs,
  161. wordIndex: indexss,
  162. marginRight: true,
  163. saveIndex,
  164. };
  165. arr[index].push(obj);
  166. let saveObj = {
  167. word: itemss.chs,
  168. pinyin,
  169. // pinyin_lt: itemss.pinyin_lt?itemss.pinyin_lt:''
  170. };
  171. saveArr.push(saveObj);
  172. saveIndex++;
  173. });
  174. });
  175. });
  176. this.indexArr = arr;
  177. this.ArticelData = saveArr;
  178. this.loading = false;
  179. },
  180. selectItem(item, index) {
  181. this.activeIndex = `${index}_${item.sentenceIndex}_${item.wordIndex}`;
  182. this.itemActive = item;
  183. this.pinyinList = [];
  184. toolGetWordPinyinCorrectionList({
  185. word: item.text,
  186. })
  187. .then((res) => {
  188. if (res.status === 1) {
  189. this.pinyinList = res.pinyin_correction_list;
  190. }
  191. this.dialogFlag = true;
  192. })
  193. .catch(() => {
  194. this.dialogFlag = true;
  195. });
  196. this.checkPinyinInput = '';
  197. },
  198. cancleDialog() {
  199. this.activeIndex = null;
  200. this.itemActive = null;
  201. this.checkPinyinInput = '';
  202. this.oldInput = '';
  203. this.dialogFlag = false;
  204. },
  205. surePinyin() {
  206. this.oldInput = JSON.parse(JSON.stringify(this.checkPinyinInput.trim()));
  207. this.handleReplaceTone(this.checkPinyinInput.trim());
  208. },
  209. handleReplaceTone(e) {
  210. let _this = this;
  211. _this.$nextTick(() => {
  212. let value = e;
  213. _this.resArr = [];
  214. if (value) {
  215. let valueArr = [];
  216. value.replace(/\s+/g, ' ');
  217. valueArr = value.split(' ');
  218. // let reg = /\s+/g;
  219. // valueArr = value.split(reg);
  220. valueArr.forEach((item, index) => {
  221. if (this.data.pinyin_type === 'tone') {
  222. this.resArr.push([
  223. {
  224. con: this.toneList[Number(item)],
  225. },
  226. ]);
  227. } else {
  228. this.handleValue(item);
  229. }
  230. });
  231. let str = '';
  232. setTimeout(() => {
  233. _this.resArr.forEach((item) => {
  234. str += ' ';
  235. item.forEach((sItem) => {
  236. if (sItem.number && sItem.con) {
  237. let number = Number(sItem.number);
  238. let con = sItem.con;
  239. let word = _this.addTone(number, con);
  240. str += word;
  241. } else if (sItem.number) {
  242. str += sItem.number;
  243. } else if (sItem.con) {
  244. str += ` ${sItem.con} `;
  245. }
  246. });
  247. });
  248. this.checkPinyinInput = str.trim();
  249. this.ArticelData[this.itemActive.saveIndex].pinyin = this.checkPinyinInput
  250. .replace(/\s+/g, ' ')
  251. .split(/\s+/)
  252. .join(',');
  253. this.itemActive.pinyin = this.checkPinyinInput.replace(/\s+/g, '');
  254. this.savePinyin();
  255. }, 10);
  256. }
  257. });
  258. },
  259. handleValue(valItem) {
  260. let reg = /\d/;
  261. let reg2 = /[A-Za-z]+\d/g;
  262. let numList = [];
  263. let valArr = valItem.split('');
  264. if (reg2.test(valItem)) {
  265. for (let i = 0; i < valArr.length; i++) {
  266. let item = valItem[i];
  267. if (reg.test(item)) {
  268. let numIndex = numList.length == 0 ? 0 : numList[numList.length - 1].index;
  269. let con = valItem.substring(numIndex, i);
  270. con = con.replace(/\d/g, '');
  271. let obj = {
  272. index: i,
  273. number: item,
  274. con,
  275. isTran: true,
  276. };
  277. numList.push(obj);
  278. }
  279. }
  280. } else {
  281. numList = [];
  282. }
  283. if (numList.length == 0) {
  284. this.resArr.push([{ con: valItem }]);
  285. } else {
  286. this.resArr.push(numList);
  287. }
  288. },
  289. addTone(number, con) {
  290. let _this = this;
  291. let zmList = ['a', 'o', 'e', 'i', 'u', 'v', 'A', 'O', 'E', 'I', 'U', 'n', 'm'];
  292. if (number) {
  293. for (let i = 0; i < zmList.length; i++) {
  294. let zm = zmList[i];
  295. if (con.indexOf(zm) > -1) {
  296. let zm2 = _this.tableData[i][number - 1];
  297. if (con.indexOf('iu') > -1) {
  298. zm2 = _this.tableData[4][number - 1];
  299. con = con.replace('u', zm2);
  300. } else if (con.indexOf('ui') > -1) {
  301. zm2 = _this.tableData[3][number - 1];
  302. con = con.replace('i', zm2);
  303. } else if (
  304. con.indexOf('yv') > -1 ||
  305. con.indexOf('jv') > -1 ||
  306. con.indexOf('qv') > -1 ||
  307. con.indexOf('xv') > -1
  308. ) {
  309. zm2 = _this.tableData[4][number - 1];
  310. con = con.replace('v', zm2);
  311. } else {
  312. con = con.replace(zm, zm2);
  313. }
  314. break;
  315. }
  316. }
  317. }
  318. return con;
  319. },
  320. savePinyin() {
  321. this.$emit(
  322. 'savePinyin',
  323. this.itemActive.paraIndex,
  324. this.itemActive.sentenceIndex,
  325. this.itemActive.wordIndex,
  326. this.itemActive.pinyin,
  327. );
  328. this.$message.success('保存成功');
  329. this.activeIndex = null;
  330. // this.itemActive = null;
  331. this.checkPinyinInput = '';
  332. this.oldInput = '';
  333. this.dialogFlag = false;
  334. },
  335. },
  336. };
  337. </script>
  338. <style lang="scss" scoped>
  339. .check-article {
  340. min-height: 100%;
  341. background: #f6f6f6;
  342. .wheader {
  343. background: #fff;
  344. }
  345. .el-button {
  346. padding: 5px 16px;
  347. font-size: 14px;
  348. font-weight: 400;
  349. line-height: 22px;
  350. color: #4e5969;
  351. background: #f2f3f5;
  352. border: 1px solid #f2f3f5;
  353. border-radius: 2px;
  354. &.el-button--primary {
  355. color: #fff;
  356. background: #165dff;
  357. border: 1px solid #165dff;
  358. }
  359. }
  360. .main {
  361. background: #fff;
  362. &-top {
  363. position: relative;
  364. display: flex;
  365. align-items: center;
  366. justify-content: space-between;
  367. margin-bottom: 24px;
  368. b {
  369. margin-left: 16px;
  370. font-size: 24px;
  371. font-weight: 500;
  372. line-height: 34px;
  373. color: #000;
  374. }
  375. }
  376. .go-back {
  377. display: flex;
  378. align-items: center;
  379. width: 60px;
  380. padding: 5px 8px;
  381. font-size: 14px;
  382. font-weight: 400;
  383. line-height: 22px;
  384. color: #333;
  385. cursor: pointer;
  386. background: #fff;
  387. border: 1px solid #d9d9d9;
  388. border-radius: 4px;
  389. box-shadow: 0 2px 0 0 rgba(0, 0, 0, 2%);
  390. .el-icon-arrow-left {
  391. margin-right: 8px;
  392. font-size: 16px;
  393. }
  394. }
  395. .article {
  396. padding: 8px;
  397. background: #fcfcfc;
  398. border: 1px solid rgba(0, 0, 0, 8%);
  399. border-radius: 2px;
  400. }
  401. .paragraph {
  402. display: flex;
  403. flex-flow: wrap;
  404. width: 100%;
  405. margin-bottom: 24px;
  406. text-align: center;
  407. .sentence-box {
  408. display: flex;
  409. flex-flow: wrap;
  410. float: left;
  411. .sentence {
  412. margin-top: 8px;
  413. color: #000;
  414. text-align: center;
  415. cursor: pointer;
  416. .words {
  417. display: block;
  418. font-size: 20px;
  419. font-weight: 400;
  420. line-height: 28px;
  421. }
  422. .pinyin {
  423. display: block;
  424. height: 14px;
  425. font-family: 'League';
  426. font-size: 14px;
  427. font-weight: 400;
  428. line-height: 1;
  429. }
  430. }
  431. }
  432. }
  433. }
  434. }
  435. .check-box {
  436. padding: 24px;
  437. background: #fff;
  438. border-radius: 4px;
  439. box-shadow: 0 4px 4px 0 rgba(0, 0, 0, 25%);
  440. .content {
  441. display: flex;
  442. align-items: center;
  443. justify-content: center;
  444. .words-box {
  445. color: #000;
  446. text-align: center;
  447. .words {
  448. display: block;
  449. font-size: 28px;
  450. font-weight: 400;
  451. line-height: 40px;
  452. }
  453. .pinyin {
  454. display: block;
  455. height: 20px;
  456. font-family: 'League';
  457. font-size: 20px;
  458. font-weight: 400;
  459. line-height: 1;
  460. }
  461. }
  462. }
  463. .checkPinyinInput {
  464. margin: 16px 0 8px;
  465. }
  466. .tips {
  467. margin: 0 0 24px;
  468. font-size: 12px;
  469. font-weight: 400;
  470. line-height: 18px;
  471. color: #a0a0a0;
  472. }
  473. .btn-box {
  474. text-align: right;
  475. .el-button {
  476. padding: 2px 12px;
  477. font-size: 12px;
  478. line-height: 20px;
  479. }
  480. }
  481. }
  482. </style>
  483. <style lang="scss">
  484. .check-article {
  485. .login-dialog {
  486. .el-dialog__header {
  487. padding: 0;
  488. }
  489. .el-dialog__body {
  490. padding: 0;
  491. }
  492. .el-input__inner {
  493. text-align: center;
  494. background: #f3f3f3;
  495. }
  496. }
  497. }
  498. </style>