├── pages
├── read
│ ├── read.json
│ ├── read.wxml
│ ├── read.wxss
│ └── read.js
├── detail
│ ├── detail.json
│ ├── detail.wxml
│ ├── detail.wxss
│ └── detail.js
├── login
│ ├── login.json
│ ├── login.wxss
│ ├── login.wxml
│ └── login.js
├── mine
│ ├── mine.json
│ ├── mine.wxml
│ ├── mine.wxss
│ └── mine.js
├── about
│ ├── about.json
│ ├── about.wxss
│ ├── about.wxml
│ └── about.js
├── shelf
│ ├── shelf.json
│ ├── shelf.wxml
│ ├── shelf.wxss
│ └── shelf.js
├── register
│ ├── register.json
│ ├── register.wxss
│ ├── register.wxml
│ └── register.js
├── books
│ ├── books.json
│ ├── books.wxss
│ ├── books.wxml
│ └── books.js
└── index
│ ├── index.wxss
│ ├── index.wxml
│ └── index.js
├── wxapp.png
├── image
├── dev.png
├── ic_mine.png
├── empty-book.png
├── ic_chapter.png
├── ic_mine_HL.png
├── ic_shelf.png
├── ic_classify.png
├── ic_mine_arc.png
├── ic_shelf_HL.png
├── ic_classify_HL.png
└── ic_chapter_current.png
├── template
├── book-type-template
│ ├── book_type_template.wxml
│ └── book_type_template.wxss
├── empty-template
│ ├── empty_template.wxml
│ └── empty_template.wxss
├── index-template
│ ├── index_template.wxml
│ └── index_template.wxss
└── books-template
│ ├── books_template.wxml
│ └── books_template.wxss
├── app.js
├── README.md
├── app.wxss
├── style
└── weui-navbar.wxss
├── app.json
└── utils
├── dev_request.js
└── md5.js
/pages/read/read.json:
--------------------------------------------------------------------------------
1 | {}
--------------------------------------------------------------------------------
/pages/detail/detail.json:
--------------------------------------------------------------------------------
1 | {}
--------------------------------------------------------------------------------
/pages/login/login.json:
--------------------------------------------------------------------------------
1 | {"navigationBarTitleText":"登录"}
--------------------------------------------------------------------------------
/pages/mine/mine.json:
--------------------------------------------------------------------------------
1 | {"navigationBarTitleText": "我的"}
--------------------------------------------------------------------------------
/pages/about/about.json:
--------------------------------------------------------------------------------
1 | {"navigationBarTitleText":"关于作者"}
--------------------------------------------------------------------------------
/pages/shelf/shelf.json:
--------------------------------------------------------------------------------
1 | {"navigationBarTitleText": "书架"}
--------------------------------------------------------------------------------
/pages/register/register.json:
--------------------------------------------------------------------------------
1 | {"navigationBarTitleText": "注册"}
--------------------------------------------------------------------------------
/pages/books/books.json:
--------------------------------------------------------------------------------
1 | {
2 | "onReachBottomDistance": 1
3 | }
4 |
5 |
--------------------------------------------------------------------------------
/wxapp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LiangLuDev/WeYue-wxapp/HEAD/wxapp.png
--------------------------------------------------------------------------------
/image/dev.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LiangLuDev/WeYue-wxapp/HEAD/image/dev.png
--------------------------------------------------------------------------------
/image/ic_mine.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LiangLuDev/WeYue-wxapp/HEAD/image/ic_mine.png
--------------------------------------------------------------------------------
/image/empty-book.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LiangLuDev/WeYue-wxapp/HEAD/image/empty-book.png
--------------------------------------------------------------------------------
/image/ic_chapter.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LiangLuDev/WeYue-wxapp/HEAD/image/ic_chapter.png
--------------------------------------------------------------------------------
/image/ic_mine_HL.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LiangLuDev/WeYue-wxapp/HEAD/image/ic_mine_HL.png
--------------------------------------------------------------------------------
/image/ic_shelf.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LiangLuDev/WeYue-wxapp/HEAD/image/ic_shelf.png
--------------------------------------------------------------------------------
/image/ic_classify.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LiangLuDev/WeYue-wxapp/HEAD/image/ic_classify.png
--------------------------------------------------------------------------------
/image/ic_mine_arc.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LiangLuDev/WeYue-wxapp/HEAD/image/ic_mine_arc.png
--------------------------------------------------------------------------------
/image/ic_shelf_HL.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LiangLuDev/WeYue-wxapp/HEAD/image/ic_shelf_HL.png
--------------------------------------------------------------------------------
/image/ic_classify_HL.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LiangLuDev/WeYue-wxapp/HEAD/image/ic_classify_HL.png
--------------------------------------------------------------------------------
/image/ic_chapter_current.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LiangLuDev/WeYue-wxapp/HEAD/image/ic_chapter_current.png
--------------------------------------------------------------------------------
/template/book-type-template/book_type_template.wxml:
--------------------------------------------------------------------------------
1 |
2 | {{item}}
3 |
4 |
5 |
--------------------------------------------------------------------------------
/template/empty-template/empty_template.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | {{empty_msg}}
5 |
6 |
--------------------------------------------------------------------------------
/template/book-type-template/book_type_template.wxss:
--------------------------------------------------------------------------------
1 | .book_type_text{
2 | font-size: 25rpx;
3 | color: #00BCD4;
4 | border-radius: 30rpx;
5 | border: 2rpx solid black;
6 | padding: 0rpx 20rpx;
7 | display:inline-block;
8 | height: 40rpx;
9 | line-height: 40rpx;
10 | margin: 10rpx;
11 | }
--------------------------------------------------------------------------------
/app.js:
--------------------------------------------------------------------------------
1 | //app.js
2 | App({
3 | onLaunch: function () {
4 | // 打开调试
5 | wx.setEnableDebug({
6 | enableDebug: true
7 | })
8 | },
9 | globalData: {
10 | openid: 'openid',
11 | appid: 'wxcf431e81711984db',
12 | appsecret: '07a921c4ff08a0609411c25ed0c1fb08',
13 | user_info:'',
14 | }
15 | })
--------------------------------------------------------------------------------
/pages/about/about.wxss:
--------------------------------------------------------------------------------
1 | .page{
2 | display: flex;
3 | flex-direction: column;
4 | align-items: center;
5 | width: 100%;
6 | }
7 |
8 | .img_avatar {
9 | margin-top: 20rpx;
10 | width: 128rpx;
11 | height: 128rpx;
12 | border-radius: 50%;
13 | }
14 |
15 | .about_v{
16 | font-size: 28rpx;
17 | color: black;
18 | margin: 20rpx;
19 | }
--------------------------------------------------------------------------------
/template/index-template/index_template.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | {{name}}
5 | {{bookCount}}本
6 |
7 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ### 微Yue电子书阅读-微信小程序
2 | #### 前言
3 | > 微信小程序依赖微信,趋势所向,闲暇之余翻翻官方api,根据Android版学习写了一个小程序。
4 | #### 功能模块
5 | > 主要是用来练手学习小程序。
6 | - 登录注册
7 | - 添加书架
8 | - 阅读书籍
9 | - 书籍分类
10 |
11 | #### 小程序预览
12 | 
13 | #### 小程序体验
14 | > 因为书籍类小程序需要以企业身份上架,所以没法以小程序二维码的方式体验。
15 |
16 | 想要体验的直接使用
17 | ```git clone https://github.com/LiangLuDev/WeYue-wxapp.git```
18 | 导入到微信开发者工具里面就能直接跑起来。
19 |
20 |
21 |
--------------------------------------------------------------------------------
/pages/about/about.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 作者是Android Developer,开发这个小程序的辛酸历程(只有我懂),官方api是最好的教程,本项目设计主要是来源于Android端,后端使用NodeJs,有很多不足,谅解(毕竟第一次)
5 |
6 |
7 |
8 | 项目GitHub地址
9 | https://github.com/LiangLuDev/WeYue-wxapp
10 |
--------------------------------------------------------------------------------
/template/empty-template/empty_template.wxss:
--------------------------------------------------------------------------------
1 | .empty-view-content {
2 | width: 100%;
3 | min-height: 500px;
4 | display: flex;
5 | flex-direction: column;
6 | justify-content: center;
7 | align-items: center;
8 | }
9 |
10 | .empty-image {
11 | width: 89rpx;
12 | height: 64rpx;
13 | }
14 |
15 | .empty-text {
16 | color: #333333;
17 | margin-top: 20rpx;
18 | font-size: 25rpx;
19 | }
--------------------------------------------------------------------------------
/pages/books/books.wxss:
--------------------------------------------------------------------------------
1 | @import "../../template/books-template/books_template.wxss";
2 | @import "../../template/empty-template/empty_template.wxss";
3 | page, .page, .page__bd {
4 | height: 100%;
5 |
6 | }
7 |
8 | ::-webkit-scrollbar {
9 | width: 0;
10 | height: 0;
11 | color: transparent;
12 | }
13 |
14 | .page__bd {
15 | padding-bottom: 0;
16 | }
17 |
18 | .weui-tab__content {
19 | padding-top: 50px;
20 | }
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/pages/index/index.wxss:
--------------------------------------------------------------------------------
1 | @import "../../template/index-template/index_template.wxss";
2 |
3 | page, .page, .page__bd {
4 | height: 100%;
5 | }
6 |
7 | ::-webkit-scrollbar {
8 | width: 0;
9 | height: 0;
10 | color: transparent
11 | }
12 |
13 | .page__bd {
14 | padding-bottom: 0;
15 | }
16 |
17 | .weui-tab__content {
18 | padding-top: 50px;
19 | text-align: center;
20 | background-color: #fafafa;
21 | }
22 |
23 | .tab-view {
24 | background-color: #fafafa;
25 | }
26 |
27 |
--------------------------------------------------------------------------------
/app.wxss:
--------------------------------------------------------------------------------
1 | /**app.wxss**/
2 | @import 'style/weui-navbar.wxss';
3 |
4 | page {
5 | background-color: #f8f8f8;
6 | font-size: 16px;
7 | font-family: -apple-system-font, Helvetica Neue, Helvetica, sans-serif;
8 | font-family: '微软雅黑', Helvetica, 'Hiragino Sans GB', 'Microsoft Yahei', Arial, sans-serif;
9 | }
10 |
11 | .container {
12 | height: 100%;
13 | display: flex;
14 | flex-direction: column;
15 | align-items: center;
16 | justify-content: space-between;
17 | padding: 200rpx 0;
18 | box-sizing: border-box;
19 | }
20 |
--------------------------------------------------------------------------------
/pages/mine/mine.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | {{username}}
9 |
10 | 关于作者
11 |
12 | 退出登录
13 |
14 |
15 |
--------------------------------------------------------------------------------
/pages/login/login.wxss:
--------------------------------------------------------------------------------
1 | .input-username {
2 | border: 1px solid lightgrey;
3 | height: 60rpx;
4 | padding-left: 20rpx;
5 | margin: 20rpx;
6 | border-radius: 8rpx;
7 | font-size: 25rpx;
8 | }
9 |
10 | .text-username{
11 | display: flex;
12 | margin-top:10rpx;
13 | margin-left: 20rpx;
14 | font-size: 25rpx;
15 | }
16 |
17 | .button-confirm{
18 | font-size: 28rpx;
19 | margin-top: 20rpx;
20 | margin-left: 20rpx;
21 | margin-right: 20rpx;
22 | background-color: #00BCD4;
23 | color: #f0f0f0;
24 | height: 70rpx;
25 | }
--------------------------------------------------------------------------------
/pages/register/register.wxss:
--------------------------------------------------------------------------------
1 | .input-username {
2 | border: 1px solid lightgrey;
3 | height: 60rpx;
4 | padding-left: 20rpx;
5 | margin: 20rpx;
6 | border-radius: 8rpx;
7 | font-size: 25rpx;
8 | }
9 |
10 | .text-username{
11 | display: flex;
12 | margin-top:10rpx;
13 | margin-left: 20rpx;
14 | font-size: 25rpx;
15 | }
16 |
17 | .button-confirm{
18 | font-size: 28rpx;
19 | margin-top: 20rpx;
20 | margin-left: 20rpx;
21 | margin-right: 20rpx;
22 | background-color: #00BCD4;
23 | color: #f0f0f0;
24 | height: 70rpx;
25 | }
--------------------------------------------------------------------------------
/pages/login/login.wxml:
--------------------------------------------------------------------------------
1 |
2 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/pages/register/register.wxml:
--------------------------------------------------------------------------------
1 |
2 |
18 |
19 |
--------------------------------------------------------------------------------
/template/index-template/index_template.wxss:
--------------------------------------------------------------------------------
1 |
2 | .classify__content {
3 | display: flex;
4 | flex-direction: row;
5 | background-color: white;
6 | border-radius: 10rpx;
7 | box-shadow:6rpx 6rpx 6rpx rgba(0,0,0,0.1);
8 | text-align: left;
9 | align-items: center;
10 | border-bottom: 1px solid #f0f0f0;
11 | padding: 20rpx;
12 | margin: 20rpx;
13 |
14 | }
15 |
16 | .classify__image {
17 | width: 40rpx;
18 | height: 40rpx;
19 | margin-left: 10rpx;
20 | }
21 |
22 | .classify__text__name {
23 | padding-left: 30rpx;
24 | font-size: 28rpx;
25 | color: black;
26 | }
27 |
28 | .classify__text__count {
29 | padding-right: 30rpx;
30 | text-align: right;
31 | font-size: 24rpx;
32 | color: #666;
33 | flex: 1;
34 | }
--------------------------------------------------------------------------------
/pages/shelf/shelf.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 | {{item.title}}
12 | 最新更新:{{item.lastChapter}}
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/pages/shelf/shelf.wxss:
--------------------------------------------------------------------------------
1 | .tab-view {
2 | background-color: #fafafa;
3 | }
4 |
5 | .book__content {
6 | margin: 20rpx;
7 | display: flex;
8 | flex-direction: row;
9 | padding-top: 5px;
10 | padding-bottom: 5px;
11 | background-color: white;
12 | border-radius: 10rpx;
13 | box-shadow:6rpx 6rpx 6rpx rgba(0,0,0,0.1);
14 |
15 | }
16 |
17 | .book__image {
18 | width: 65px;
19 | height: 87px;
20 | margin-left: 10rpx;
21 | }
22 |
23 | .book_text {
24 | display: flex;
25 | flex-direction: column;
26 | width: 75%;
27 | margin-left: 10rpx;
28 | }
29 |
30 | .book__text__title {
31 | color: #515151;
32 | font-size: 30rpx;
33 | }
34 |
35 | .book__text__brief {
36 | display: block;
37 | overflow: hidden;
38 | text-overflow: ellipsis;
39 | white-space: nowrap;
40 | font-size: 28rpx;
41 | margin-top: 25rpx;
42 | color: #00BCD4;
43 | line-height: 30rpx;
44 | }
--------------------------------------------------------------------------------
/pages/about/about.js:
--------------------------------------------------------------------------------
1 | // pages/about/about.js
2 | Page({
3 |
4 | /**
5 | * 页面的初始数据
6 | */
7 | data: {
8 |
9 | },
10 |
11 | /**
12 | * 生命周期函数--监听页面加载
13 | */
14 | onLoad: function (options) {
15 |
16 | },
17 |
18 | /**
19 | * 生命周期函数--监听页面初次渲染完成
20 | */
21 | onReady: function () {
22 |
23 | },
24 |
25 | /**
26 | * 生命周期函数--监听页面显示
27 | */
28 | onShow: function () {
29 |
30 | },
31 |
32 | /**
33 | * 生命周期函数--监听页面隐藏
34 | */
35 | onHide: function () {
36 |
37 | },
38 |
39 | /**
40 | * 生命周期函数--监听页面卸载
41 | */
42 | onUnload: function () {
43 |
44 | },
45 |
46 | /**
47 | * 页面相关事件处理函数--监听用户下拉动作
48 | */
49 | onPullDownRefresh: function () {
50 |
51 | },
52 |
53 | /**
54 | * 页面上拉触底事件的处理函数
55 | */
56 | onReachBottom: function () {
57 |
58 | },
59 |
60 | /**
61 | * 用户点击右上角分享
62 | */
63 | onShareAppMessage: function () {
64 |
65 | }
66 | })
--------------------------------------------------------------------------------
/pages/mine/mine.wxss:
--------------------------------------------------------------------------------
1 | .page{
2 | display: flex;
3 | flex-direction: column;
4 | width: 100%;
5 | }
6 |
7 | .view-top{
8 | background: #00BCD4;
9 | width: inherit;
10 | height: 230rpx;
11 | }
12 |
13 | .arc_image{
14 | width:100%;
15 | height: 50rpx;
16 | }
17 | .user-view{
18 | display: flex;
19 | width: 100%;
20 | flex-direction: column;
21 | margin-top: -60rpx;
22 | align-items: center;
23 |
24 | }
25 |
26 | .img_avatar {
27 | width: 128rpx;
28 | height: 128rpx;
29 |
30 | border-radius: 50%;
31 | }
32 | .text_username{
33 | font-size: 30rpx;
34 | margin-top:15rpx;
35 | }
36 |
37 | .mine_view{
38 | margin: 20rpx;
39 | display: flex;
40 | flex-direction: row;
41 | padding-top: 15rpx;
42 | padding-bottom: 15rpx;
43 | background-color: white;
44 | border-radius: 10rpx;
45 | box-shadow:6rpx 6rpx 6rpx rgba(0,0,0,0.1);
46 | justify-content: center;
47 | font-size: 28rpx;
48 |
49 | }
--------------------------------------------------------------------------------
/template/books-template/books_template.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
5 |
6 |
7 | {{item.title}}
8 | {{item.author}} | {{item.majorCate}}
9 | {{item.longIntro}}
10 |
11 | {{item.latelyFollower}}
12 | 人气 |
13 | {{item.retentionRatio}}%
14 | 读者留存
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/style/weui-navbar.wxss:
--------------------------------------------------------------------------------
1 | .weui-navbar {
2 | display: -webkit-box;
3 | display: -webkit-flex;
4 | display: flex;
5 | position: fixed;
6 | z-index: 500;
7 | top: 0;
8 | width: 100%;
9 | background-color: #00BCD4;
10 | border-bottom: 1rpx solid #CCCCCC;
11 | }
12 | .weui-navbar__item {
13 | position: relative;
14 | display: block;
15 | -webkit-box-flex: 1;
16 | -webkit-flex: 1;
17 | flex: 1;
18 | padding: 13px 0;
19 | text-align: center;
20 | font-size: 0;
21 | color:#CCCCCC
22 | }
23 | .weui-navbar__item.weui-bar__item_on {
24 | color: white;
25 | }
26 | .weui-navbar__slider {
27 | position: absolute;
28 | content: " ";
29 | left: 0;
30 | bottom: 0;
31 | width: 6em;
32 | height: 3px;
33 | background-color: white;
34 | -webkit-transition: -webkit-transform .3s;
35 | transition: -webkit-transform .3s;
36 | transition: transform .3s;
37 | transition: transform .3s, -webkit-transform .3s;
38 | }
39 | .weui-navbar__title {
40 | display: inline-block;
41 | font-size: 15px;
42 | max-width: 8em;
43 | width: auto;
44 | overflow: hidden;
45 | text-overflow: ellipsis;
46 | white-space: nowrap;
47 | word-wrap: normal;
48 | }
49 |
--------------------------------------------------------------------------------
/pages/shelf/shelf.js:
--------------------------------------------------------------------------------
1 | var dev_request = require('../../utils/dev_request');
2 |
3 | Page({
4 |
5 | /**
6 | * 页面的初始数据
7 | */
8 | data: {
9 | isEmpty: false,
10 | empty_msg: 'Pen友,书架没书,赶紧添加几本吧',
11 | books: []
12 | },
13 |
14 | /**
15 | * 生命周期函数--监听页面加载
16 | */
17 | onLoad: function (options) {
18 |
19 |
20 | },
21 |
22 |
23 | onShow: function () {
24 | let that = this
25 | dev_request.Get('/user/bookshelf', function (books) {
26 | if (books.data.length > 0) {
27 | that.isEmpty = true
28 | books.data.forEach(function (item) {
29 | item.cover = dev_request.ZHUISHU_URL + item.cover
30 | })
31 | that.setData({
32 | books: books.data
33 | })
34 | } else {
35 | that.isEmpty = false
36 | }
37 | })
38 | },
39 |
40 | openBook: function (params) {
41 | let book=params.currentTarget.dataset.book
42 | wx.navigateTo({
43 | url: '../read/read?bookid=' + book._id + '&isCollect=' + book.isCollect + '&bookTitle=' + book.title
44 | })
45 | }
46 |
47 |
48 | })
--------------------------------------------------------------------------------
/pages/login/login.js:
--------------------------------------------------------------------------------
1 | // pages/login/login.js
2 |
3 | let dev_request = require('../../utils/dev_request');
4 | const app = getApp()
5 |
6 | Page({
7 |
8 | /**
9 | * 页面的初始数据
10 | */
11 | data: {},
12 |
13 | /**
14 | * 生命周期函数--监听页面加载
15 | */
16 | onLoad: function (options) {
17 |
18 | },
19 | //登录提交按钮
20 | formLogin: function (e) {
21 | console.log(e);
22 | let username = e.detail.value.username;
23 | let password = e.detail.value.password;
24 | if (username.length === 0 || password.length === 0) {
25 | wx.showToast({
26 | title: '用户名或密码不得为空!',
27 | icon: 'none',
28 | duration: 1000
29 | })
30 | } else {
31 | let data = {
32 | name: username,
33 | password: password
34 | }
35 | dev_request.Get('/user/login', data, function (res) {
36 | app.globalData.user_info=res.data
37 | wx.showToast({
38 | title: '登录成功',
39 | icon: 'success',
40 | duration: 1000
41 | })
42 | wx.navigateBack()//登录成功返回上一页
43 | })
44 | }
45 | }
46 |
47 | ,bindtapRegister:function () {
48 | wx.navigateTo({
49 | url:'../register/register'
50 | })
51 | }
52 |
53 | })
--------------------------------------------------------------------------------
/app.json:
--------------------------------------------------------------------------------
1 | {
2 | "pages": [
3 | "pages/index/index",
4 | "pages/mine/mine",
5 | "pages/shelf/shelf",
6 | "pages/books/books",
7 | "pages/login/login",
8 | "pages/register/register",
9 | "pages/detail/detail",
10 | "pages/read/read",
11 | "pages/about/about"
12 | ],
13 | "window": {
14 | "backgroundTextStyle": "light",
15 | "navigationBarBackgroundColor": "#00BCD4",
16 | "navigationBarTitleText": "微Yue电子书",
17 | "navigationBarTextStyle": "white"
18 | },
19 | "tabBar": {
20 | "color": "#666666",
21 | "selectedColor": "#00BCD4",
22 | "borderStyle": "black",
23 | "backgroundColor": "#ffffff",
24 | "list": [
25 | {
26 | "pagePath": "pages/index/index",
27 | "iconPath": "image/ic_classify.png",
28 | "selectedIconPath": "image/ic_classify_HL.png",
29 | "text": "分类"
30 | },
31 | {
32 | "pagePath": "pages/shelf/shelf",
33 | "iconPath": "image/ic_shelf.png",
34 | "selectedIconPath": "image/ic_shelf_HL.png",
35 | "text": "书架"
36 | },
37 | {
38 | "pagePath": "pages/mine/mine",
39 | "iconPath": "image/ic_mine.png",
40 | "selectedIconPath": "image/ic_mine_HL.png",
41 | "text": "我的"
42 | }
43 | ]
44 | },
45 | "networkTimeout": {
46 | "request": 10000,
47 | "connectSocket": 10000,
48 | "uploadFile": 10000,
49 | "downloadFile": 10000
50 | },
51 | "debug": false
52 | }
--------------------------------------------------------------------------------
/pages/register/register.js:
--------------------------------------------------------------------------------
1 | // pages/register/register.js
2 | let dev_request = require('../../utils/dev_request');
3 | let md5 = require('../../utils/md5');
4 | Page({
5 |
6 | /**
7 | * 页面的初始数据
8 | */
9 | data: {},
10 |
11 | /**
12 | * 生命周期函数--监听页面加载
13 | */
14 | onLoad: function (options) {
15 |
16 | },
17 |
18 | formRegister: function (e) {
19 | let username = e.detail.value.username;
20 | let password = e.detail.value.password;
21 | let confirm_password = e.detail.value.confirm_password;
22 |
23 | if (username.length === 0 || password.length === 0 || confirm_password.length === 0) {
24 | wx.showToast({
25 | title: '用户名或密码不得为空!',
26 | icon: 'none',
27 | duration: 1000
28 | })
29 | } else if (password !== confirm_password) {
30 | wx.showToast({
31 | title: '两次输入密码不一致!',
32 | icon: 'none',
33 | duration: 1000
34 | })
35 | } else {
36 | let data = {
37 | name: username,
38 | password: md5.hexMD5(password)
39 | }
40 | dev_request.Post('/user/register', data, function (res) {
41 | wx.showToast({
42 | title: res.data,
43 | icon: 'success',
44 | duration: 1000
45 | })
46 | wx.navigateBack()//登录成功返回上一页
47 | })
48 | }
49 | }
50 | })
--------------------------------------------------------------------------------
/pages/index/index.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | {{item}}
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/template/books-template/books_template.wxss:
--------------------------------------------------------------------------------
1 |
2 | .tab-view {
3 | background-color: #fafafa;
4 | }
5 |
6 | .book__content {
7 | margin: 20rpx;
8 | display: flex;
9 | flex-direction: row;
10 | padding-top: 10rpx;
11 | padding-bottom: 10rpx;
12 | background-color: white;
13 | border-radius: 10rpx;
14 | box-shadow:6rpx 6rpx 6rpx rgba(0,0,0,0.1);
15 |
16 | }
17 |
18 | .book_image_view {
19 | display: flex;
20 | justify-content: center;
21 | width: 25%;
22 | }
23 |
24 | .book__image {
25 | width: 65px;
26 | height: 87px;
27 | margin-left: 10rpx;
28 | }
29 |
30 | .book_text {
31 | display: flex;
32 | flex-direction: column;
33 | width: 75%;
34 | margin-left: 10rpx;
35 | }
36 |
37 | .book__text__title {
38 | color: #515151;
39 | font-size: 30rpx;
40 | }
41 |
42 | .book__text__author {
43 | display: block;
44 | overflow: hidden;
45 | text-overflow: ellipsis;
46 | white-space: nowrap;
47 | font-size: 25rpx;
48 | margin-top: 15rpx;
49 | color: #515151;
50 | height: 25rpx;
51 | line-height: 25rpx;
52 | }
53 |
54 | .book__text__brief {
55 | display: block;
56 | overflow: hidden;
57 | text-overflow: ellipsis;
58 | white-space: nowrap;
59 | font-size: 25rpx;
60 | margin-top: 15rpx;
61 | color: #515151;
62 | height: 25rpx;
63 | line-height: 25rpx;
64 | }
65 | .book_text_count{
66 | display: flex;
67 | flex-direction: row;
68 | margin-top: 15rpx;
69 | align-items: center;
70 | }
71 |
72 | .text_count{
73 | font-size: 25rpx;
74 | color: #00BCD4;
75 | }
76 | .text{
77 | font-size: 25rpx;
78 | color: #515151;
79 | }
--------------------------------------------------------------------------------
/pages/index/index.js:
--------------------------------------------------------------------------------
1 | var sliderWidth = 96; // 需要设置slider的宽度,用于计算中间位置
2 | var dev_request = require('../../utils/dev_request');
3 | Page({
4 | data: {
5 | tabs: ["男生", "女生", "出版"],
6 | classifys: {},
7 | activeIndex: 0,
8 | sliderOffset: 0,
9 | sliderLeft: 0,
10 | base_url: dev_request.BASE_URL
11 | },
12 | onLoad: function () {
13 | var that = this;
14 | wx.getSystemInfo({
15 | success: function (res) {
16 | that.setData({
17 | sliderLeft: (res.windowWidth / that.data.tabs.length - sliderWidth) / 2,
18 | sliderOffset: res.windowWidth / that.data.tabs.length * that.data.activeIndex
19 | });
20 | }
21 | });
22 |
23 | dev_request.Get('/classify', function (res) {
24 | //图片地址加上链接
25 | res.data.male.forEach(function (item) {
26 | item.icon = dev_request.BASE_URL + item.icon
27 | })
28 | res.data.female.forEach(function (item) {
29 | item.icon = dev_request.BASE_URL + item.icon
30 | })
31 | res.data.press.forEach(function (item) {
32 | item.icon = dev_request.BASE_URL + item.icon
33 | })
34 |
35 | that.setData({
36 | classifys: res.data
37 | })
38 | });
39 | },
40 | tabClick: function (e) {
41 | this.setData({
42 | sliderOffset: e.currentTarget.offsetLeft,
43 | activeIndex: e.currentTarget.id
44 | });
45 | },
46 | startBooks: function (e) {
47 | wx.navigateTo({
48 | url: '../books/books?major=' + e.currentTarget.dataset.major,
49 | })
50 | }
51 |
52 | })
--------------------------------------------------------------------------------
/pages/mine/mine.js:
--------------------------------------------------------------------------------
1 | // pages/shelf/shelf.js
2 | //获取应用实例
3 | const dev_request = require('../../utils/dev_request')
4 | const app = getApp()
5 | Page({
6 |
7 | /**
8 | * 页面的初始数据
9 | */
10 | data: {
11 | avatar: '../../image/dev.png',
12 | username: '未登录',
13 | },
14 |
15 | /**
16 | * 生命周期函数--监听页面加载
17 | */
18 | onLoad: function (options) {
19 |
20 | },
21 |
22 |
23 | /**
24 | * 生命周期函数--监听页面显示
25 | */
26 | onShow: function () {
27 | let userinfo = app.globalData.user_info;
28 | if (userinfo) {
29 | this.setData({
30 | avatar: dev_request.BASE_URL + userinfo.icon,
31 | username: userinfo.nickname,
32 | })
33 | }
34 | },
35 |
36 | bindTapUseravatar: function () {
37 | if (this.data.username === '未登录') {
38 | wx.navigateTo({
39 | url: "../login/login"
40 | })
41 | }
42 | },
43 | /**
44 | * 关于作者
45 | */
46 | aboutAuthor:function () {
47 | wx.navigateTo({
48 | url: "../about/about"
49 | })
50 | }
51 | ,
52 | /**
53 | * 退出登录
54 | */
55 | outLogin: function () {
56 | let that=this
57 | wx.showModal({
58 | title: '是否退出登录?',
59 | content: '退出后将清除用户本地用户信息以及阅读记录',
60 | success: res => {
61 | if (res.confirm) {
62 | wx.clearStorage()
63 | app.globalData.user_info = ''
64 | that.setData({
65 | avatar: '../../image/dev.png',
66 | username: '未登录',
67 | })
68 | }
69 | }
70 | })
71 | }
72 | })
--------------------------------------------------------------------------------
/pages/read/read.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 目录
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 | {{item.title}}
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 | {{chapter.title}}
22 | {{chapter.cpContent}}
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/pages/read/read.wxss:
--------------------------------------------------------------------------------
1 |
2 | /*正文*/
3 | .chapter_sv{
4 | display: flex;
5 | align-items: center;
6 | flex-direction: column;
7 | background-color: antiquewhite;
8 | }
9 |
10 | .chapter_view{
11 | display: flex;
12 | flex-direction: column;
13 | }
14 | .btn_chapters{
15 | background-color: #00BCD4;
16 | color: white;
17 | float: left;
18 | margin-left: 30rpx;
19 | margin-right: 30rpx;
20 | margin-top: 20rpx;
21 | }
22 | .text_chapter_name{
23 | text-align: center;
24 | display: block;
25 | color: black;
26 | margin-top: 10rpx;
27 | font-size: 35rpx;
28 | }
29 | .text_chapter{
30 | display: block;
31 | color: black;
32 | font-size: 28rpx;
33 | margin: 20rpx;
34 | }
35 | .btn_view{
36 | display: flex;
37 | flex-direction: row;
38 | margin: 20rpx 60rpx;
39 | }
40 | .btn_chapter{
41 | color: white;
42 | background-color: #00BCD4;
43 | margin: 20rpx;
44 | }
45 |
46 |
47 |
48 | /*目录弹框*/
49 |
50 | .chapters_view{
51 | width:70%;
52 | position:fixed;
53 | left:0;
54 | top: 0;
55 | bottom:0;
56 | background:antiquewhite;
57 | transform:translate(-100%,0);
58 | transition:all 0.2s linear;
59 | z-index: 9;
60 | height: 100%;
61 | }
62 |
63 | .chapters_view.show {
64 | transform:translate(0,0);
65 | }
66 |
67 | .chapters_mask {
68 | width:100%;
69 | position:fixed;
70 | left:0;
71 | top: 0;
72 | bottom:0;
73 | background:rgba(0,0,0,.5);
74 | z-index: 8;
75 | display:none;
76 | }
77 |
78 | .chapters_mask.show {display:block;}
79 |
80 | .chapters_text{
81 | font-size: 30rpx;
82 | margin-top: 20rpx;
83 | margin-left: 20rpx;
84 | }
85 |
86 | .chapter_text_view{
87 | display: flex;
88 | flex-direction: row;
89 | padding: 20rpx;
90 | align-items: center;
91 |
92 | }
93 | .ic_chapter{
94 | margin-left:10rpx;
95 | margin-right:10rpx;
96 | width: 40rpx;
97 | height: 40rpx;
98 | }
99 | .chapter_text{
100 | display: block;
101 | overflow: hidden;
102 | text-overflow: ellipsis;
103 | white-space: nowrap;
104 | font-size: 30rpx;
105 | color: black;
106 | height: 30rpx;
107 | line-height: 30rpx;
108 | }
109 |
--------------------------------------------------------------------------------
/pages/books/books.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
11 | {{item}}
12 |
13 |
14 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
--------------------------------------------------------------------------------
/pages/detail/detail.wxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | {{bookinfo.title}}
8 |
9 | {{bookinfo.author}}
10 | |
11 | {{bookinfo.majorCate}}
12 |
13 |
14 | {{bookinfo.wordCount}}
15 | |
16 | {{bookinfo.updated}}
17 |
18 |
19 |
20 |
21 | 追书评分
22 | {{bookinfo.rating.score}}
23 | {{bookinfo.rating.count}}人评
24 |
25 |
26 |
27 |
28 |
29 |
30 | 追书人气
31 | {{bookinfo.latelyFollower}}
32 |
33 |
34 |
35 |
36 |
37 |
38 | 读者留存
39 | {{bookinfo.retentionRatio}}%
40 |
41 |
42 |
43 |
44 |
45 |
46 | 日更新字
47 | {{bookinfo.serializeWordCount}}
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 | 简介
56 |
57 | {{bookinfo.longIntro}}
58 |
59 |
60 |
61 |
62 | 标签
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 | {{addText}}
72 | 开始阅读
73 |
74 |
--------------------------------------------------------------------------------
/pages/detail/detail.wxss:
--------------------------------------------------------------------------------
1 | @import "../../template/book-type-template/book_type_template.wxss";
2 | .book_detail_sv{
3 | display: flex;
4 | width: 100%;
5 | height: 100%;
6 | }
7 |
8 | /*书籍信息*/
9 | .book_info{
10 | display: flex;
11 | flex-direction: row;
12 | background-color: #fafafa;
13 | margin-top: 15rpx;
14 | margin-left: 25rpx;
15 | margin-right: 25rpx;
16 | }
17 | .book_image{
18 | width: 65px;
19 | height: 87px;
20 | border-radius: 6rpx;
21 | }
22 | .book_text{
23 | display: flex;
24 | flex-direction: column;
25 | margin-left: 15rpx;
26 | }
27 | .book_title{
28 | color: black;
29 | font-size: 30rpx;
30 | }
31 | .book_author_type{
32 | display: flex;
33 | flex-direction: row;
34 | margin-top: 10rpx;
35 | }
36 | .text_{
37 | margin-left: 10rpx;
38 | margin-right:10rpx;
39 | font-size: 24rpx;
40 | color: #515151;
41 | }
42 | .book_text_author{
43 | font-size: 24rpx;
44 | color: #00BCD4;
45 | }
46 | .book_text_type{
47 | font-size: 24rpx;
48 | color: #515151;
49 | }
50 |
51 | .view_score{ display: flex; flex-direction: column; position: fixed; right: 0; padding: 20rpx 15rpx; background-color: white; align-items: center; margin-right: 20rpx; border-radius: 10rpx; box-shadow:6rpx 6rpx 6rpx rgba(0,0,0,0.1); }
52 | .text_zhuishu{ color: #515151; font-size: 24rpx; }
53 | .text_score{ color: #00BCD4; font-size: 40rpx; }
54 | .text_evaluate{ color: #515151; font-size: 20rpx; }
55 | .book_fow{ display: flex; flex-direction: row; min-height: 50rpx; margin: 20rpx 40rpx;}
56 | .v_fow_num{ display: flex; flex: auto; flex-direction: column; justify-content: center; align-items: center; border-right: 2rpx solid #aeadad; }
57 | .v_fow_num:last-child {border:none;}
58 | .v_vertical_line{ flex: auto; background-color: #aeadad; width: 2rpx; margin-top: 10rpx; margin-bottom:10rpx; height: 100%; }
59 | .text_fow{ color: #515151; font-size: 24rpx; }
60 | .text_fow_num{ margin-top: 20rpx; color: black; font-size: 20rpx; }
61 | .bottom_view{ display: flex; flex-direction: row; position: fixed; bottom: 0; width: 100%; height: 80rpx; }
62 | .v_horizontal_line{ background-color: #aeadad; height: 2rpx; flex: auto; margin-left: 20rpx; margin-right:20rpx; margin-top: 20rpx; }
63 | .v_brief{ margin-top: 20rpx; line-height: 30rpx; display: flex; margin-left: 20rpx; flex-direction: row; }
64 | .v_view{ background-color: #00BCD4; width: 5rpx; height: 30rpx; }
65 | .text_brief_name{ color: black; font-size: 30rpx; margin-left: 10rpx; }
66 | .text_brief{ color: #515151;
67 | margin: 20rpx 40rpx 20rpx 60rpx;
68 | font-size: 24rpx; display:block; }
69 | .add{ display: flex; align-items: center; justify-content: center; width: 50%; height: 100%; color: #00BCD4; background-color: white; font-size: 28rpx; }
70 | .read{ display: flex; align-items: center; justify-content: center; width: 50%; height: 100%; color: white; font-size: 28rpx; background-color: #00BCD4; }
71 | .book_type{
72 | display: flex;
73 | margin: 20rpx;
74 | }
--------------------------------------------------------------------------------
/pages/books/books.js:
--------------------------------------------------------------------------------
1 | let sliderWidth = 96; // 需要设置slider的宽度,用于计算中间位置
2 | let dev_request = require('../../utils/dev_request');
3 | let mMajor
4 | let mPage
5 | let mType
6 | let bookInfo
7 | Page({
8 |
9 | /**
10 | * 页面的初始数据
11 | */
12 | data: {
13 | tabs: ['热门', '新书', '好评'],
14 | books: [],
15 | activeIndex: 0,
16 | sliderOffset: 0,
17 | sliderLeft: 0,
18 | base_url: dev_request.BASE_URL,
19 | isEmpty:false,
20 | empty_msg:'Pen友,别慌,此分类还没有添加书籍'
21 | },
22 |
23 | /**
24 | * 生命周期函数--监听页面加载
25 | */
26 | onLoad: function (options) {
27 | var that = this;
28 | wx.getSystemInfo({
29 | success: function (res) {
30 | that.setData({
31 | sliderLeft: (res.windowWidth / that.data.tabs.length - sliderWidth) / 2,
32 | sliderOffset: res.windowWidth / that.data.tabs.length * that.data.activeIndex
33 | });
34 | }
35 | });
36 | mPage = 1
37 | mType = 'hot'
38 | mMajor = options.major;
39 | bookInfo = []
40 | wx.setNavigationBarTitle({
41 | title: mMajor
42 | });
43 |
44 | },
45 |
46 | onShow: function () {
47 | this.getBooks(1)
48 | bookInfo = []
49 | },
50 |
51 |
52 | tabClick: function (e) {
53 | bookInfo = []
54 | mPage = 1
55 | switch (e.currentTarget.id) {
56 | case '0':
57 | mType = 'hot'
58 | this.getBooks(mPage)
59 | break
60 | case '1':
61 | mType = 'new'
62 | this.getBooks(mPage)
63 | break
64 | case '2':
65 | mType = 'reputation'
66 | this.getBooks(mPage)
67 | break
68 | }
69 |
70 | this.setData({
71 | sliderOffset: e.currentTarget.offsetLeft,
72 | activeIndex: e.currentTarget.id
73 | });
74 | },
75 |
76 | /**
77 | * 获取书籍列表信息
78 | */
79 | getBooks: function (page) {
80 | let that = this;
81 | let data = {
82 |
83 | type: mType,
84 | major: mMajor,
85 | page: page
86 |
87 | };
88 | dev_request.Get('/books', data, function (book) {
89 | book.data.forEach(function (item) {
90 | item.cover = dev_request.ZHUISHU_URL + item.cover
91 | bookInfo.push(item)
92 | })
93 | that.setData({
94 | books: bookInfo,
95 | isEmpty:bookInfo.length === 0
96 | })
97 |
98 | });
99 |
100 | },
101 |
102 |
103 | /**
104 | * 跳转书籍详情
105 | * @param params
106 | */
107 | startBooksDetail:function (params) {
108 | wx.navigateTo({
109 | url: '../detail/detail?book_name=' + params.currentTarget.dataset.book_name+"&bookid="+params.currentTarget.dataset.bookid,
110 | })
111 | },
112 |
113 | /**
114 | * 页面上拉触底事件的处理函数
115 | */
116 | onReachBottom: function () {
117 | let that = this;
118 | ++mPage
119 | that.getBooks(mPage)
120 |
121 |
122 | },
123 |
124 |
125 | })
--------------------------------------------------------------------------------
/pages/detail/detail.js:
--------------------------------------------------------------------------------
1 | let bookid
2 | let dev_request = require('../../utils/dev_request');
3 | Page({
4 |
5 | /**
6 | * 页面的初始数据
7 | */
8 | data: {
9 | bookinfo: '',
10 | addText: '加入书架',
11 | isHaveBookType:false
12 | },
13 |
14 | /**
15 | * 生命周期函数--监听页面加载
16 | */
17 | onLoad: function (options) {
18 |
19 | bookid = options.bookid
20 |
21 |
22 |
23 | },
24 |
25 |
26 |
27 | onShow:function () {
28 | let that = this
29 | wx.showLoading({
30 | title:'加载中'
31 | })
32 |
33 | dev_request.Get('/books/' + bookid, function (bookdetail) {
34 | wx.hideLoading()
35 | let data = bookdetail.data
36 | wx.setNavigationBarTitle({
37 | title: data.title
38 | });
39 | data.cover = dev_request.ZHUISHU_URL + bookdetail.data.cover
40 | let wordCount = data.wordCount + '字'
41 | if (data.wordCount / 10000 > 0) {
42 | wordCount = parseInt(data.wordCount / 10000) + '万字'
43 | }
44 | data.wordCount = wordCount
45 | data.rating.score = data.rating.score.toFixed(1)
46 | //书籍更新时间计算
47 | let updateTime = new Date(data.updated).getTime()
48 | let dateTime = new Date().getTime()
49 | let day = parseInt((dateTime - updateTime) / (1000 * 3600 * 24))
50 | let hour = parseInt((dateTime - updateTime) / (1000 * 3600 ))
51 | data.updated = day > 0 ? day + '天前' : hour + '小时前'
52 | let addText = data.isCollect ? '移除书架' : '加入书架'
53 | that.setData({
54 | bookinfo: bookdetail.data,
55 | addText: addText,
56 | isHaveBookType:data.tags.length>0
57 | })
58 | })
59 | },
60 |
61 | /**
62 | * 添加书籍到书架
63 | */
64 | addBook: function () {
65 | let that=this
66 | let url = '/user/bookshelf'
67 | let data = {
68 | bookid: bookid,
69 | }
70 | if (this.data.addText === '加入书架') {
71 | dev_request.Post(url, data, function (addBookInfo) {
72 | wx.showToast({
73 | title: addBookInfo.data,
74 | icon: 'success',
75 | duration: 1000
76 | })
77 | that.setData({
78 | addText:'移除书架'
79 | })
80 | })
81 |
82 | } else if (this.data.addText === '移除书架') {
83 | dev_request.Delete(url, data, function (deleteBookInfo) {
84 | wx.showToast({
85 | title: deleteBookInfo.data,
86 | icon: 'success',
87 | duration: 1000
88 | })
89 | that.setData({
90 | addText:'加入书架'
91 | })
92 | })
93 |
94 | }
95 | },
96 | /**
97 | * 阅读书籍
98 | */
99 | readBook: function () {
100 | let book=this.data.bookinfo
101 | let isCollect=this.data.addText==='移除书架'
102 | wx.navigateTo({
103 | url: '../read/read?bookid='+bookid+'&isCollect='+isCollect+'&bookTitle='+book.title
104 | })
105 | },
106 |
107 |
108 | /**
109 | * 用户点击右上角分享
110 | */
111 | onShareAppMessage: function () {
112 |
113 | }
114 | })
--------------------------------------------------------------------------------
/pages/read/read.js:
--------------------------------------------------------------------------------
1 | let dev_request = require('../../utils/dev_request');
2 | let isCollect = false;
3 | let bookid;
4 | Page({
5 |
6 | /**
7 | * 页面的初始数据
8 | */
9 | data: {
10 | isOpenChapter: false,//是否打开目录弹框
11 | isCollect: false,//是否收藏
12 | chapters: '',//目录
13 | chapter: '',//正文
14 | currentChapter: 0,//当前目录下标
15 | },
16 |
17 | /**
18 | * 生命周期函数--监听页面加载
19 | */
20 | onLoad: function (options) {
21 | let that = this
22 | bookid = options.bookid
23 | isCollect = options.isCollect
24 |
25 | wx.setNavigationBarTitle({
26 | title: options.bookTitle
27 | });
28 |
29 | dev_request.Get('/books/' + bookid + '/chapters', function (bookChapters) {
30 |
31 |
32 | wx.getStorage({
33 | key: bookid,
34 | success: res => {
35 | that.getChapter(bookChapters.data.chapters[res.data.chapterIndex].link)
36 | that.setData({
37 | currentChapter: res.data.chapterIndex
38 | })
39 | }, fail: err => {
40 | console.log(err);
41 | that.getChapter(bookChapters.data.chapters[0].link)
42 | }
43 | });
44 |
45 |
46 | that.setData({
47 | chapters: bookChapters.data.chapters
48 | })
49 | })
50 |
51 |
52 | },
53 |
54 | /**
55 | * 获取正文
56 | * @param link
57 | */
58 | getChapter: function (link) {
59 | let that = this
60 | wx.request({
61 | url: 'http://chapterup.zhuishushenqi.com/chapter/' + link,
62 | success: bookChapter => {
63 | that.setData({
64 | chapter: bookChapter.data.chapter,
65 | })
66 | }
67 | })
68 | },
69 | /**
70 | * 打开目录弹框
71 | */
72 | showChapter: function () {
73 | this.setData({
74 | isOpenChapter: true
75 | })
76 | },
77 | /**
78 | * 关闭目录弹框
79 | */
80 | hideChapter: function () {
81 | this.setData({
82 | isOpenChapter: false
83 | })
84 | },
85 | /**
86 | * 上一章数据获取
87 | * @param params
88 | */
89 | preChapter: function (params) {
90 | let currentIndex = params.currentTarget.dataset.current_index
91 | currentIndex--
92 | let chapter = this.data.chapters[currentIndex]
93 | this.getChapter(chapter.link)
94 | this.setData({
95 | currentChapter: currentIndex,
96 | chapter: ""
97 | })
98 |
99 | },
100 | /**
101 | * 下一章数据获取
102 | * @param params
103 | */
104 | nextChapter: function (params) {
105 | let currentIndex = params.currentTarget.dataset.current_index
106 | currentIndex++
107 | let chapter = this.data.chapters[currentIndex]
108 | this.getChapter(chapter.link)
109 | this.setData({
110 | currentChapter: currentIndex,
111 | chapter: ""
112 | })
113 |
114 | },
115 |
116 | selectChapter: function (params) {
117 | let index = params.currentTarget.dataset.index
118 | if (this.data.currentChapter !== index) {
119 | let chapter = this.data.chapters[index]
120 | this.getChapter(chapter.link)
121 | this.setData({
122 | currentChapter: index,
123 | isOpenChapter: false,
124 | chapter: ""
125 | })
126 |
127 | }
128 | },
129 | /**
130 | * 生命周期函数--监听页面卸载
131 | */
132 | onUnload: function () {
133 | let data = {
134 | bookid: bookid,
135 | chapterIndex: this.data.currentChapter,
136 | }
137 | wx.setStorage({
138 | key: bookid,
139 | data: data
140 | })
141 |
142 |
143 | },
144 |
145 | })
--------------------------------------------------------------------------------
/utils/dev_request.js:
--------------------------------------------------------------------------------
1 | // const BASE_URL = 'http://192.168.1.223:3389';
2 | // const BASE_URL = 'http://192.168.5.87:3389';
3 | const BASE_URL = 'http://www.luliangdev.cn';
4 | const ZHUISHU_URL = 'http://statics.zhuishushenqi.com';
5 | const app = getApp();
6 |
7 | /**
8 | * 网络请求封装
9 | * @param url url路径名 例:/books
10 | * @param method 请求方式 POST/GET/DELETE等
11 | * @param data 请求参数 string类型
12 | * @param success 成功回调
13 | * @param fail 失败回调
14 | */
15 | function request(url, method, data, success, fail) {
16 | if (!fail && !success && typeof data === 'function') {
17 | // fail = null;
18 | success = data;
19 | data = "";
20 | } else if (!fail) {
21 | if (typeof data === 'function') {
22 | fail = success
23 | success = data
24 | data = ""
25 | } else if (typeof data === 'object') {
26 | // fail = null
27 | } else {
28 | console.log("传递参数类型不正确");
29 | }
30 |
31 | } else {
32 | console.log("传递参数个数不正确");
33 | }
34 | let wxtask = wx.request({
35 | url: BASE_URL + '/api' + url,
36 | header: {
37 | 'access-token': app.globalData.user_info.token,
38 | 'app-type': 'wx-app'
39 | },
40 | method: method,
41 | data: data,
42 | success: function (res) {
43 | switch (res.data.code) {
44 | case 10000:
45 | case 10001:
46 | case 10002:
47 | case 10004:
48 | success(res.data)
49 | break
50 | case 10005:
51 | case 40000:
52 | case 40001:
53 | case 40003:
54 | case 40004:
55 | case 40005:
56 | case 50000:
57 | case 50003:
58 | wx.showToast({
59 | title: res.data.msg,
60 | icon: 'none',
61 | duration: 1000
62 | })
63 | if (fail) {
64 | fail(res.data.msg)
65 | }
66 | break
67 | case 60001:
68 | case 60002:
69 | wx.showToast({
70 | title: res.data.msg,
71 | icon: 'none',
72 | duration: 1000
73 | })
74 | //token无效跳转登录页面
75 | wx.navigateTo({
76 | url: "../login/login"
77 | })
78 |
79 | break
80 | }
81 | },
82 | fail: function (res) {
83 | console.log(res);
84 | wx.showToast({
85 | title: res,
86 | icon: 'none',
87 | duration: 1000
88 | })
89 | if (fail) {
90 | fail(res)
91 | }
92 | }
93 | })
94 |
95 |
96 | return wxtask;
97 | }
98 |
99 |
100 | /**
101 | * 请求封装-Get
102 | * @param url 请求地址
103 | * @param data 请求参数
104 | * @param success 成功回调
105 | * @param fail 失败回调
106 | * @constructor
107 | *
108 | * 返回值为微信请求实例 用于取消请求
109 | */
110 | function Get(url, data, success, fail) {
111 | return request(url, "GET", data, success, fail)
112 | }
113 |
114 |
115 | /**
116 | * 请求封装-Post
117 | * @param url 请求地址
118 | * @param data 请求参数
119 | * @param success 成功回调
120 | * @param fail 失败回调
121 | * @constructor
122 | *
123 | * 返回值为微信请求实例 用于取消请求
124 | */
125 | function Post(url, data, success, fail) {
126 | return request(url, 'POST', data, success, fail)
127 | }
128 |
129 |
130 | /**
131 | * 请求封装-Delete
132 | * @param url 请求地址
133 | * @param data 请求参数
134 | * @param success 成功回调
135 | * @param fail 失败回调
136 | * @constructor
137 | *
138 | * 返回值为微信请求实例 用于取消请求
139 | */
140 | function Delete(url, data, success, fail) {
141 | return request(url, 'DELETE', data, success, fail)
142 | }
143 |
144 | exports.Get = Get;
145 | exports.Post = Post;
146 | exports.Delete = Delete;
147 | exports.BASE_URL = BASE_URL;
148 | exports.ZHUISHU_URL = ZHUISHU_URL;
--------------------------------------------------------------------------------
/utils/md5.js:
--------------------------------------------------------------------------------
1 | /*
2 | * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message
3 | * Digest Algorithm, as defined in RFC 1321.
4 | * Version 1.1 Copyright (C) Paul Johnston 1999 - 2002.
5 | * Code also contributed by Greg Holt
6 | * See http://pajhome.org.uk/site/legal.html for details.
7 | */
8 |
9 | /*
10 | * Add integers, wrapping at 2^32. This uses 16-bit operations internally
11 | * to work around bugs in some JS interpreters.
12 | */
13 | function safe_add(x, y)
14 | {
15 | var lsw = (x & 0xFFFF) + (y & 0xFFFF)
16 | var msw = (x >> 16) + (y >> 16) + (lsw >> 16)
17 | return (msw << 16) | (lsw & 0xFFFF)
18 | }
19 |
20 | /*
21 | * Bitwise rotate a 32-bit number to the left.
22 | */
23 | function rol(num, cnt)
24 | {
25 | return (num << cnt) | (num >>> (32 - cnt))
26 | }
27 |
28 | /*
29 | * These functions implement the four basic operations the algorithm uses.
30 | */
31 | function cmn(q, a, b, x, s, t)
32 | {
33 | return safe_add(rol(safe_add(safe_add(a, q), safe_add(x, t)), s), b)
34 | }
35 | function ff(a, b, c, d, x, s, t)
36 | {
37 | return cmn((b & c) | ((~b) & d), a, b, x, s, t)
38 | }
39 | function gg(a, b, c, d, x, s, t)
40 | {
41 | return cmn((b & d) | (c & (~d)), a, b, x, s, t)
42 | }
43 | function hh(a, b, c, d, x, s, t)
44 | {
45 | return cmn(b ^ c ^ d, a, b, x, s, t)
46 | }
47 | function ii(a, b, c, d, x, s, t)
48 | {
49 | return cmn(c ^ (b | (~d)), a, b, x, s, t)
50 | }
51 |
52 | /*
53 | * Calculate the MD5 of an array of little-endian words, producing an array
54 | * of little-endian words.
55 | */
56 | function coreMD5(x)
57 | {
58 | var a = 1732584193
59 | var b = -271733879
60 | var c = -1732584194
61 | var d = 271733878
62 |
63 | for(var i = 0; i < x.length; i += 16)
64 | {
65 | var olda = a
66 | var oldb = b
67 | var oldc = c
68 | var oldd = d
69 |
70 | a = ff(a, b, c, d, x[i+ 0], 7 , -680876936)
71 | d = ff(d, a, b, c, x[i+ 1], 12, -389564586)
72 | c = ff(c, d, a, b, x[i+ 2], 17, 606105819)
73 | b = ff(b, c, d, a, x[i+ 3], 22, -1044525330)
74 | a = ff(a, b, c, d, x[i+ 4], 7 , -176418897)
75 | d = ff(d, a, b, c, x[i+ 5], 12, 1200080426)
76 | c = ff(c, d, a, b, x[i+ 6], 17, -1473231341)
77 | b = ff(b, c, d, a, x[i+ 7], 22, -45705983)
78 | a = ff(a, b, c, d, x[i+ 8], 7 , 1770035416)
79 | d = ff(d, a, b, c, x[i+ 9], 12, -1958414417)
80 | c = ff(c, d, a, b, x[i+10], 17, -42063)
81 | b = ff(b, c, d, a, x[i+11], 22, -1990404162)
82 | a = ff(a, b, c, d, x[i+12], 7 , 1804603682)
83 | d = ff(d, a, b, c, x[i+13], 12, -40341101)
84 | c = ff(c, d, a, b, x[i+14], 17, -1502002290)
85 | b = ff(b, c, d, a, x[i+15], 22, 1236535329)
86 |
87 | a = gg(a, b, c, d, x[i+ 1], 5 , -165796510)
88 | d = gg(d, a, b, c, x[i+ 6], 9 , -1069501632)
89 | c = gg(c, d, a, b, x[i+11], 14, 643717713)
90 | b = gg(b, c, d, a, x[i+ 0], 20, -373897302)
91 | a = gg(a, b, c, d, x[i+ 5], 5 , -701558691)
92 | d = gg(d, a, b, c, x[i+10], 9 , 38016083)
93 | c = gg(c, d, a, b, x[i+15], 14, -660478335)
94 | b = gg(b, c, d, a, x[i+ 4], 20, -405537848)
95 | a = gg(a, b, c, d, x[i+ 9], 5 , 568446438)
96 | d = gg(d, a, b, c, x[i+14], 9 , -1019803690)
97 | c = gg(c, d, a, b, x[i+ 3], 14, -187363961)
98 | b = gg(b, c, d, a, x[i+ 8], 20, 1163531501)
99 | a = gg(a, b, c, d, x[i+13], 5 , -1444681467)
100 | d = gg(d, a, b, c, x[i+ 2], 9 , -51403784)
101 | c = gg(c, d, a, b, x[i+ 7], 14, 1735328473)
102 | b = gg(b, c, d, a, x[i+12], 20, -1926607734)
103 |
104 | a = hh(a, b, c, d, x[i+ 5], 4 , -378558)
105 | d = hh(d, a, b, c, x[i+ 8], 11, -2022574463)
106 | c = hh(c, d, a, b, x[i+11], 16, 1839030562)
107 | b = hh(b, c, d, a, x[i+14], 23, -35309556)
108 | a = hh(a, b, c, d, x[i+ 1], 4 , -1530992060)
109 | d = hh(d, a, b, c, x[i+ 4], 11, 1272893353)
110 | c = hh(c, d, a, b, x[i+ 7], 16, -155497632)
111 | b = hh(b, c, d, a, x[i+10], 23, -1094730640)
112 | a = hh(a, b, c, d, x[i+13], 4 , 681279174)
113 | d = hh(d, a, b, c, x[i+ 0], 11, -358537222)
114 | c = hh(c, d, a, b, x[i+ 3], 16, -722521979)
115 | b = hh(b, c, d, a, x[i+ 6], 23, 76029189)
116 | a = hh(a, b, c, d, x[i+ 9], 4 , -640364487)
117 | d = hh(d, a, b, c, x[i+12], 11, -421815835)
118 | c = hh(c, d, a, b, x[i+15], 16, 530742520)
119 | b = hh(b, c, d, a, x[i+ 2], 23, -995338651)
120 |
121 | a = ii(a, b, c, d, x[i+ 0], 6 , -198630844)
122 | d = ii(d, a, b, c, x[i+ 7], 10, 1126891415)
123 | c = ii(c, d, a, b, x[i+14], 15, -1416354905)
124 | b = ii(b, c, d, a, x[i+ 5], 21, -57434055)
125 | a = ii(a, b, c, d, x[i+12], 6 , 1700485571)
126 | d = ii(d, a, b, c, x[i+ 3], 10, -1894986606)
127 | c = ii(c, d, a, b, x[i+10], 15, -1051523)
128 | b = ii(b, c, d, a, x[i+ 1], 21, -2054922799)
129 | a = ii(a, b, c, d, x[i+ 8], 6 , 1873313359)
130 | d = ii(d, a, b, c, x[i+15], 10, -30611744)
131 | c = ii(c, d, a, b, x[i+ 6], 15, -1560198380)
132 | b = ii(b, c, d, a, x[i+13], 21, 1309151649)
133 | a = ii(a, b, c, d, x[i+ 4], 6 , -145523070)
134 | d = ii(d, a, b, c, x[i+11], 10, -1120210379)
135 | c = ii(c, d, a, b, x[i+ 2], 15, 718787259)
136 | b = ii(b, c, d, a, x[i+ 9], 21, -343485551)
137 |
138 | a = safe_add(a, olda)
139 | b = safe_add(b, oldb)
140 | c = safe_add(c, oldc)
141 | d = safe_add(d, oldd)
142 | }
143 | return [a, b, c, d]
144 | }
145 |
146 | /*
147 | * Convert an array of little-endian words to a hex string.
148 | */
149 | function binl2hex(binarray)
150 | {
151 | var hex_tab = "0123456789abcdef"
152 | var str = ""
153 | for(var i = 0; i < binarray.length * 4; i++)
154 | {
155 | str += hex_tab.charAt((binarray[i>>2] >> ((i%4)*8+4)) & 0xF) +
156 | hex_tab.charAt((binarray[i>>2] >> ((i%4)*8)) & 0xF)
157 | }
158 | return str
159 | }
160 |
161 | /*
162 | * Convert an array of little-endian words to a base64 encoded string.
163 | */
164 | function binl2b64(binarray)
165 | {
166 | var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
167 | var str = ""
168 | for(var i = 0; i < binarray.length * 32; i += 6)
169 | {
170 | str += tab.charAt(((binarray[i>>5] << (i%32)) & 0x3F) |
171 | ((binarray[i>>5+1] >> (32-i%32)) & 0x3F))
172 | }
173 | return str
174 | }
175 |
176 | /*
177 | * Convert an 8-bit character string to a sequence of 16-word blocks, stored
178 | * as an array, and append appropriate padding for MD4/5 calculation.
179 | * If any of the characters are >255, the high byte is silently ignored.
180 | */
181 | function str2binl(str)
182 | {
183 | var nblk = ((str.length + 8) >> 6) + 1 // number of 16-word blocks
184 | var blks = new Array(nblk * 16)
185 | for(var i = 0; i < nblk * 16; i++) blks[i] = 0
186 | for(var i = 0; i < str.length; i++)
187 | blks[i>>2] |= (str.charCodeAt(i) & 0xFF) << ((i%4) * 8)
188 | blks[i>>2] |= 0x80 << ((i%4) * 8)
189 | blks[nblk*16-2] = str.length * 8
190 | return blks
191 | }
192 |
193 | /*
194 | * Convert a wide-character string to a sequence of 16-word blocks, stored as
195 | * an array, and append appropriate padding for MD4/5 calculation.
196 | */
197 | function strw2binl(str)
198 | {
199 | var nblk = ((str.length + 4) >> 5) + 1 // number of 16-word blocks
200 | var blks = new Array(nblk * 16)
201 | for(var i = 0; i < nblk * 16; i++) blks[i] = 0
202 | for(var i = 0; i < str.length; i++)
203 | blks[i>>1] |= str.charCodeAt(i) << ((i%2) * 16)
204 | blks[i>>1] |= 0x80 << ((i%2) * 16)
205 | blks[nblk*16-2] = str.length * 16
206 | return blks
207 | }
208 |
209 | /*
210 | * External interface
211 | */
212 | function hexMD5 (str) { return binl2hex(coreMD5( str2binl(str))) }
213 | function hexMD5w(str) { return binl2hex(coreMD5(strw2binl(str))) }
214 | function b64MD5 (str) { return binl2b64(coreMD5( str2binl(str))) }
215 | function b64MD5w(str) { return binl2b64(coreMD5(strw2binl(str))) }
216 | /* Backward compatibility */
217 | function calcMD5(str) { return binl2hex(coreMD5( str2binl(str))) }
218 | module.exports = {
219 | hexMD5: hexMD5
220 | }
--------------------------------------------------------------------------------