import common from '../../utils/util'; import main from '../../utils/main'; import animation from '../../utils/animation'; import commonBehavior from '../../pages/behaviors/commonBehavior'; const Theme = [{ "Name": "DarkColor", "backgroundColor": "#004433", "color": "#C1E1C1", "frontColor": '#ffffff', }, { "Name": "LightColor", "backgroundColor": "#D0ECD3", "color": "#151815", "frontColor": '#000000', }]; const app = getApp(); var timeout1 = []; //用于判断是否是双击 var canSaveSchedule=1;//存进度 Page({ behaviors: [commonBehavior], data: { Words: "", IsShowLightColor: true, IsShowTranslate: false, IsShowWordTranslate: false, IsShowWordDetail: false, //显示单词细节 TranslateHeight: 100, //翻译单词框的高度 lastTapTime: 0, // 记录上一次点击的时间,用于检测双击 Percentage:0, }, onLoad: function (options) { let that = this; let IsShowLightColor = wx.getStorageSync('IsShowLightColor'); if (!IsShowLightColor) { IsShowLightColor = false; } that.setData({ Containnerheight: main.getWindowHeight(), IsShowLightColor: IsShowLightColor, Title:options.Title, Chapter:options.Chapter, }); wx.setNavigationBarTitle({ title: options.Chapter, }); that.init(options); that.setTheme(); setTimeout(function(){ wx.createSelectorQuery().select(".panel1").boundingClientRect(function (rect) { //console.log("rect.height:"+rect.height); that.setData({ ArticleHeight: rect.height, }); }).exec(); },1000); this.audioCtx = wx.createAudioContext('myAudio'); }, init: function (options) { let that = this; let chapter = options.Chapter.replace("Chapter ", ""); main.getData('GetReaderBooksChapterContent?UserID=' + app.globalData.userInfo.UserID + '&Title=' + options.Title + '&Chapter=' + chapter, function (data) { if (data) { data = that.updateData(data); let arr=[]; for(let i=0;i100) // num=100; // // 更新scrollTop数据 // that.setData({ // Percentage: num, // ScrollTop:schedule.ScrollTop, // }); wx.pageScrollTo({ scrollTop: schedule.ScrollTop, duration: 300, }); that.onPageScroll({scrollTop:schedule.ScrollTop}); } }, updateData: function (content) { let that = this; let arr1 = [], arr2 = []; for (let j = 0; j < content.length; j++) { arr2 = []; for (let i = 0; i < content[j].length; i++) { // 确保每个句子末尾有空格,避免和下一句紧挨着 let sentence = content[j][i]; if (sentence != "\"") { // 替换所有单引号为双引号,包括对话中的单引号和句尾的单引号 sentence = sentence.replace(/(^|[,.;:!?\s])'([^']+)'([,.;:!?]|\s|$)/g, '$1"$2"$3'); // 处理常见的带点缩写,将其中的点替换为特殊标记,以防止被分割 // 1. 称谓缩写 sentence = sentence.replace(/\b(Dr|Mr|Mrs|Ms|Prof)\./g, '$1@DOT@'); // 2. 时间缩写 sentence = sentence.replace(/\b([ap])\.m\./gi, '$1@DOT@m@DOT@'); // 3. 学位缩写 sentence = sentence.replace(/\b(B|M|Ph)\.([A-Z])\./gi, '$1@DOT@$2@DOT@'); // 4. 公司名称缩写 sentence = sentence.replace(/\b(Inc|Ltd|Co|Corp)\./g, '$1@DOT@'); // 5. 拉丁缩写 sentence = sentence.replace(/\b(e\.g|i\.e|etc|et al|vs)\./g, '$1@DOT@'); // 6. 军衔缩写 sentence = sentence.replace(/\b(Lt|Col|Gen|Sgt|Capt)\./g, '$1@DOT@'); // 7. 地理缩写 sentence = sentence.replace(/\b(St|Ave|Rd|Blvd)\./g, '$1@DOT@'); // 8. 其他常见缩写 sentence = sentence.replace(/\b(U\.S|U\.K|U\.N)\./g, '$1@DOT@'); // 先处理破折号,在破折号前后添加空格,使其成为独立元素 sentence = sentence.replace(/([^\s])([—\-–—])([^\s])/g, '$1 $2 $3'); // 将句子按空格分割成单词数组 let words = sentence.trim().split(/\s+/); // 将单词数组添加到ArticleEnglishArr arr2.push(words); } else arr2.push(sentence); } arr1.push(arr2); } content=arr1; // 在设置数据前,确保所有@DOT@都被替换回. that.replaceAllDOTMarkers(content); return content; }, // 替换Content对象中所有的@DOT@标记为. replaceAllDOTMarkers: function (obj) { if (!obj) return; // 如果是字符串,直接替换 if (typeof obj === 'string') { return obj.replace(/@DOT@/g, '.'); } // 如果是数组,递归处理每个元素 if (Array.isArray(obj)) { for (let i = 0; i < obj.length; i++) { if (typeof obj[i] === 'string') { obj[i] = obj[i].replace(/@DOT@/g, '.'); } else if (typeof obj[i] === 'object' && obj[i] !== null) { this.replaceAllDOTMarkers(obj[i]); } } return; } // 如果是对象,递归处理每个属性 if (typeof obj === 'object') { for (let key in obj) { if (obj.hasOwnProperty(key)) { if (typeof obj[key] === 'string') { obj[key] = obj[key].replace(/@DOT@/g, '.'); } else if (typeof obj[key] === 'object' && obj[key] !== null) { this.replaceAllDOTMarkers(obj[key]); } } } } }, setTheme: function () { let that = this; const css = Theme[that.data.IsShowLightColor ? 1 : 0]; wx.setNavigationBarColor({ frontColor: css.frontColor, backgroundColor: css.backgroundColor, }); wx.setBackgroundColor({ backgroundColor: css.backgroundColor, backgroundColorTop: css.backgroundColor, backgroundColorBottom: css.backgroundColor, }); that.setData({ ThemeCSS: css.Name, }); wx.setStorageSync('IsShowLightColor', that.data.IsShowLightColor); }, getSentenceTraslate: function (e) { let that = this; let index = e.currentTarget.dataset.index; let index2 = e.currentTarget.dataset.index2; that.setSelectedObject(e,true); let engSentence="", chnSentence; for(let i=0;i100) num=100; // 更新scrollTop数据 this.setData({ Percentage: num, ScrollTop:scrollTop, }); this.saveSchedule(); }, saveSchedule:function(){ if (canSaveSchedule){ let obj={}; obj.Chapter=this.data.Chapter; obj.ScrollTop=this.data.ScrollTop; if (!obj.ScrollTop) obj.ScrollTop=0; wx.setStorageSync('Schedule_'+this.data.Title, obj); canSaveSchedule=0; setTimeout(function(){ canSaveSchedule=1; },10000); } }, onUnload:function(){ this.saveSchedule(); }, catchTouchMove: main.catchTouchMove, onShareAppMessage: function () { return { title: app.globalData.ShareTitle, path: app.globalData.SharePath + '?goto=article&ID=' + this.data.ID + '&UserID=' + app.globalData.userInfo.UserID, } }, })