├── .gitignore ├── README.md ├── README ├── Screenshot1.png ├── Screenshot1.webp ├── Screenshot2.png ├── Screenshot2.webp ├── Screenshot3.png ├── Screenshot3.webp ├── Screenshot4.png ├── Screenshot4.webp ├── Screenshot5.png ├── Screenshot5.webp ├── WordReadingCode.jpg └── WordReadingCode.webp ├── app.js ├── app.json ├── app.wxss ├── data ├── icon │ ├── back.svg │ ├── back_w.svg │ ├── book.png │ ├── book.svg │ ├── bookshelf.svg │ ├── cancel.svg │ ├── catalog.svg │ ├── clipboard.svg │ ├── clipboard_blue.svg │ ├── cloud.svg │ ├── cloud_blue.svg │ ├── cloud_download.svg │ ├── cloud_grey.svg │ ├── delete.svg │ ├── delete_red.svg │ ├── directory.svg │ ├── explainBox2.svg │ ├── image.svg │ ├── import.svg │ ├── me.png │ ├── me.svg │ ├── more.svg │ ├── phone.svg │ ├── plus.svg │ ├── plus_b.svg │ ├── read.svg │ ├── read_blue.svg │ ├── rename.svg │ ├── rename_cursor.svg │ ├── save.svg │ ├── save_blue.svg │ ├── save_w.svg │ ├── search.svg │ ├── search_w.svg │ ├── share.svg │ ├── share_grey.svg │ ├── sound.svg │ ├── store.png │ ├── tag.svg │ ├── tag_w.svg │ └── word.png ├── image.png ├── noneBookmark.svg ├── nullBookshelf.svg └── tabbar │ ├── bookshelf.png │ ├── bookshelf_b.png │ ├── find.png │ ├── find_b.png │ ├── me.png │ ├── me.svg │ ├── me_b.png │ ├── word.png │ ├── word_b.png │ ├── 书架 (1).svg │ ├── 书架.svg │ ├── 发现 (1).svg │ └── 词库管理.svg ├── js ├── bookshelfMgr.js ├── clipboard.js ├── dict.js └── setNavHeight.wxs ├── pages ├── bookshelf │ ├── README.md │ ├── bookshelf.js │ ├── bookshelf.json │ ├── bookshelf.wxml │ ├── bookshelf.wxs │ └── bookshelf.wxss ├── logs │ ├── logs.js │ ├── logs.json │ ├── logs.wxml │ └── logs.wxss ├── me │ ├── me.js │ ├── me.json │ ├── me.wxml │ ├── me.wxs │ └── me.wxss ├── reading │ ├── reading.js │ ├── reading.json │ ├── reading.wxml │ ├── reading.wxs │ └── reading.wxss ├── store │ ├── store.js │ ├── store.json │ ├── store.wxml │ ├── store.wxs │ └── store.wxss ├── storeList │ ├── storeList.js │ ├── storeList.json │ ├── storeList.wxml │ ├── storeList.wxs │ └── storeList.wxss └── wordbook │ ├── wordbook.js │ ├── wordbook.json │ ├── wordbook.wxml │ └── wordbook.wxss ├── project.config.json ├── sitemap.json ├── template ├── template.wxml └── template.wxss └── utils └── util.js /.gitignore: -------------------------------------------------------------------------------- 1 | # Windows 2 | [Dd]esktop.ini 3 | Thumbs.db 4 | $RECYCLE.BIN/ 5 | 6 | # macOS 7 | .DS_Store 8 | .fseventsd 9 | .Spotlight-V100 10 | .TemporaryItems 11 | .Trashes 12 | 13 | # Node.js 14 | node_modules/ 15 | 16 | # CloudFunction 云函数 17 | cloudFunction/ 18 | 19 | # WordReading 20 | js/bookshelfMgr.md 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 划词英语阅读 2 | 微信小程序-划词英语阅读是一款学习类小程序。 3 | 划词英语阅读实现了点击查词,横向滑动翻译,单词朗读、句子朗读,是学习英语的好助手。阅读内容可由剪贴板导入。 4 | 5 | 此项目目前还有很多不完善的地方,由于时间精力的原因生词本功能还未实现。也欢迎大家对此提出意见和建议,不断优化更新,一起学习进步。 6 | 7 | 😁star鼓励下? 8 | 9 | 10 | # 扫码体验-划词英语阅读 11 | ![划词英语阅读小程序码](./README/WordReadingCode.webp) 12 | 13 | 14 | # 截图 15 | ### 书架页 16 | ![](./README/Screenshot1.webp) 17 | ### 阅读页 - 点击查词 18 | ![](./README/Screenshot2.webp) 19 | ### 阅读页 - 横向滑动翻译 20 | ![](./README/Screenshot3.webp) 21 | ### 阅读页 - 翻译框内点击查词 22 | ![](./README/Screenshot4.webp) 23 | ### 阅读页 - 输入查词 24 | ![](./README/Screenshot5.webp) 25 | 26 | # 目前遇到的问题及设想 27 | ## 问题一:错词 28 | 由pdf、ppt等格式导入的文本中常常会出现两个单词连在一起的现象(中间缺少空格),或是OCR识别的文本常常含有错词。这种情况下查词效率很低,ps:可以通过键盘输入查词。 29 | 需要开发一个可以纠正错词,拆分连在一起的两个词的程序或者接口。 30 | 31 | ## 问题二:阅读排版格式 32 | 目前阅读界面的所有文本字体大小颜色都一样,阅读时重点不突出,且没有图片。阅读较为枯燥。 33 | 34 | 目前设想过让阅读界面支持Markdown语法或是简单的一些HTML标签,但是在小程序这个平台约束较多。 35 | 36 | # 项目说明 37 | 此项目的所有源文件仅可用做学习用途! 38 | -------------------------------------------------------------------------------- /README/Screenshot1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baotlake/WordReading/a05ee9264d7fc8d085b4d550bf2c51310e4eb8bd/README/Screenshot1.png -------------------------------------------------------------------------------- /README/Screenshot1.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baotlake/WordReading/a05ee9264d7fc8d085b4d550bf2c51310e4eb8bd/README/Screenshot1.webp -------------------------------------------------------------------------------- /README/Screenshot2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baotlake/WordReading/a05ee9264d7fc8d085b4d550bf2c51310e4eb8bd/README/Screenshot2.png -------------------------------------------------------------------------------- /README/Screenshot2.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baotlake/WordReading/a05ee9264d7fc8d085b4d550bf2c51310e4eb8bd/README/Screenshot2.webp -------------------------------------------------------------------------------- /README/Screenshot3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baotlake/WordReading/a05ee9264d7fc8d085b4d550bf2c51310e4eb8bd/README/Screenshot3.png -------------------------------------------------------------------------------- /README/Screenshot3.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baotlake/WordReading/a05ee9264d7fc8d085b4d550bf2c51310e4eb8bd/README/Screenshot3.webp -------------------------------------------------------------------------------- /README/Screenshot4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baotlake/WordReading/a05ee9264d7fc8d085b4d550bf2c51310e4eb8bd/README/Screenshot4.png -------------------------------------------------------------------------------- /README/Screenshot4.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baotlake/WordReading/a05ee9264d7fc8d085b4d550bf2c51310e4eb8bd/README/Screenshot4.webp -------------------------------------------------------------------------------- /README/Screenshot5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baotlake/WordReading/a05ee9264d7fc8d085b4d550bf2c51310e4eb8bd/README/Screenshot5.png -------------------------------------------------------------------------------- /README/Screenshot5.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baotlake/WordReading/a05ee9264d7fc8d085b4d550bf2c51310e4eb8bd/README/Screenshot5.webp -------------------------------------------------------------------------------- /README/WordReadingCode.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baotlake/WordReading/a05ee9264d7fc8d085b4d550bf2c51310e4eb8bd/README/WordReadingCode.jpg -------------------------------------------------------------------------------- /README/WordReadingCode.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baotlake/WordReading/a05ee9264d7fc8d085b4d550bf2c51310e4eb8bd/README/WordReadingCode.webp -------------------------------------------------------------------------------- /app.js: -------------------------------------------------------------------------------- 1 | //app.js 2 | App({ 3 | onLaunch: function () { 4 | // 展示本地存储能力 5 | var logs = wx.getStorageSync('logs') || [] 6 | logs.unshift(Date.now()) 7 | wx.setStorageSync('logs', logs) 8 | 9 | // 登录 10 | wx.login({ 11 | success: res => { 12 | // 发送 res.code 到后台换取 openId, sessionKey, unionId 13 | // console.log('wx.getUserInfo -> res',res) 14 | } 15 | }) 16 | // 获取用户信息 17 | wx.getSetting({ 18 | success: res => { 19 | if (res.authSetting['scope.userInfo']) { 20 | // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框 21 | wx.getUserInfo({ 22 | success: res => { 23 | // 可以将 res 发送给后台解码出 unionId 24 | this.globalData.userInfo = res.userInfo 25 | 26 | // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回 27 | // 所以此处加入 callback 以防止这种情况 28 | if (this.userInfoReadyCallback) { 29 | this.userInfoReadyCallback(res) 30 | } 31 | } 32 | }) 33 | } 34 | } 35 | }) 36 | // 云服务初始化 37 | wx.cloud.init({ 38 | env: 'release-bf6b22' 39 | }) 40 | // 检查是否获取到OpenId 41 | var app = this 42 | wx.getStorage({ 43 | key:'openid', 44 | success(res){ 45 | console.log('getStorage openid ->',res) 46 | if(res.data == ''){ 47 | console.log('storage openid 为空') 48 | app.storageOpenId() 49 | } 50 | }, 51 | fail(res){ 52 | console.log('getStorage fail ->',res) 53 | // 获取并缓存OpenID 54 | app.storageOpenId() 55 | } 56 | }) 57 | 58 | }, 59 | globalData: { 60 | userInfo: null, 61 | settings: {}, 62 | }, 63 | getOpenId:async function(){ 64 | // 调用云函数 ->获取OpenId, 65 | var openId = await new Promise ((resolve,reject)=>{ 66 | wx.cloud.callFunction({ 67 | name: 'getOpenId', 68 | // complete: res => { 69 | // // console.log('call function test result', res) 70 | // wx.setStorage({ 71 | // key: 'openid', 72 | // data: res.result.openid 73 | // }) 74 | // resolve(res.result) 75 | // } 76 | }).then(res=>{ 77 | // console.log('promise then ->',res.result.openid) 78 | var openid = res.result.openid 79 | resolve(openid) 80 | }) 81 | }) 82 | // console.log('getopenID return openid =======',openId) 83 | return openId 84 | }, 85 | storageOpenId: async function(){ 86 | // console.log('--------缓存openId -----------') 87 | var openId = await this.getOpenId() 88 | console.log('point - openid awit after') 89 | wx.setStorage({ 90 | key:'openid', 91 | data:openId 92 | }) 93 | console.log('------------------storage - openID -> ',openId) 94 | }, 95 | setBookHistory:function(index,id,history){ 96 | let bookmgr = require('./js/bookshelfMgr.js'); 97 | let bookMgr = new bookmgr.bookshelfClass() 98 | bookMgr.setHistory(index, id, history) 99 | console.log('set history finish...') 100 | }, 101 | setting: function(key,value){ 102 | // key设置键名 value设置值, setting对value不做识别、判断,只负责储存、同步 103 | let setting = wx.getStorageInfoSync('setting'); 104 | if (Object.prototype.toString.call(setting) != "[object Object]"){ 105 | // 异常, 重置 106 | setting = {} 107 | } 108 | 109 | //添加&更新 110 | setting[key] = value; 111 | this.globalData.setting = setting; 112 | 113 | // 储存 114 | wx.setStorageSync({ 115 | key:'setting', 116 | data:setting 117 | }) 118 | }, 119 | 120 | }) -------------------------------------------------------------------------------- /app.json: -------------------------------------------------------------------------------- 1 | { 2 | "pages": [ 3 | "pages/bookshelf/bookshelf", 4 | "pages/reading/reading", 5 | "pages/logs/logs", 6 | "pages/wordbook/wordbook", 7 | "pages/me/me", 8 | "pages/store/store", 9 | "pages/storeList/storeList" 10 | ], 11 | "window": { 12 | "navigationStyle": "custom", 13 | "backgroundTextStyle": "light", 14 | "navigationBarBackgroundColor": "#fff", 15 | "navigationBarTitleText": "WeChat", 16 | "navigationBarTextStyle": "black" 17 | }, 18 | "requiredBackgroundModes": [ 19 | "audio" 20 | ], 21 | "tabBar": { 22 | "color": "#888888", 23 | "selectedColor": "#1c80ff", 24 | "borderStyle": "black", 25 | "backgroundColor": "#ffffff", 26 | "list": [ 27 | { 28 | "pagePath": "pages/bookshelf/bookshelf", 29 | "iconPath": "data/tabbar/bookshelf_b.png", 30 | "selectedIconPath": "data/tabbar/bookshelf.png", 31 | "text": "书架" 32 | }, 33 | { 34 | "pagePath": "pages/store/store", 35 | "iconPath": "data/tabbar/find_b.png", 36 | "selectedIconPath": "data/tabbar/find.png", 37 | "text": "发现" 38 | }, 39 | { 40 | "pagePath": "pages/wordbook/wordbook", 41 | "iconPath": "data/tabbar/word_b.png", 42 | "selectedIconPath": "data/tabbar/word.png", 43 | "text": "生词本" 44 | }, 45 | { 46 | "pagePath": "pages/me/me", 47 | "iconPath": "data/tabbar/me_b.png", 48 | "selectedIconPath": "data/tabbar/me.png", 49 | "text": "我" 50 | } 51 | ] 52 | }, 53 | "plugins": { 54 | "WechatSI": { 55 | "version": "0.3.0", 56 | "provider": "wx069ba97219f66d99" 57 | } 58 | }, 59 | "sitemapLocation": "sitemap.json" 60 | } -------------------------------------------------------------------------------- /app.wxss: -------------------------------------------------------------------------------- 1 | /**app.wxss**/ 2 | .container { 3 | height: 100%; 4 | display: flex; 5 | flex-direction: column; 6 | align-items: center; 7 | justify-content: space-between; 8 | padding: 200rpx 0; 9 | box-sizing: border-box; 10 | } -------------------------------------------------------------------------------- /data/icon/back.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /data/icon/back_w.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /data/icon/book.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baotlake/WordReading/a05ee9264d7fc8d085b4d550bf2c51310e4eb8bd/data/icon/book.png -------------------------------------------------------------------------------- /data/icon/book.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /data/icon/bookshelf.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 8 | 11 | 14 | 15 | -------------------------------------------------------------------------------- /data/icon/cancel.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /data/icon/catalog.svg: -------------------------------------------------------------------------------- 1 | catalog -------------------------------------------------------------------------------- /data/icon/clipboard.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /data/icon/clipboard_blue.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 8 | 16 | 17 | -------------------------------------------------------------------------------- /data/icon/cloud.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /data/icon/cloud_blue.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 8 | 12 | 13 | -------------------------------------------------------------------------------- /data/icon/cloud_download.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 10 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /data/icon/cloud_grey.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /data/icon/delete.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /data/icon/delete_red.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 8 | 13 | 15 | 17 | 18 | -------------------------------------------------------------------------------- /data/icon/directory.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /data/icon/explainBox2.svg: -------------------------------------------------------------------------------- 1 | explainBox@ -------------------------------------------------------------------------------- /data/icon/image.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /data/icon/import.svg: -------------------------------------------------------------------------------- 1 | import -------------------------------------------------------------------------------- /data/icon/me.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baotlake/WordReading/a05ee9264d7fc8d085b4d550bf2c51310e4eb8bd/data/icon/me.png -------------------------------------------------------------------------------- /data/icon/me.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /data/icon/more.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /data/icon/phone.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /data/icon/plus.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /data/icon/plus_b.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /data/icon/read.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /data/icon/read_blue.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /data/icon/rename.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /data/icon/rename_cursor.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /data/icon/save.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /data/icon/save_blue.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /data/icon/save_w.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /data/icon/search.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /data/icon/search_w.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /data/icon/share.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 8 | 13 | 14 | -------------------------------------------------------------------------------- /data/icon/share_grey.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 8 | 13 | 14 | -------------------------------------------------------------------------------- /data/icon/sound.svg: -------------------------------------------------------------------------------- 1 | sound -------------------------------------------------------------------------------- /data/icon/store.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baotlake/WordReading/a05ee9264d7fc8d085b4d550bf2c51310e4eb8bd/data/icon/store.png -------------------------------------------------------------------------------- /data/icon/tag.svg: -------------------------------------------------------------------------------- 1 | tag -------------------------------------------------------------------------------- /data/icon/tag_w.svg: -------------------------------------------------------------------------------- 1 | tag -------------------------------------------------------------------------------- /data/icon/word.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baotlake/WordReading/a05ee9264d7fc8d085b4d550bf2c51310e4eb8bd/data/icon/word.png -------------------------------------------------------------------------------- /data/image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baotlake/WordReading/a05ee9264d7fc8d085b4d550bf2c51310e4eb8bd/data/image.png -------------------------------------------------------------------------------- /data/noneBookmark.svg: -------------------------------------------------------------------------------- 1 | 未标题-1还没有书签哦 -------------------------------------------------------------------------------- /data/nullBookshelf.svg: -------------------------------------------------------------------------------- 1 | nullBookshelf书架还没有书 -------------------------------------------------------------------------------- /data/tabbar/bookshelf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baotlake/WordReading/a05ee9264d7fc8d085b4d550bf2c51310e4eb8bd/data/tabbar/bookshelf.png -------------------------------------------------------------------------------- /data/tabbar/bookshelf_b.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baotlake/WordReading/a05ee9264d7fc8d085b4d550bf2c51310e4eb8bd/data/tabbar/bookshelf_b.png -------------------------------------------------------------------------------- /data/tabbar/find.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baotlake/WordReading/a05ee9264d7fc8d085b4d550bf2c51310e4eb8bd/data/tabbar/find.png -------------------------------------------------------------------------------- /data/tabbar/find_b.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baotlake/WordReading/a05ee9264d7fc8d085b4d550bf2c51310e4eb8bd/data/tabbar/find_b.png -------------------------------------------------------------------------------- /data/tabbar/me.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baotlake/WordReading/a05ee9264d7fc8d085b4d550bf2c51310e4eb8bd/data/tabbar/me.png -------------------------------------------------------------------------------- /data/tabbar/me.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /data/tabbar/me_b.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baotlake/WordReading/a05ee9264d7fc8d085b4d550bf2c51310e4eb8bd/data/tabbar/me_b.png -------------------------------------------------------------------------------- /data/tabbar/word.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baotlake/WordReading/a05ee9264d7fc8d085b4d550bf2c51310e4eb8bd/data/tabbar/word.png -------------------------------------------------------------------------------- /data/tabbar/word_b.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baotlake/WordReading/a05ee9264d7fc8d085b4d550bf2c51310e4eb8bd/data/tabbar/word_b.png -------------------------------------------------------------------------------- /data/tabbar/书架 (1).svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /data/tabbar/书架.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /data/tabbar/发现 (1).svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /data/tabbar/词库管理.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /js/clipboard.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baotlake/WordReading/a05ee9264d7fc8d085b4d550bf2c51310e4eb8bd/js/clipboard.js -------------------------------------------------------------------------------- /js/setNavHeight.wxs: -------------------------------------------------------------------------------- 1 | 2 | 3 | function setNavHeight(systemInfo, oldValue, ownerInstance, instance){ 4 | console.log('set nav height--------------------------------') 5 | if(systemInfo){ 6 | console.log('适应 nav bar 高度========') 7 | var navBar = ownerInstance.selectComponent('.navigationBar') 8 | var navHeight; 9 | var system = systemInfo.system 10 | if (systemInfo.system.substring(0,2) == 'iOS') { 11 | navHeight = '44px' 12 | } else { 13 | navHeight = '48px' 14 | } 15 | navBar.setStyle({ 16 | 'padding-top': systemInfo.statusBarHeight + 'px', 17 | 'height': navHeight 18 | }) 19 | } 20 | } 21 | 22 | function setNavPadding(systemInfo, oldValue, ownerInstance, instance){ 23 | console.log('set nav height--------------------------------') 24 | if (systemInfo) { 25 | console.log('适应 nav bar 高度========') 26 | var navBar = ownerInstance.selectComponent('.navigationBar') 27 | var navHeight; 28 | var system = systemInfo.system 29 | // if (systemInfo.system.substring(0, 2) == 'iOS') { 30 | // navHeight = '44px' 31 | // } else { 32 | // navHeight = '48px' 33 | // } 34 | navBar.setStyle({ 35 | 'padding-top': systemInfo.statusBarHeight + 'px', 36 | }) 37 | } 38 | } 39 | 40 | 41 | module.exports = { 42 | setNavHeight:setNavHeight, 43 | setNavPadding: setNavPadding 44 | } -------------------------------------------------------------------------------- /pages/bookshelf/README.md: -------------------------------------------------------------------------------- 1 | book-more-box: 2 | 高度:42 x itemNum 3 | 42 x 6 = 252px 4 | 5 | more-box的操作菜单 6 | 取消 7 | 上传 8 | 分享 9 | 取消分享 10 | 重命名 11 | 删除 12 | 更多 13 | 14 | 15 | 不同情况 16 | 情况1:本地 未上传 未分享 | 17 | 18 | 情况2:本地 上传 未分享 | 19 | 20 | 情况3:本地 上传 分享 | 取消分享 分享码 21 | 22 | 情况4:云端 上传 未分享 | 23 | 24 | 情况5:云端 上传 分享 25 | 26 | 1-4: 本地 27 | 1-2:未上传 28 | 1:未分享 29 | 3-4:上传 30 | 3:未分享 31 | 4:分享 32 | 5-8:云端 33 | 5-6:上传 34 | 5:未分享 35 | 6:分享 36 | 37 | 38 | 待解决: 39 | 查词失败await没有返回,没有提示 40 | 句子读音能否播放的参数 变换 时间不太合理 41 | 42 | -------------------------------------------------------------------------------- /pages/bookshelf/bookshelf.js: -------------------------------------------------------------------------------- 1 | // pages/bookshelf/bookshelf.js 2 | const bookmgr = require('../../js/bookshelfMgr.js'); 3 | var bookMgr; 4 | var currentBook; // 当前将要进行操作的book, 使用完清空,避免误操作,{id:''} 5 | var inputText; // 记录输入的内容,使用完清空,避免混染 6 | var inputDo; // 记录调用input的原因,要干什么 7 | var booksList; 8 | var cloudBooksList; 9 | var bookshelf; // 当前页面引用, 用户setData或调用页面内函数 10 | 11 | 12 | async function getClipboardData(){ 13 | var data = await new Promise((resolve) => { 14 | wx.getClipboardData({ 15 | success(res) { 16 | resolve(res.data) 17 | } 18 | }) 19 | }) 20 | return data 21 | } 22 | 23 | /**返回text指定长度(l),多余的以‘...’显示 24 | * type='0' ,表示不区分中文、英文; 默认 25 | * type ='1', 表示区分中英文,一个中文相当于两个英文字母,l表示中文字数 26 | * 27 | */ 28 | function myTextSlice(text, l, type = '0') { 29 | if (text) { 30 | if (type == '0') { 31 | if (text.length >= 0) { 32 | return text.substring(0, l) + '...' 33 | } else { 34 | console.log('type 0 , 较短字符') 35 | return text 36 | } 37 | } else if (type == '1') { 38 | var returnText = '' 39 | var hanPattern = /[^\x00-\xff]/ 40 | if (text.length > l) { 41 | l = l * 2 42 | for (var i = 0; i < l; i++) { 43 | if (text.substring(i, i + 1).match(hanPattern)) { 44 | // 全角字符 \ 双字节字符 45 | returnText = returnText + text.substring(i, i + 1) 46 | l = l - 1 47 | } else if (text.substring(i, i + 1) == '') { 48 | console.log('遇到字符串结尾') 49 | // 字符串结尾 50 | return text 51 | } else { 52 | // 半角字符 53 | returnText = returnText + text.substring(i, i + 1) 54 | } 55 | } 56 | returnText = returnText + '...' 57 | } else { 58 | console.log('较短字符') 59 | returnText = text 60 | } 61 | return returnText 62 | } 63 | } 64 | } 65 | 66 | /**对书按时间排序 */ 67 | function collate(bookList){ 68 | let recentList = [bookList[0]]; 69 | for(let i=1; i=0;j--){ 71 | try{ 72 | var ri = recentList[j]['history']['time'] 73 | }catch(e){ 74 | var ri = 0 75 | } 76 | try { 77 | var bi = bookList[i]['history']['time'] 78 | } catch (e) { 79 | var bi = 0 80 | } 81 | if(ri >= bi){ 82 | recentList.splice(j+1, 0, bookList[i]) 83 | break 84 | }else if(j == 0){ 85 | recentList.splice(j, 0, bookList[i]) 86 | } 87 | } 88 | } 89 | console.log('排序结果->',recentList) 90 | return recentList 91 | } 92 | 93 | function historyInit(booksList){ 94 | let bookmgr = require('../../js/bookshelfMgr.js'); 95 | let bookMgr = new bookmgr.bookshelfClass() 96 | 97 | for(var i =0; i') 160 | bookMgr = new bookmgr.bookshelfClass() 161 | booksList = bookMgr.getBooksInfo() 162 | historyInit(booksList) // 兼容性初始化 163 | this.setData({ 164 | systemInfo:wx.getSystemInfoSync(), 165 | booksList:booksList 166 | }) 167 | // 云端book, 包含setData显示 168 | this.setCloudBookList() 169 | // collate(booksList) 170 | 171 | // test 172 | // getNewUserBooks() 173 | }, 174 | 175 | /** 176 | * 生命周期函数--监听页面初次渲染完成 177 | */ 178 | onReady: function () { 179 | 180 | }, 181 | 182 | /** 183 | * 生命周期函数--监听页面显示 184 | */ 185 | onShow: function () { 186 | this.refreshPage() 187 | }, 188 | 189 | /** 190 | * 生命周期函数--监听页面隐藏 191 | */ 192 | onHide: function () { 193 | 194 | }, 195 | 196 | /** 197 | * 生命周期函数--监听页面卸载 198 | */ 199 | onUnload: function () { 200 | 201 | }, 202 | 203 | /** 204 | * 页面相关事件处理函数--监听用户下拉动作 205 | */ 206 | onPullDownRefresh: function () { 207 | 208 | }, 209 | 210 | /** 211 | * 页面上拉触底事件的处理函数 212 | */ 213 | onReachBottom: function () { 214 | 215 | }, 216 | 217 | /** 218 | * 用户点击右上角分享 219 | */ 220 | onShareAppMessage: function () { 221 | 222 | }, 223 | 224 | /**点击书,进入目录或开始阅读 */ 225 | tapBook:async function(e){ 226 | console.log('tapBook ->', e.currentTarget.dataset.id) 227 | var id = e.currentTarget.dataset.id 228 | // 判断此Id是否在本地booKs中 229 | let check = bookMgr.getBookInfo(id) 230 | if(check[0] != undefined){ 231 | wx.navigateTo({ 232 | url: '../../pages/reading/reading?bookId=' + id 233 | }) 234 | }else{ 235 | // 判断是否在cloudBooks中 236 | let cloudCheck; 237 | for (let i in cloudBooksList){ 238 | if(id == cloudBooksList[i]['id']){ 239 | cloudCheck = true 240 | break 241 | } 242 | } 243 | if (cloudCheck){ 244 | // 存在于cloudBooks中 245 | wx.showLoading({ 246 | title:'下载中...' 247 | }) 248 | var ok; 249 | try{ 250 | ok = await bookMgr.downloadBook(id) 251 | }catch(e){} 252 | wx.hideLoading() 253 | if(ok = true){ 254 | wx.navigateTo({ 255 | url: '../../pages/reading/reading?bookId=' + id 256 | }) 257 | }else{ 258 | wx.showToast({ 259 | title:'下载出错,请重试!', 260 | icon:'none' 261 | }) 262 | } 263 | 264 | } 265 | } 266 | 267 | }, 268 | 269 | /**进入阅读界面,不传参数 */ 270 | toReadPage:function(){ 271 | wx.navigateTo({ 272 | url: '../../pages/reading/reading' 273 | }) 274 | }, 275 | 276 | /**进入阅读界面,并尝试获取剪贴板内容, */ 277 | getClipboard:function(){ 278 | wx.navigateTo({ 279 | url: '../../pages/reading/reading?todo=' + 'openClipboard' 280 | }) 281 | }, 282 | 283 | /**记录当前要操作或将要操作的book */ 284 | setCurrentBook:function(e){ 285 | console.log('set currentBook----') 286 | let id = e.currentTarget.dataset.id; 287 | // console.log('set current book ->',currentBook,e) 288 | let currentBookInfo = getBookInfo(id) 289 | let local; 290 | let upload; 291 | let share; 292 | let type = 1; 293 | if ('cloud' in currentBookInfo){ 294 | local = true; 295 | type = 1 296 | if (currentBookInfo.cloud.length > 0){ 297 | upload = true; 298 | type = 3 299 | } 300 | }else{ 301 | type = 5 302 | } 303 | // 全局变量记录 304 | currentBook = { 305 | id: id, 306 | bookshelf: e.currentTarget.dataset.w, 307 | type:type 308 | } 309 | if ('share' in currentBookInfo){ 310 | if (currentBookInfo.share.shareLink.length > 0){ 311 | share = true; 312 | type += 1 313 | } 314 | } 315 | 316 | let title = myTextSlice(currentBookInfo['title'], 6, '1') 317 | var page_currentBook = { 318 | title: title , 319 | type:type.toString() 320 | } 321 | this.setData({ 322 | currentBook: page_currentBook 323 | }) 324 | }, 325 | 326 | /**刷新页面数据*/ 327 | refreshPage:async function(){ 328 | var newBooksList = bookMgr.getBooksInfo() 329 | booksList = newBooksList 330 | this.setData({ 331 | booksList: booksList 332 | }) 333 | this.setCloudBookList(request=false) 334 | }, 335 | 336 | deleteBook:async function(e){ 337 | // test delete book 338 | var id = e.currentTarget.dataset.id 339 | let bookshelf; 340 | if(id == undefined && 'id' in currentBook){ 341 | id = currentBook['id'] 342 | bookshelf = currentBook.bookshelf 343 | currentBook = {} // 使用完清空 344 | } 345 | console.log('bookshelf ->',bookshelf) 346 | 347 | var bookInfo = bookMgr.getBookInfo(id) 348 | let isCloud = (bookshelf=="cloud")?'云端':'' 349 | var tip = `确认删除${isCloud}《${bookInfo[1]['title']}》吗?` 350 | var certain = await new Promise((resolve,reject)=>{ 351 | wx.showModal({ 352 | title: '删除', 353 | content: tip, 354 | success(res) { 355 | resolve(res.confirm) 356 | } 357 | }) 358 | }) 359 | 360 | if(certain && bookshelf=="cloud"){ 361 | // 仅删除云端 362 | console.log('仅删除云端') 363 | await bookMgr.deleteCloudBook(id) 364 | } else if (certain){ 365 | // 没有指定cloud,全删 366 | console.log('没有指定cloud,全删') 367 | await bookMgr.deleteBook(id) 368 | } 369 | // console.log('test_delete_book modal tip ->',certain) 370 | let that = this 371 | setTimeout(() => { 372 | this.refreshPage() 373 | }, 200) 374 | }, 375 | 376 | getInput: function(e){ 377 | inputText = e.detail.value 378 | 379 | }, 380 | 381 | inputDo:function(e){ 382 | if(inputDo == "newBook"){ 383 | this.saveBookByClipboard(e) 384 | }else{ 385 | this.renameTitle(e) 386 | } 387 | inputDo = '' 388 | }, 389 | 390 | renameTitle: function (e) { 391 | // console.log(e) 392 | if (e.currentTarget.dataset.certain == 'true') { 393 | //重命名 394 | var id = currentBook['id'] 395 | bookMgr.renameBook(id, inputText) 396 | inputText = '' // 清空 397 | this.refreshPage() 398 | } else { 399 | // 取消重命名 400 | wx.showToast({ 401 | title: '取消保存', 402 | icon: 'none' 403 | }) 404 | } 405 | if (this.data.inputBox) { 406 | this.setData({ 407 | inputBox: false, 408 | bookTitle: '' 409 | }) 410 | } else { 411 | this.setData({ 412 | inputBox: true, 413 | bookTitle: '' 414 | }) 415 | } 416 | inputText = '' // 用完清空,避免混染 417 | }, 418 | 419 | setInputText:function(e){ 420 | // inputText 421 | let type = e.currentTarget.dataset.type 422 | if (type == "bookTitle"){ 423 | // 给inputText赋值bookTitle,重命名书 424 | let id = currentBook['id'] 425 | let isCloud = currentBook['bookshelf'] 426 | let bookTitle = bookMgr.getBookInfo(id)[1]['title'] 427 | inputDo = "rename" 428 | this.setData({ 429 | inputText: bookTitle 430 | }) 431 | 432 | }else if(type == "newBook"){ 433 | // 设置默认新书书名 434 | inputDo = "newBook" 435 | this.setData({ 436 | inputText: 'new Book' 437 | }) 438 | inputText = 'new Book' 439 | } 440 | }, 441 | 442 | upload:async function(e){ 443 | // 上传至云端 444 | var id = e.currentTarget.dataset.id 445 | if (id == undefined && 'id' in currentBook) { 446 | id = currentBook['id'] 447 | currentBook = {} // 使用完清空 448 | } 449 | await bookMgr.uploadBook(id) 450 | that = this 451 | 452 | setTimeout((that)=>{ 453 | that.refreshPage() 454 | },200) 455 | 456 | }, 457 | 458 | shareBook:async function(e){ 459 | var id = e.currentTarget.dataset.id 460 | if (id == undefined && 'id' in currentBook) { 461 | id = currentBook['id'] 462 | currentBook = {} // 使用完清空 463 | } 464 | let shareLink = await bookMgr.shareBook(id) 465 | let bookTitle = bookMgr.getBookInfo(id)[1]['title'] 466 | shareLink = `我分享给你了《${bookTitle}》,快用英语划词阅读打开吧!share://${shareLink}/。` 467 | // shareLink复制到系统剪贴板 468 | wx.setClipboardData({ 469 | data: shareLink 470 | }) 471 | }, 472 | 473 | test:function(e){ 474 | console.log('test ->',e) 475 | }, 476 | 477 | tapBook_del:function(e){ 478 | console.log('e ->',e) 479 | }, 480 | 481 | // 获取分享的书,通过shareLink, 检查剪贴板 482 | getShareBook:async function (e) { 483 | let clip_data =await getClipboardData() 484 | if(clip_data.length <= 1000){ 485 | let shareLinkExtract = /^[\s\S]*?\b(\w+?&.+?&\w+?)\b[\s\S]*$/ 486 | let shareLink = clip_data.replace(shareLinkExtract,'$1') 487 | console.log('提取后的shareLink->',shareLink) 488 | if (shareLink.match(/\w+?&.+?&\w+?/) != null){ 489 | // 有效shareLink 490 | var bookMgr = new bookmgr.bookshelfClass() 491 | wx.showLoading({ 492 | title:'获取中...' 493 | }) 494 | console.log('shareLink ->',shareLink) 495 | var status = await bookMgr.addBookByShare(shareLink) 496 | wx.hideLoading() 497 | if(status.stats == 'ok'){ 498 | wx.showToast({ 499 | title:'添加成功!' 500 | }) 501 | // 刷新页面显示, 改在后面刷新 502 | // setTimeout((bookshelf) => { 503 | // bookshelf.refreshPage() 504 | // }, 200) 505 | }else{ 506 | wx.showToast({ 507 | title:"添加失败", 508 | icon:"none" 509 | }) 510 | } 511 | }else{ 512 | wx.showToast({ 513 | title: '剪贴板未发现分享链接!', 514 | icon: "none" 515 | }) 516 | } 517 | }else{ 518 | wx.showToast({ 519 | title:'剪贴板未发现分享链接!', 520 | icon:"none" 521 | }) 522 | } 523 | // 刷新页面显示 524 | setTimeout(() => { 525 | bookshelf.refreshPage() 526 | }, 200) 527 | }, 528 | 529 | // 保存剪贴板内容 530 | saveBookByClipboard: async function (e) { 531 | // 先隐藏inputBox 532 | // console.log(e) 533 | if (e.currentTarget.dataset.certain == 'true') { 534 | // 保存 535 | // var bookMgr = new bookmgr.bookshelfClass() 536 | // bookMgr.addBookByText(article.article, inputText) 537 | let clipboardData = await getClipboardData() 538 | // console.log('clipboard data ->',gcb.clipboardData) 539 | var bookMgr = new bookmgr.bookshelfClass() 540 | console.log('inputTest ->',inputText) 541 | await bookMgr.addBookByText(clipboardData, inputText) 542 | } else { 543 | // 取消保存 544 | wx.showToast({ 545 | title: '取消保存', 546 | icon: 'none' 547 | }) 548 | } 549 | // 无论是否保存,清空page.data中的inputText 550 | if (this.data.inputBox) { 551 | this.setData({ 552 | inputBox: false, 553 | inputText: '' 554 | }) 555 | } else { 556 | this.setData({ 557 | inputBox: true, 558 | inputText: '' 559 | }) 560 | } 561 | inputText = '' // 用完清空,避免混染 562 | this.refreshPage() 563 | }, 564 | 565 | /**显示云端book list*/ 566 | setCloudBookList:async function(request=true){ 567 | if (request) cloudBooksList = await bookMgr.getCloudBooksList() 568 | // 检查bookList 在本地有没有 569 | for(let i in cloudBooksList){ 570 | cloudBooksList[i]['info'] = {len:cloudBooksList[i]['len']}; 571 | delete cloudBooksList.len; 572 | for (let j in booksList){ 573 | if(cloudBooksList[i]['id'] == booksList[j]['id']){ 574 | // cloud book 同时在本地存在 575 | // 重命名 不会更改 云端title 576 | booksList[j]['title'] = cloudBooksList[i]['title'] 577 | cloudBooksList[i] = booksList[j]; 578 | break; 579 | } 580 | } 581 | } 582 | // 显示 583 | if (cloudBooksList){ 584 | this.setData({ 585 | cloudBooksList: cloudBooksList 586 | }) 587 | } 588 | }, 589 | 590 | /**下载云端book */ 591 | download:async function(e){ 592 | var id = e.currentTarget.dataset.id 593 | if (id == undefined && 'id' in currentBook) { 594 | id = currentBook['id'] 595 | bookshelf = currentBook.bookshelf 596 | currentBook = {} // 使用完清空 597 | } 598 | // 判断是否在cloudBooks中 599 | let cloudCheck; 600 | for (let i in cloudBooksList) { 601 | if (id == cloudBooksList[i]['id']) { 602 | cloudCheck = true 603 | break 604 | } 605 | } 606 | if (cloudCheck) { 607 | // 存在于cloudBooks中 608 | var ok; 609 | wx.showToast({ 610 | title: '开始下载...', 611 | icon:'none' 612 | }) 613 | try { 614 | ok = await bookMgr.downloadBook(id) 615 | } catch (e) { } 616 | wx.showToast({ 617 | title: '下载完成!' 618 | }) 619 | }else{ 620 | wx.showToast({ 621 | title: '发生错误,未下载!', 622 | icon:'none' 623 | }) 624 | } 625 | }, 626 | 627 | /**取消分享, 取消后,用分享口令无法获取到这本书*/ 628 | cancelShare:async function(e){ 629 | 630 | } 631 | 632 | }) 633 | 634 | -------------------------------------------------------------------------------- /pages/bookshelf/bookshelf.json: -------------------------------------------------------------------------------- 1 | { 2 | "usingComponents": {} 3 | } -------------------------------------------------------------------------------- /pages/bookshelf/bookshelf.wxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 最近{{(booksList.length >= 5)?' - 5':' - ' + booksList.length}} 18 | 19 | 20 | 21 | 22 |