|
|
@@ -189,21 +189,74 @@ export default {
|
|
|
// 将数字拼音转换为声调拼音
|
|
|
convertTonePinyin() {
|
|
|
if (!this.numberPinyin) return;
|
|
|
- let newPinyin = this.numberPinyin
|
|
|
- .trim()
|
|
|
- .split(/\s+/)
|
|
|
- .map((item) => {
|
|
|
- return handleToneValue(item);
|
|
|
- })
|
|
|
- .map((item) =>
|
|
|
- item.map(({ number, con }) => (number && con ? addTone(Number(number), con) : number || con || '')),
|
|
|
- )
|
|
|
- .filter((item) => item.length > 0)
|
|
|
- .join(' ');
|
|
|
+ let newPinyin = this.handleReplaceTone(this.numberPinyin.replace(/\s+| +/g, ''));
|
|
|
const leading = (this.dataContent.pinyin.match(/^[ ]+/) || [''])[0];
|
|
|
const trailing = (this.dataContent.pinyin.match(/[ ]+$/) || [''])[0];
|
|
|
this.dataContent.pinyin = leading + newPinyin + trailing;
|
|
|
},
|
|
|
+ handleReplaceTone(e) {
|
|
|
+ let _this = this;
|
|
|
+ let value = e;
|
|
|
+ _this.resArr = [];
|
|
|
+ if (value) {
|
|
|
+ let valueArr = [];
|
|
|
+ value.replace(/\s+/g, ' ');
|
|
|
+ valueArr = value.split(' ');
|
|
|
+ // let reg = /\s+/g;
|
|
|
+ // valueArr = value.split(reg);
|
|
|
+
|
|
|
+ valueArr.forEach((item, index) => {
|
|
|
+ this.handleValue(item);
|
|
|
+ });
|
|
|
+ let str = '';
|
|
|
+ _this.resArr.forEach((item) => {
|
|
|
+ str += ' ';
|
|
|
+ item.forEach((sItem) => {
|
|
|
+ if (sItem.number && sItem.con) {
|
|
|
+ let number = Number(sItem.number);
|
|
|
+ let con = sItem.con;
|
|
|
+ let word = addTone(number, con);
|
|
|
+ str += word;
|
|
|
+ } else if (sItem.number) {
|
|
|
+ str += sItem.number;
|
|
|
+ } else if (sItem.con) {
|
|
|
+ str += ` ${sItem.con} `;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ return str.trim();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ handleValue(valItem) {
|
|
|
+ let reg = /\d/;
|
|
|
+ let reg2 = /[A-Za-z]+\d/g;
|
|
|
+ let numList = [];
|
|
|
+ let valArr = valItem.split('');
|
|
|
+ if (reg2.test(valItem)) {
|
|
|
+ for (let i = 0; i < valArr.length; i++) {
|
|
|
+ let item = valItem[i];
|
|
|
+ if (reg.test(item)) {
|
|
|
+ let numIndex = numList.length === 0 ? 0 : numList[numList.length - 1].index;
|
|
|
+ let con = valItem.substring(numIndex, i);
|
|
|
+ con = con.replace(/\d/g, '');
|
|
|
+ let obj = {
|
|
|
+ index: i,
|
|
|
+ number: item,
|
|
|
+ con,
|
|
|
+ isTran: true,
|
|
|
+ };
|
|
|
+ numList.push(obj);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ numList = [];
|
|
|
+ }
|
|
|
+ if (numList.length === 0) {
|
|
|
+ this.resArr.push([{ con: valItem }]);
|
|
|
+ } else {
|
|
|
+ this.resArr.push(numList);
|
|
|
+ }
|
|
|
+ },
|
|
|
dialogClose() {
|
|
|
this.$emit('update:visible', false);
|
|
|
this.numberPinyin = '';
|