├── .DS_Store ├── README.md ├── app.js ├── app.json ├── app.wxss ├── config.js ├── font.wxss ├── imgs ├── .DS_Store ├── 0.jpeg ├── link.png ├── qrcode.jpg ├── save_share.png ├── share.png ├── wechat.png └── 演示.gif ├── libs ├── .DS_Store └── aes.js ├── pages ├── .DS_Store ├── common │ ├── foot.wxml │ └── header.wxml ├── content │ ├── content.js │ ├── content.json │ ├── content.wxml │ └── content.wxss ├── contentDetails │ ├── contentDetails.js │ ├── contentDetails.json │ ├── contentDetails.wxml │ └── contentDetails.wxss ├── contentShare │ ├── contentShare.js │ ├── contentShare.json │ ├── contentShare.wxml │ └── contentShare.wxss └── index │ ├── index.js │ ├── index.json │ ├── index.wxml │ └── index.wxss ├── project.config.json ├── sitemap.json └── utils ├── api.js ├── common.wxs └── util.js /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/richard1015/News/01f1ffd944c9cc8cd096a26e591ed050fdc4ab63/.DS_Store -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # News 2 | 3 | #### 项目介绍 4 | 微信小程序项目 5 | 涉及功能 6 | 7 | 高仿Readhub小程序 8 | 9 | 1.仿wx.showActionSheet组件, 因为wx.showActionSheet组件不可以调用分享,so自己手动实现 10 | 11 | 2.canvas文章内容自动换行,内边距功能实现 canvas绘图 12 | 13 | 3.canvas动态生成图片功能 14 | 15 | 4.canvas 自动适配 16 | 17 | 5.文章左右滑动查看功能 18 | 19 | 6.canvas绘图时 ,目前有一个地方待优化,就当文章内容过多时,需要等比例缩放内容(解决中……) 20 | 21 | #### 在线体验 当前小程序未审核通过请点击微信IDE链接 22 | ![演示](/imgs/qrcode.jpg "qrcode.jpg") 23 | 微信IDE演示代码https://developers.weixin.qq.com/s/WCkpsTm97M7p 24 | 25 | ![演示](/imgs/%E6%BC%94%E7%A4%BA.gif "演示.gif") 26 | 27 | ![首页](https://gitee.com/uploads/images/2018/0503/113000_fec66a5b_1353184.png "屏幕截图.png") 28 | ![文章详情](https://gitee.com/uploads/images/2018/0503/113029_09f90faa_1353184.png "屏幕截图.png") 29 | ![文章详情左右滑动功能](https://gitee.com/uploads/images/2018/0503/113128_e9e31bc6_1353184.png "屏幕截图.png") 30 | ![分享按钮点击](https://gitee.com/uploads/images/2018/0503/113155_cf509986_1353184.png "屏幕截图.png") 31 | ![生成卡片,保存图片到手机](https://gitee.com/uploads/images/2018/0503/113239_6e655035_1353184.png "屏幕截图.png") 32 | ![文章内容](https://gitee.com/uploads/images/2018/0503/113059_57b8e82a_1353184.png "屏幕截图.png") 33 | #### 软件架构 34 | 软件架构说明 35 | 36 | 37 | #### 安装教程 38 | 39 | 1. xxxx 40 | 2. xxxx 41 | 3. xxxx 42 | 43 | #### 使用说明 44 | 45 | 1. 使用微信开发者工具打开项目即可 46 | 2. xxxx 47 | 3. xxxx 48 | 49 | #### 参与贡献 50 | 51 | 1. Fork 本项目 52 | 2. 新建 Feat_xxx 分支 53 | 3. 提交代码 54 | 4. 新建 Pull Request 55 | -------------------------------------------------------------------------------- /app.js: -------------------------------------------------------------------------------- 1 | //app.js 2 | var apiHelper = require("utils/api.js"); 3 | App({ 4 | onLaunch: function () { 5 | var self = this 6 | console.log('App Launch') 7 | // 获取手机信息 8 | wx.getSystemInfo({ 9 | success: function (res) { 10 | let model = res.model.substring(0, res.model.lastIndexOf("X")) + "X"; 11 | if (model == 'iPhone X') { 12 | self.globalData.isIphoneX = true //判断是否为iPhone X 默认为值false,iPhone X 值为true 13 | } 14 | } 15 | }) 16 | // 获取用户信息 17 | self.getUserInfo(function (res) { 18 | return 19 | //获取openId 20 | self.getUserOpenId(res, function (error, openid) { 21 | if (error) { 22 | console.error(error) 23 | } else { 24 | // userInfo.openId = openid; 25 | // //提交用户信息 26 | // apiHelper.paramData.cmd = "/wxuser"; //cmd 27 | // apiHelper.paramData.param = userInfo; 28 | // apiHelper.post((res) => { 29 | // if (res.State == 0) { 30 | // console.log('用户信息提交成功') 31 | // } 32 | // }); 33 | } 34 | }); 35 | }) 36 | 37 | }, 38 | onShow: function () { 39 | console.log('App Show') 40 | }, 41 | onHide: function () { 42 | console.log('App Hide') 43 | }, 44 | globalData: { 45 | userInfo: null, 46 | hasLogin: false, 47 | openid: null, 48 | isIphoneX: false 49 | }, 50 | // lazy loadin userInfo 51 | getUserInfo: function (callback) { 52 | var self = this; 53 | wx.getSetting({ 54 | success: res => { 55 | if (res.authSetting['scope.userInfo']) { 56 | // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框 57 | wx.getUserInfo({ 58 | success: res => { 59 | // 可以将 res 发送给后台解码出 unionId 60 | self.globalData.userInfo = res.userInfo 61 | // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回 62 | // 所以此处加入 callback 以防止这种情况 63 | if (callback) { 64 | callback(res) 65 | } 66 | } 67 | }) 68 | } else { 69 | wx.authorize({ 70 | scope: 'scope.userInfo', 71 | success() { 72 | // 用户已经同意小程序使用录音功能,后续调用 wx.startRecord 接口不会弹窗询问 73 | wx.getUserInfo({ 74 | success: res => { 75 | // 可以将 res 发送给后台解码出 unionId 76 | self.globalData.userInfo = res.userInfo 77 | // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回 78 | // 所以此处加入 callback 以防止这种情况 79 | if (callback) { 80 | callback(res) 81 | } 82 | } 83 | }) 84 | }, 85 | fail(ex) { 86 | console.log(ex) 87 | self.getUserInfo(); 88 | } 89 | }) 90 | } 91 | } 92 | }) 93 | 94 | 95 | }, 96 | // lazy loading openid 97 | getUserOpenId: function (res, callback) { 98 | var self = this 99 | 100 | if (self.globalData.openid) { 101 | callback(null, self.globalData.openid) 102 | } else { 103 | wx.login({ 104 | success: function (data) { 105 | res.code = data.code; 106 | // console.log(res) 107 | //获取openId 108 | apiHelper.paramData.cmd = "wx/wxcallback"; //cmd 109 | apiHelper.paramData.param = { 110 | code: encodeURIComponent(res.code), 111 | encryptedData: encodeURIComponent(res.rawData), 112 | iv: encodeURIComponent(res.iv) 113 | }; 114 | // apiHelper.errorMsgState = false; 115 | apiHelper.loadingState = false; 116 | apiHelper.post((res) => { 117 | if (res.State == 0) { 118 | // console.log('拉取openid成功', res.Value) 119 | self.globalData.openid = res.Value 120 | callback(null, self.globalData.openid) 121 | } 122 | }); 123 | }, 124 | fail: function (err) { 125 | console.log('wx.login 接口调用失败,将无法正常使用开放接口等服务', err) 126 | callback(err) 127 | } 128 | }) 129 | } 130 | } 131 | }) -------------------------------------------------------------------------------- /app.json: -------------------------------------------------------------------------------- 1 | { 2 | "pages": [ 3 | "pages/index/index", 4 | "pages/contentShare/contentShare", 5 | "pages/content/content", 6 | "pages/contentDetails/contentDetails" 7 | ], 8 | "window": { 9 | "backgroundTextStyle": "light", 10 | "navigationBarBackgroundColor": "#fff", 11 | "navigationBarTitleText": "canvas绘制", 12 | "navigationBarTextStyle": "black" 13 | }, 14 | "sitemapLocation": "sitemap.json" 15 | } -------------------------------------------------------------------------------- /app.wxss: -------------------------------------------------------------------------------- 1 | /**app.wxss**/ 2 | @import "./font.wxss"; 3 | 4 | .header { 5 | width: 100%; 6 | height: 257rpx; 7 | position: absolute; 8 | top: 0; 9 | z-index: -1; 10 | } 11 | 12 | .header .map { 13 | width: 100%; 14 | height: 100%; 15 | } 16 | 17 | .foot { 18 | width: 100%; 19 | height: 552rpx; 20 | bottom: 0; 21 | position: absolute; 22 | z-index: -1; 23 | } 24 | 25 | .foot .foottext { 26 | color: #e83428; 27 | font-size: 22rpx; 28 | font-weight: bold; 29 | position: absolute; 30 | text-align: center; 31 | width: 100%; 32 | bottom: 24rpx; 33 | } 34 | 35 | .foot .footimg { 36 | width: 100%; 37 | height: 100%; 38 | position: absolute; 39 | left: 0; 40 | top: 0; 41 | } 42 | 43 | .hand { 44 | height: 429rpx; 45 | width: 273rpx; 46 | position: absolute; 47 | right: -90rpx; 48 | top: 813rpx; 49 | } 50 | -------------------------------------------------------------------------------- /config.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 小程序配置文件 3 | */ 4 | // 测试服务器ip 5 | // var host = "http://127.0.0.1:7001/" 6 | // 远程线上服务器ip 7 | var host ="https://zhuzhida.vip/" 8 | var config = { 9 | // 下面的地址配合云端 Server 工作 10 | host 11 | }; 12 | 13 | module.exports = config 14 | -------------------------------------------------------------------------------- /font.wxss: -------------------------------------------------------------------------------- 1 | @font-face { 2 | font-family: "iconfont"; 3 | src: url('//at.alicdn.com/t/font_637955_f8e72e5a0trfi529.eot?t=1524295758433'); /* IE9*/ 4 | src: url('//at.alicdn.com/t/font_637955_f8e72e5a0trfi529.eot?t=1524295758433#iefix') format('embedded-opentype'), 5 | /* IE6-IE8 */ url('data:application/x-font-woff;charset=utf-8;base64,d09GRgABAAAAAAbQAAsAAAAACbQAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAABHU1VCAAABCAAAADMAAABCsP6z7U9TLzIAAAE8AAAARAAAAFZW7kfwY21hcAAAAYAAAABhAAABnM64aZpnbHlmAAAB5AAAAuIAAANwiXfBiWhlYWQAAATIAAAALwAAADYRIlaZaGhlYQAABPgAAAAcAAAAJAffA4ZobXR4AAAFFAAAABAAAAAQD+oAAGxvY2EAAAUkAAAACgAAAAoCLgFEbWF4cAAABTAAAAAfAAAAIAEgAJluYW1lAAAFUAAAAUUAAAJtPlT+fXBvc3QAAAaYAAAANQAAAEaVy3CbeJxjYGRgYOBikGPQYWB0cfMJYeBgYGGAAJAMY05meiJQDMoDyrGAaQ4gZoOIAgCKIwNPAHicY2Bk/s04gYGVgYOpk+kMAwNDP4RmfM1gxMjBwMDEwMrMgBUEpLmmMDgwVDxjZm7438AQw9zA0AAUZgTJAQAkjgxyeJzFkMENgCAMRV8pGmIcxaNxIE+OwMSsgW3lwgR+8kr785MSgAVQ4zAyyIPgus2V8JUt/Mxlc7GT7K6Npr1PnUsiUaJTT8rKb5L/Vs/ao55j8v+uA3ti48P9NiC9+BQPfwAAAHicNZLPT9RAFMfndWi7v9gf/bmdssu2pa0IbHS725IUFk3ECNGoURPWePHA3tSDRC5GMMYsBw4mbiJcDQlcPIhyQaIXL4TDJib+AUZPHrh5pDpl42Tem++beTOT+bxBLEJ/f+ADXEQiOoPOo0voBkLAjYGZZUpguPUqMwaywcqqlMWu5Rq8ZVbxNKgmJyk1v+6oHM/lIAtl8Iya71YZFxr1JhNCTSkBaDq5JdhDAn4FqaJbfhnNM29BHraGcs2JaG58RqpVxMRyRhA0QVhPcCybYJiBXBYeqEqSTaa4aIvNEflgeJQZhozmkqutwYou3F+rPyzZahJgdRVEvZLdnimQAu1PiSIKGp8fTBTJoDUiwfKvdFHMlJyfiDaBvvUL/ox1xKM0ytEXq0hHw8hC4+gcqqNJNIUunBJ4hNYphYJR8GSv4TY82fVky6YxthoeTzVLLaCmWnTSaliyKlsNlU4ANblvY7G2s8CXQW1CUAUxC6bjNqiOQYHbpIxkieM9TvFoTmDRwHSmwTKdhh9SjL6nqHJQpnR52Ik+hWHY67Za8Bxmw16sTl6H4ZOpqfA9zC6EC72QrqXD09btdmGl3cG4016MvY2vL95kwK/gNJsTAUbDs2Ie2CRjBExJ59MJnU1ARk+wGSBcAngOvsPlaD++sddd6EX7NPrTCxd248Pj6HQlbDE7Lapa4QzuLLY7DBNfF+0SUSQpaSSdzeUnNNt1bW0iX8ikR6S7hON5jvBshgrIEAA+xUNcG47WZmsA8D1alyIyUEArMYeQTTH1CfqBSoHZplP3a4rEef+Fq6hBP0lSVD5QVCcG7JYhZln32Sr08wYQ3uus7WG8t3Z79lmOlKI7kkZ/FPkqEuJq2sr8RWCPP344Zh1L2m7OcQOHb9Y10/RMMzqJR8M4XNrEeHPp8SaGir9uXFui+4hD+v43FAsbRxgfbUy2x/avlFK6/uId/gaGF+9dhvgAz/wHBx6j0wAAeJxjYGRgYADiuWFGr+L5bb4ycLMwgMB1Rk4/BP1/CQsjcwyQy8HABBIFAPhqCC8AeJxjYGRgYG7438AQwwJkMTAASTCNBFgARzYCbwQAAAAD6QAABAAAAAQBAAAAAAAAAHYBRAG4AAB4nGNgZGBgYGHoZRBiAAEmIOYCQgaG/2A+AwAYGQG6AHicZY9NTsMwEIVf+gekEqqoYIfkBWIBKP0Rq25YVGr3XXTfpk6bKokjx63UA3AejsAJOALcgDvwSCebNpbH37x5Y08A3OAHHo7fLfeRPVwyO3INF7gXrlN/EG6QX4SbaONVuEX9TdjHM6bCbXRheYPXuGL2hHdhDx18CNdwjU/hOvUv4Qb5W7iJO/wKt9Dx6sI+5l5XuI1HL/bHVi+cXqnlQcWhySKTOb+CmV7vkoWt0uqca1vEJlODoF9JU51pW91T7NdD5yIVWZOqCas6SYzKrdnq0AUb5/JRrxeJHoQm5Vhj/rbGAo5xBYUlDowxQhhkiMro6DtVZvSvsUPCXntWPc3ndFsU1P9zhQEC9M9cU7qy0nk6T4E9XxtSdXQrbsuelDSRXs1JErJCXta2VELqATZlV44RelzRiT8oZ0j/AAlabsgAAAB4nGNgYoAALgbsgIWRiZGZkYWRlYGxgj+1qDw1MzcxLTWvIjMxL52tPDU5I7GEgQEAi7wJZwAAAA==') format('woff'), 6 | url('//at.alicdn.com/t/font_637955_f8e72e5a0trfi529.ttf?t=1524295758433') format('truetype'), 7 | /* chrome, 8 | firefox, 9 | opera, 10 | Safari, 11 | Android, 12 | iOS 4.2+*/ url('//at.alicdn.com/t/font_637955_f8e72e5a0trfi529.svg?t=1524295758433#iconfont') format('svg'); /* iOS 4.1- */ 13 | } 14 | 15 | .iconfont { 16 | font-family: "iconfont" !important; 17 | font-size: 30rpx; 18 | font-style: normal; 19 | -webkit-font-smoothing: antialiased; 20 | -moz-osx-font-smoothing: grayscale; 21 | } 22 | 23 | .icon-erweimafenxiang:before { 24 | content: "\e603"; 25 | } 26 | 27 | .icon-wechat:before { 28 | content: "\e600"; 29 | color: #3bd230; 30 | } 31 | -------------------------------------------------------------------------------- /imgs/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/richard1015/News/01f1ffd944c9cc8cd096a26e591ed050fdc4ab63/imgs/.DS_Store -------------------------------------------------------------------------------- /imgs/0.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/richard1015/News/01f1ffd944c9cc8cd096a26e591ed050fdc4ab63/imgs/0.jpeg -------------------------------------------------------------------------------- /imgs/link.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/richard1015/News/01f1ffd944c9cc8cd096a26e591ed050fdc4ab63/imgs/link.png -------------------------------------------------------------------------------- /imgs/qrcode.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/richard1015/News/01f1ffd944c9cc8cd096a26e591ed050fdc4ab63/imgs/qrcode.jpg -------------------------------------------------------------------------------- /imgs/save_share.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/richard1015/News/01f1ffd944c9cc8cd096a26e591ed050fdc4ab63/imgs/save_share.png -------------------------------------------------------------------------------- /imgs/share.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/richard1015/News/01f1ffd944c9cc8cd096a26e591ed050fdc4ab63/imgs/share.png -------------------------------------------------------------------------------- /imgs/wechat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/richard1015/News/01f1ffd944c9cc8cd096a26e591ed050fdc4ab63/imgs/wechat.png -------------------------------------------------------------------------------- /imgs/演示.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/richard1015/News/01f1ffd944c9cc8cd096a26e591ed050fdc4ab63/imgs/演示.gif -------------------------------------------------------------------------------- /libs/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/richard1015/News/01f1ffd944c9cc8cd096a26e591ed050fdc4ab63/libs/.DS_Store -------------------------------------------------------------------------------- /libs/aes.js: -------------------------------------------------------------------------------- 1 | /* 2 | CryptoJS v3.1.2 3 | code.google.com/p/crypto-js 4 | (c) 2009-2013 by Jeff Mott. All rights reserved. 5 | code.google.com/p/crypto-js/wiki/License 6 | */ 7 | var CryptoJS=CryptoJS||function(u,p){var d={},l=d.lib={},s=function(){},t=l.Base={extend:function(a){s.prototype=this;var c=new s;a&&c.mixIn(a);c.hasOwnProperty("init")||(c.init=function(){c.$super.init.apply(this,arguments)});c.init.prototype=c;c.$super=this;return c},create:function(){var a=this.extend();a.init.apply(a,arguments);return a},init:function(){},mixIn:function(a){for(var c in a)a.hasOwnProperty(c)&&(this[c]=a[c]);a.hasOwnProperty("toString")&&(this.toString=a.toString)},clone:function(){return this.init.prototype.extend(this)}}, 8 | r=l.WordArray=t.extend({init:function(a,c){a=this.words=a||[];this.sigBytes=c!=p?c:4*a.length},toString:function(a){return(a||v).stringify(this)},concat:function(a){var c=this.words,e=a.words,j=this.sigBytes;a=a.sigBytes;this.clamp();if(j%4)for(var k=0;k>>2]|=(e[k>>>2]>>>24-8*(k%4)&255)<<24-8*((j+k)%4);else if(65535>>2]=e[k>>>2];else c.push.apply(c,e);this.sigBytes+=a;return this},clamp:function(){var a=this.words,c=this.sigBytes;a[c>>>2]&=4294967295<< 9 | 32-8*(c%4);a.length=u.ceil(c/4)},clone:function(){var a=t.clone.call(this);a.words=this.words.slice(0);return a},random:function(a){for(var c=[],e=0;e>>2]>>>24-8*(j%4)&255;e.push((k>>>4).toString(16));e.push((k&15).toString(16))}return e.join("")},parse:function(a){for(var c=a.length,e=[],j=0;j>>3]|=parseInt(a.substr(j, 10 | 2),16)<<24-4*(j%8);return new r.init(e,c/2)}},b=w.Latin1={stringify:function(a){var c=a.words;a=a.sigBytes;for(var e=[],j=0;j>>2]>>>24-8*(j%4)&255));return e.join("")},parse:function(a){for(var c=a.length,e=[],j=0;j>>2]|=(a.charCodeAt(j)&255)<<24-8*(j%4);return new r.init(e,c)}},x=w.Utf8={stringify:function(a){try{return decodeURIComponent(escape(b.stringify(a)))}catch(c){throw Error("Malformed UTF-8 data");}},parse:function(a){return b.parse(unescape(encodeURIComponent(a)))}}, 11 | q=l.BufferedBlockAlgorithm=t.extend({reset:function(){this._data=new r.init;this._nDataBytes=0},_append:function(a){"string"==typeof a&&(a=x.parse(a));this._data.concat(a);this._nDataBytes+=a.sigBytes},_process:function(a){var c=this._data,e=c.words,j=c.sigBytes,k=this.blockSize,b=j/(4*k),b=a?u.ceil(b):u.max((b|0)-this._minBufferSize,0);a=b*k;j=u.min(4*a,j);if(a){for(var q=0;q>>2]>>>24-8*(r%4)&255)<<16|(l[r+1>>>2]>>>24-8*((r+1)%4)&255)<<8|l[r+2>>>2]>>>24-8*((r+2)%4)&255,v=0;4>v&&r+0.75*v>>6*(3-v)&63));if(l=t.charAt(64))for(;d.length%4;)d.push(l);return d.join("")},parse:function(d){var l=d.length,s=this._map,t=s.charAt(64);t&&(t=d.indexOf(t),-1!=t&&(l=t));for(var t=[],r=0,w=0;w< 15 | l;w++)if(w%4){var v=s.indexOf(d.charAt(w-1))<<2*(w%4),b=s.indexOf(d.charAt(w))>>>6-2*(w%4);t[r>>>2]|=(v|b)<<24-8*(r%4);r++}return p.create(t,r)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="}})(); 16 | (function(u){function p(b,n,a,c,e,j,k){b=b+(n&a|~n&c)+e+k;return(b<>>32-j)+n}function d(b,n,a,c,e,j,k){b=b+(n&c|a&~c)+e+k;return(b<>>32-j)+n}function l(b,n,a,c,e,j,k){b=b+(n^a^c)+e+k;return(b<>>32-j)+n}function s(b,n,a,c,e,j,k){b=b+(a^(n|~c))+e+k;return(b<>>32-j)+n}for(var t=CryptoJS,r=t.lib,w=r.WordArray,v=r.Hasher,r=t.algo,b=[],x=0;64>x;x++)b[x]=4294967296*u.abs(u.sin(x+1))|0;r=r.MD5=v.extend({_doReset:function(){this._hash=new w.init([1732584193,4023233417,2562383102,271733878])}, 17 | _doProcessBlock:function(q,n){for(var a=0;16>a;a++){var c=n+a,e=q[c];q[c]=(e<<8|e>>>24)&16711935|(e<<24|e>>>8)&4278255360}var a=this._hash.words,c=q[n+0],e=q[n+1],j=q[n+2],k=q[n+3],z=q[n+4],r=q[n+5],t=q[n+6],w=q[n+7],v=q[n+8],A=q[n+9],B=q[n+10],C=q[n+11],u=q[n+12],D=q[n+13],E=q[n+14],x=q[n+15],f=a[0],m=a[1],g=a[2],h=a[3],f=p(f,m,g,h,c,7,b[0]),h=p(h,f,m,g,e,12,b[1]),g=p(g,h,f,m,j,17,b[2]),m=p(m,g,h,f,k,22,b[3]),f=p(f,m,g,h,z,7,b[4]),h=p(h,f,m,g,r,12,b[5]),g=p(g,h,f,m,t,17,b[6]),m=p(m,g,h,f,w,22,b[7]), 18 | f=p(f,m,g,h,v,7,b[8]),h=p(h,f,m,g,A,12,b[9]),g=p(g,h,f,m,B,17,b[10]),m=p(m,g,h,f,C,22,b[11]),f=p(f,m,g,h,u,7,b[12]),h=p(h,f,m,g,D,12,b[13]),g=p(g,h,f,m,E,17,b[14]),m=p(m,g,h,f,x,22,b[15]),f=d(f,m,g,h,e,5,b[16]),h=d(h,f,m,g,t,9,b[17]),g=d(g,h,f,m,C,14,b[18]),m=d(m,g,h,f,c,20,b[19]),f=d(f,m,g,h,r,5,b[20]),h=d(h,f,m,g,B,9,b[21]),g=d(g,h,f,m,x,14,b[22]),m=d(m,g,h,f,z,20,b[23]),f=d(f,m,g,h,A,5,b[24]),h=d(h,f,m,g,E,9,b[25]),g=d(g,h,f,m,k,14,b[26]),m=d(m,g,h,f,v,20,b[27]),f=d(f,m,g,h,D,5,b[28]),h=d(h,f, 19 | m,g,j,9,b[29]),g=d(g,h,f,m,w,14,b[30]),m=d(m,g,h,f,u,20,b[31]),f=l(f,m,g,h,r,4,b[32]),h=l(h,f,m,g,v,11,b[33]),g=l(g,h,f,m,C,16,b[34]),m=l(m,g,h,f,E,23,b[35]),f=l(f,m,g,h,e,4,b[36]),h=l(h,f,m,g,z,11,b[37]),g=l(g,h,f,m,w,16,b[38]),m=l(m,g,h,f,B,23,b[39]),f=l(f,m,g,h,D,4,b[40]),h=l(h,f,m,g,c,11,b[41]),g=l(g,h,f,m,k,16,b[42]),m=l(m,g,h,f,t,23,b[43]),f=l(f,m,g,h,A,4,b[44]),h=l(h,f,m,g,u,11,b[45]),g=l(g,h,f,m,x,16,b[46]),m=l(m,g,h,f,j,23,b[47]),f=s(f,m,g,h,c,6,b[48]),h=s(h,f,m,g,w,10,b[49]),g=s(g,h,f,m, 20 | E,15,b[50]),m=s(m,g,h,f,r,21,b[51]),f=s(f,m,g,h,u,6,b[52]),h=s(h,f,m,g,k,10,b[53]),g=s(g,h,f,m,B,15,b[54]),m=s(m,g,h,f,e,21,b[55]),f=s(f,m,g,h,v,6,b[56]),h=s(h,f,m,g,x,10,b[57]),g=s(g,h,f,m,t,15,b[58]),m=s(m,g,h,f,D,21,b[59]),f=s(f,m,g,h,z,6,b[60]),h=s(h,f,m,g,C,10,b[61]),g=s(g,h,f,m,j,15,b[62]),m=s(m,g,h,f,A,21,b[63]);a[0]=a[0]+f|0;a[1]=a[1]+m|0;a[2]=a[2]+g|0;a[3]=a[3]+h|0},_doFinalize:function(){var b=this._data,n=b.words,a=8*this._nDataBytes,c=8*b.sigBytes;n[c>>>5]|=128<<24-c%32;var e=u.floor(a/ 21 | 4294967296);n[(c+64>>>9<<4)+15]=(e<<8|e>>>24)&16711935|(e<<24|e>>>8)&4278255360;n[(c+64>>>9<<4)+14]=(a<<8|a>>>24)&16711935|(a<<24|a>>>8)&4278255360;b.sigBytes=4*(n.length+1);this._process();b=this._hash;n=b.words;for(a=0;4>a;a++)c=n[a],n[a]=(c<<8|c>>>24)&16711935|(c<<24|c>>>8)&4278255360;return b},clone:function(){var b=v.clone.call(this);b._hash=this._hash.clone();return b}});t.MD5=v._createHelper(r);t.HmacMD5=v._createHmacHelper(r)})(Math); 22 | (function(){var u=CryptoJS,p=u.lib,d=p.Base,l=p.WordArray,p=u.algo,s=p.EvpKDF=d.extend({cfg:d.extend({keySize:4,hasher:p.MD5,iterations:1}),init:function(d){this.cfg=this.cfg.extend(d)},compute:function(d,r){for(var p=this.cfg,s=p.hasher.create(),b=l.create(),u=b.words,q=p.keySize,p=p.iterations;u.length>>2]&255}};d.BlockCipher=v.extend({cfg:v.cfg.extend({mode:b,padding:q}),reset:function(){v.reset.call(this);var a=this.cfg,b=a.iv,a=a.mode;if(this._xformMode==this._ENC_XFORM_MODE)var c=a.createEncryptor;else c=a.createDecryptor,this._minBufferSize=1;this._mode=c.call(a, 28 | this,b&&b.words)},_doProcessBlock:function(a,b){this._mode.processBlock(a,b)},_doFinalize:function(){var a=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){a.pad(this._data,this.blockSize);var b=this._process(!0)}else b=this._process(!0),a.unpad(b);return b},blockSize:4});var n=d.CipherParams=l.extend({init:function(a){this.mixIn(a)},toString:function(a){return(a||this.formatter).stringify(this)}}),b=(p.format={}).OpenSSL={stringify:function(a){var b=a.ciphertext;a=a.salt;return(a?s.create([1398893684, 29 | 1701076831]).concat(a).concat(b):b).toString(r)},parse:function(a){a=r.parse(a);var b=a.words;if(1398893684==b[0]&&1701076831==b[1]){var c=s.create(b.slice(2,4));b.splice(0,4);a.sigBytes-=16}return n.create({ciphertext:a,salt:c})}},a=d.SerializableCipher=l.extend({cfg:l.extend({format:b}),encrypt:function(a,b,c,d){d=this.cfg.extend(d);var l=a.createEncryptor(c,d);b=l.finalize(b);l=l.cfg;return n.create({ciphertext:b,key:c,iv:l.iv,algorithm:a,mode:l.mode,padding:l.padding,blockSize:a.blockSize,formatter:d.format})}, 30 | decrypt:function(a,b,c,d){d=this.cfg.extend(d);b=this._parse(b,d.format);return a.createDecryptor(c,d).finalize(b.ciphertext)},_parse:function(a,b){return"string"==typeof a?b.parse(a,this):a}}),p=(p.kdf={}).OpenSSL={execute:function(a,b,c,d){d||(d=s.random(8));a=w.create({keySize:b+c}).compute(a,d);c=s.create(a.words.slice(b),4*c);a.sigBytes=4*b;return n.create({key:a,iv:c,salt:d})}},c=d.PasswordBasedCipher=a.extend({cfg:a.cfg.extend({kdf:p}),encrypt:function(b,c,d,l){l=this.cfg.extend(l);d=l.kdf.execute(d, 31 | b.keySize,b.ivSize);l.iv=d.iv;b=a.encrypt.call(this,b,c,d.key,l);b.mixIn(d);return b},decrypt:function(b,c,d,l){l=this.cfg.extend(l);c=this._parse(c,l.format);d=l.kdf.execute(d,b.keySize,b.ivSize,c.salt);l.iv=d.iv;return a.decrypt.call(this,b,c,d.key,l)}})}(); 32 | (function(){for(var u=CryptoJS,p=u.lib.BlockCipher,d=u.algo,l=[],s=[],t=[],r=[],w=[],v=[],b=[],x=[],q=[],n=[],a=[],c=0;256>c;c++)a[c]=128>c?c<<1:c<<1^283;for(var e=0,j=0,c=0;256>c;c++){var k=j^j<<1^j<<2^j<<3^j<<4,k=k>>>8^k&255^99;l[e]=k;s[k]=e;var z=a[e],F=a[z],G=a[F],y=257*a[k]^16843008*k;t[e]=y<<24|y>>>8;r[e]=y<<16|y>>>16;w[e]=y<<8|y>>>24;v[e]=y;y=16843009*G^65537*F^257*z^16843008*e;b[k]=y<<24|y>>>8;x[k]=y<<16|y>>>16;q[k]=y<<8|y>>>24;n[k]=y;e?(e=z^a[a[a[G^z]]],j^=a[a[j]]):e=j=1}var H=[0,1,2,4,8, 33 | 16,32,64,128,27,54],d=d.AES=p.extend({_doReset:function(){for(var a=this._key,c=a.words,d=a.sigBytes/4,a=4*((this._nRounds=d+6)+1),e=this._keySchedule=[],j=0;j>>24]<<24|l[k>>>16&255]<<16|l[k>>>8&255]<<8|l[k&255]):(k=k<<8|k>>>24,k=l[k>>>24]<<24|l[k>>>16&255]<<16|l[k>>>8&255]<<8|l[k&255],k^=H[j/d|0]<<24);e[j]=e[j-d]^k}c=this._invKeySchedule=[];for(d=0;dd||4>=j?k:b[l[k>>>24]]^x[l[k>>>16&255]]^q[l[k>>> 34 | 8&255]]^n[l[k&255]]},encryptBlock:function(a,b){this._doCryptBlock(a,b,this._keySchedule,t,r,w,v,l)},decryptBlock:function(a,c){var d=a[c+1];a[c+1]=a[c+3];a[c+3]=d;this._doCryptBlock(a,c,this._invKeySchedule,b,x,q,n,s);d=a[c+1];a[c+1]=a[c+3];a[c+3]=d},_doCryptBlock:function(a,b,c,d,e,j,l,f){for(var m=this._nRounds,g=a[b]^c[0],h=a[b+1]^c[1],k=a[b+2]^c[2],n=a[b+3]^c[3],p=4,r=1;r>>24]^e[h>>>16&255]^j[k>>>8&255]^l[n&255]^c[p++],s=d[h>>>24]^e[k>>>16&255]^j[n>>>8&255]^l[g&255]^c[p++],t= 35 | d[k>>>24]^e[n>>>16&255]^j[g>>>8&255]^l[h&255]^c[p++],n=d[n>>>24]^e[g>>>16&255]^j[h>>>8&255]^l[k&255]^c[p++],g=q,h=s,k=t;q=(f[g>>>24]<<24|f[h>>>16&255]<<16|f[k>>>8&255]<<8|f[n&255])^c[p++];s=(f[h>>>24]<<24|f[k>>>16&255]<<16|f[n>>>8&255]<<8|f[g&255])^c[p++];t=(f[k>>>24]<<24|f[n>>>16&255]<<16|f[g>>>8&255]<<8|f[h&255])^c[p++];n=(f[n>>>24]<<24|f[g>>>16&255]<<16|f[h>>>8&255]<<8|f[k&255])^c[p++];a[b]=q;a[b+1]=s;a[b+2]=t;a[b+3]=n},keySize:8});u.AES=p._createHelper(d)})(); 36 | 37 | module.exports = CryptoJS; -------------------------------------------------------------------------------- /pages/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/richard1015/News/01f1ffd944c9cc8cd096a26e591ed050fdc4ab63/pages/.DS_Store -------------------------------------------------------------------------------- /pages/common/foot.wxml: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /pages/common/header.wxml: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /pages/content/content.js: -------------------------------------------------------------------------------- 1 | // pages/content/content.js 2 | var apiHelper = require("../../utils/api.js"); 3 | Page({ 4 | 5 | /** 6 | * 页面的初始数据 7 | */ 8 | data: { 9 | newsArray: [], 10 | animation: '', 11 | shareTitle:"", 12 | shareContent:"", 13 | shareId: 0, 14 | swiperIndex: 0, 15 | previousMargin: 35, //swiper 前边距,可用于露出前一项的一小部分,接受 px 和 rpx 值 16 | nextMargin: 35, //swiper 后边距,可用于露出后一项的一小部分,接受 px 和 rpx 值 17 | isBusy: false, //是否正在请求数据中 18 | backButton: false, // 返回首页 按钮显示状态,识别二维码进入显示 ,否则不显示 19 | currentPageIndex: 1, //当前请求全局页数 20 | currentDateIsNoData: true, //当前天是否还有数据 21 | }, 22 | toPage: function(event) { 23 | wx.showToast({ 24 | title: `暂未开放!`, 25 | icon: 'none', 26 | duration: 2000 27 | }) 28 | return; 29 | wx.navigateTo({ 30 | url: `/pages/contentDetails/contentDetails?id=${event.target.id}` 31 | }) 32 | }, 33 | toPageIndex: function(event) { 34 | wx.redirectTo({ 35 | url: '/pages/index/index', 36 | }) 37 | }, 38 | loadData: function() { 39 | if (!this.data.isBusy) { 40 | //查看当天是否还有数据 41 | if (this.data.currentDateIsNoData) { 42 | this.data.currentPageIndex = this.data.newsArray[this.data.newsArray.length - 1].order; 43 | this.getListNew(this.data.currentPageIndex); 44 | } 45 | } 46 | }, 47 | 48 | swiperChange: function(event) { 49 | console.log(event); 50 | if (event.detail.current == this.data.newsArray.length - 1) { 51 | this.loadData(); 52 | } 53 | }, 54 | /* new */ 55 | getListNew(pageIndex, pageSize = 10) { 56 | this.data.isBusy = true; 57 | var self = this; 58 | apiHelper.paramData.cmd = "news"; //cmd 59 | apiHelper.paramData.loadingState = false; 60 | apiHelper.paramData.param = { 61 | pageIndex, 62 | pageSize 63 | }; 64 | apiHelper.post((res) => { 65 | if (res.State == 0) { 66 | res.Value = res.Value.data; 67 | if (res.Value.length == 0) { 68 | //标识数据已被全部请求完 69 | self.data.currentDateIsNoData = false; 70 | } else { 71 | self.data.newsArray = self.data.newsArray.concat(res.Value); 72 | //数据 剩余条数不超过请求条数,说明下一页已没有数据 73 | if (res.Value.length < pageSize) { 74 | //标识数据已被全部请求完 75 | self.data.currentDateIsNoData = false; 76 | } else { 77 | self.data.currentDateIsNoData = true; 78 | } 79 | } 80 | } 81 | self.setData({ 82 | newsArray: self.data.newsArray 83 | }); 84 | this.data.isBusy = false; 85 | }, 'get'); 86 | }, 87 | nothing: function() {}, 88 | /** 89 | * 保存分享事件 90 | */ 91 | saveShare: function(event) { 92 | console.log('save share event !' + this.data.shareId) 93 | this.cancelShare(); 94 | wx.navigateTo({ 95 | url: `/pages/contentShare/contentShare?id=${this.data.shareId}` 96 | }) 97 | }, 98 | /** 99 | * 分享事件 100 | */ 101 | share: function(event) { 102 | this.data.shareId = event.target.id; 103 | let title = event.target.dataset.title||""; 104 | let info = event.target.dataset.content||""; 105 | wx.setStorage({ 106 | key: "shareInfo", 107 | data: JSON.stringify({ 108 | title: title, 109 | intro: info 110 | }) 111 | }) 112 | //弹出 113 | this.animation.translate3d(0, 0, 0).step(); 114 | this.setData({ 115 | animation: this.animation.export() 116 | }) 117 | }, 118 | /** 119 | * 取消分享事件 120 | */ 121 | cancelShare: function() { 122 | //收起 123 | this.animation.translate3d(0, 1000, 0).step(); 124 | this.setData({ 125 | animation: this.animation.export() 126 | }) 127 | }, 128 | 129 | /** 130 | * 生命周期函数--监听页面加载 131 | */ 132 | onLoad: function(options) { 133 | // options 中的 scene 需要使用 decodeURIComponent 才能获取到生成二维码时传入的 scene 134 | if (options.scene) { 135 | var scene = decodeURIComponent(options.scene) 136 | options.id = scene; 137 | this.setData({ 138 | backButton: true 139 | }); 140 | } 141 | var pages = getCurrentPages(); 142 | var currPage = pages[pages.length - 1]; //当前页面 143 | var prevPage = pages[pages.length - 2]; //上一个页面 144 | //判断入口 145 | if (prevPage) { 146 | //直接调用上一个页面的setData()方法,把数据存到上一个页面即编辑款项页面中去 147 | let swiperIndex = prevPage.data.newsArray.findIndex(item => { 148 | return item.id == options.id 149 | }); 150 | this.setData({ 151 | swiperIndex: swiperIndex, 152 | currentPageIndex: prevPage.data.currentPageIndex, 153 | currentDateIsNoData: prevPage.data.currentDateIsNoData 154 | }); 155 | this.setData({ 156 | newsArray: prevPage.data.newsArray //当前选择的好友名字赋值给编辑款项中的姓名临时变量 157 | }); 158 | } else { 159 | let id = options.id; 160 | var self = this; 161 | self.setData({ 162 | id 163 | }); 164 | apiHelper.paramData.cmd = "studyAbroadNews/getNewsDetail"; //cmd 165 | apiHelper.paramData.param = { 166 | id 167 | }; 168 | apiHelper.post((res) => { 169 | if (res.State == 0 && res.Value) { 170 | self.setData({ 171 | newsArray: [res.Value] //当前选择的好友名字赋值给编辑款项中的姓名临时变量 172 | }); 173 | self.loadData(); 174 | } 175 | }); 176 | } 177 | }, 178 | 179 | /** 180 | * 生命周期函数--监听页面初次渲染完成 181 | */ 182 | onReady: function() { 183 | this.animation = wx.createAnimation() 184 | }, 185 | 186 | /** 187 | * 生命周期函数--监听页面显示 188 | */ 189 | onShow: function() { 190 | 191 | }, 192 | 193 | /** 194 | * 生命周期函数--监听页面隐藏 195 | */ 196 | onHide: function() { 197 | 198 | }, 199 | 200 | /** 201 | * 生命周期函数--监听页面卸载 202 | */ 203 | onUnload: function() { 204 | 205 | }, 206 | 207 | /** 208 | * 页面相关事件处理函数--监听用户下拉动作 209 | */ 210 | onPullDownRefresh: function() { 211 | 212 | }, 213 | 214 | /** 215 | * 页面上拉触底事件的处理函数 216 | */ 217 | onReachBottom: function() { 218 | 219 | }, 220 | 221 | 222 | /** 223 | * 用户点击右上角分享 224 | */ 225 | onShareAppMessage: function(res) { 226 | 227 | } 228 | }) -------------------------------------------------------------------------------- /pages/content/content.json: -------------------------------------------------------------------------------- 1 | {} -------------------------------------------------------------------------------- /pages/content/content.wxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | {{item.title}} 10 | 11 | {{item.summary}} 12 | 13 | 14 | 15 | 16 | 17 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 30 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /pages/content/content.wxss: -------------------------------------------------------------------------------- 1 | /* pages/content/content.wxss */ 2 | 3 | swiper { 4 | height: 100%; 5 | width: 100%; 6 | position: fixed; 7 | } 8 | 9 | .content { 10 | /* position: fixed; */ 11 | width: 100%; 12 | height: 100%; 13 | /* background-image: url(http://aojixiaoxi.ks3-cn-beijing.ksyun.com/smallroutine/GPAApplet.png); 14 | background-size: contain; 15 | background-repeat: no-repeat; 16 | background-position: top center; */ 17 | background: #f8f8f8; 18 | /* display: flex; *//* flex-direction: column; 垂直显示 *//* align-items: center; 垂直居中 justify-content: center; 水平居中 */ 19 | box-sizing: border-box; 20 | padding: 30rpx 20rpx 141rpx 20rpx; 21 | } 22 | 23 | /* 24 | ::-webkit-scrollbar { 25 | width: 0; 26 | height: 0; 27 | color: transparent; 28 | } */ 29 | 30 | .content .content_view { 31 | width: 100%; 32 | height: 100%; 33 | overflow-y: auto; 34 | background: #fff; 35 | border-radius: 6rpx; 36 | padding: 0rpx 30rpx 0 30rpx; 37 | box-sizing: border-box; 38 | /* border: 1px solid red; *//* position: relative; */ 39 | } 40 | 41 | .content .content_view .title { 42 | font-size: 40rpx; 43 | color: #000; 44 | text-align: justify; 45 | line-height: 60rpx; 46 | display: block; 47 | margin-top: 50rpx; 48 | margin-bottom: 40rpx; 49 | } 50 | 51 | .content .content_view .title2 { 52 | font-size: 30rpx; 53 | color: #999; 54 | text-align: justify; 55 | overflow: hidden; 56 | } 57 | 58 | .content .content_view .title2 .left { 59 | float: left; 60 | } 61 | 62 | .content .content_view .title2 .right { 63 | float: right; 64 | } 65 | 66 | .content .content_view .content_font { 67 | font-size: 32rpx; 68 | color: #666; 69 | text-align: justify; 70 | line-height: 60rpx; 71 | } 72 | 73 | .content .content_view .page-head-line { 74 | width: 100%; 75 | height: 2rpx; 76 | background-color: #eee; 77 | margin: 50rpx auto; 78 | box-sizing: border-box; 79 | } 80 | 81 | .content .content_header { 82 | width: auto; 83 | height: 104rpx; 84 | box-sizing: border-box; 85 | position: fixed; 86 | top: 30rpx; 87 | left: 20rpx; 88 | right: 20rpx; 89 | z-index: 1; 90 | background: linear-gradient(-180deg, #fff 0%, rgba(255, 255, 255, 0.00) 100%); 91 | } 92 | 93 | .content .content_foot { 94 | height: 112rpx; 95 | width: auto; 96 | bottom: 30rpx; 97 | left: 20rpx; 98 | right: 20rpx; 99 | position: fixed; 100 | box-sizing: border-box; 101 | background: #fff; 102 | padding-left: 30rpx; 103 | } 104 | 105 | .content .content_foot .page-head-line { 106 | width: 100%; 107 | height: 2rpx; 108 | background-color: #eee; 109 | box-sizing: border-box; 110 | } 111 | 112 | .content .content_foot button { 113 | background: #fafafa; 114 | border: 1px solid #d9d9d9; 115 | border-radius: 6px; 116 | width: 180rpx; 117 | height: 60rpx; 118 | line-height: 60rpx; 119 | font-size: 28rpx; 120 | color: #000; 121 | position: absolute; 122 | top: 50%; 123 | left: 30rpx; 124 | transform: translateY(-50%); 125 | } 126 | 127 | .content .content_foot button.back_index { 128 | left: 230rpx; 129 | } 130 | 131 | .content .content_foot .share-img { 132 | height: 100%; 133 | width: 80rpx; 134 | float: right; 135 | padding-right: 30rpx; 136 | } 137 | 138 | .content .content_foot image { 139 | height: 32rpx; 140 | width: 32rpx; 141 | position: absolute; 142 | top: 50%; 143 | right: 30rpx; 144 | transform: translateY(-50%); 145 | } 146 | 147 | .myActionSheet { 148 | width: 100%; 149 | height: 100%; 150 | position: fixed; 151 | background: rgba(0, 0, 0, 0.4); 152 | transform: translate3d(0, 1000px, 0); 153 | transition: transform 0.5s; 154 | } 155 | 156 | .myActionSheet .ul { 157 | bottom: 0; 158 | width: 100%; 159 | position: absolute; 160 | background: #edecf3; 161 | } 162 | 163 | .myActionSheet button { 164 | height: 96rpx; 165 | line-height: 96rpx; 166 | font-size: 30rpx; 167 | color: #333; 168 | text-align: center; 169 | border: none; 170 | background: #fff; 171 | box-sizing: border-box; 172 | width: 100%; 173 | border-radius: 0; 174 | } 175 | 176 | .myActionSheet button::after { 177 | border-bottom: 1px solid #edecf3; 178 | border-radius: 0; 179 | } 180 | 181 | .myActionSheet button:last-child { 182 | margin-top: 10rpx; 183 | border: none; 184 | border-radius: 0; 185 | } 186 | -------------------------------------------------------------------------------- /pages/contentDetails/contentDetails.js: -------------------------------------------------------------------------------- 1 | // pages/contentDetails/contentDetails.js 2 | var apiHelper = require("../../utils/api.js"); 3 | Page({ 4 | /** 5 | * 页面的初始数据 6 | */ 7 | data: { 8 | webUrl: "" 9 | }, 10 | 11 | /** 12 | * 生命周期函数--监听页面加载 13 | */ 14 | onLoad: function(options) { 15 | console.log(options) 16 | let id = options.id; 17 | var self = this; 18 | self.setData({ 19 | webUrl:id 20 | }); 21 | }, 22 | 23 | /** 24 | * 生命周期函数--监听页面初次渲染完成 25 | */ 26 | onReady: function() { 27 | 28 | }, 29 | 30 | /** 31 | * 生命周期函数--监听页面显示 32 | */ 33 | onShow: function() { 34 | 35 | }, 36 | 37 | /** 38 | * 生命周期函数--监听页面隐藏 39 | */ 40 | onHide: function() { 41 | 42 | }, 43 | 44 | /** 45 | * 生命周期函数--监听页面卸载 46 | */ 47 | onUnload: function() { 48 | 49 | }, 50 | 51 | /** 52 | * 页面相关事件处理函数--监听用户下拉动作 53 | */ 54 | onPullDownRefresh: function() { 55 | 56 | }, 57 | 58 | /** 59 | * 页面上拉触底事件的处理函数 60 | */ 61 | onReachBottom: function() { 62 | 63 | }, 64 | 65 | 66 | /** 67 | * 用户点击右上角分享 68 | */ 69 | onShareAppMessage: function(res) { 70 | if (res.from === 'button') { 71 | // 来自页面内转发按钮 72 | console.log(res.target) 73 | } 74 | return { 75 | title: this.data.info.title, 76 | path: '/pages/content/content?id=' + this.data.id, 77 | success: function(res) { 78 | // 转发成功 79 | }, 80 | fail: function(res) { 81 | // 转发失败 82 | } 83 | } 84 | } 85 | }) -------------------------------------------------------------------------------- /pages/contentDetails/contentDetails.json: -------------------------------------------------------------------------------- 1 | {} -------------------------------------------------------------------------------- /pages/contentDetails/contentDetails.wxml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /pages/contentDetails/contentDetails.wxss: -------------------------------------------------------------------------------- 1 | /* pages/contentDetails/contentDetails.wxss */ 2 | 3 | .contentDetails { 4 | width: 100%; 5 | height: 100%; 6 | background: #fff; 7 | border-radius: 6rpx; 8 | padding: 0rpx 30rpx 0 30rpx; 9 | box-sizing: border-box; 10 | } 11 | 12 | .contentDetails .title { 13 | font-size: 40rpx; 14 | color: #000; 15 | text-align: justify; 16 | line-height: 60rpx; 17 | display: block; 18 | margin-top: 50rpx; 19 | margin-bottom: 40rpx; 20 | } 21 | 22 | .contentDetails .title2 { 23 | font-size: 30rpx; 24 | color: #999; 25 | text-align: justify; 26 | overflow: hidden; 27 | } 28 | 29 | .contentDetails .title2 .left { 30 | float: left; 31 | } 32 | 33 | .contentDetails .title2 .right { 34 | float: right; 35 | } 36 | 37 | .contentDetails .content_font { 38 | font-size: 32rpx; 39 | color: #666; 40 | text-align: justify; 41 | line-height: 60rpx; 42 | } 43 | 44 | .contentDetails .page-head-line { 45 | width: 100%; 46 | height: 2rpx; 47 | background-color: #eee; 48 | margin: 50rpx auto; 49 | box-sizing: border-box; 50 | } 51 | 52 | .contentDetails .content_header { 53 | width: auto; 54 | height: 104rpx; 55 | box-sizing: border-box; 56 | position: fixed; 57 | top: 0rpx; 58 | left: 20rpx; 59 | right: 20rpx; 60 | z-index: 1; 61 | background: linear-gradient(-180deg, #fff 0%, rgba(255, 255, 255, 0.00) 100%); 62 | } 63 | -------------------------------------------------------------------------------- /pages/contentShare/contentShare.js: -------------------------------------------------------------------------------- 1 | // pages/contentShare/contentShare.js 2 | var apiHelper = require("../../utils/api.js"); 3 | 4 | function findBreakPoint(text, width, context) { 5 | var min = 0; 6 | var max = text.length - 1; 7 | while (min <= max) { 8 | var middle = Math.floor((min + max) / 2); 9 | var middleWidth = context.measureText(text.substr(0, middle)).width; 10 | var oneCharWiderThanMiddleWidth = context.measureText(text.substr(0, middle + 1)).width; 11 | if (middleWidth <= width && oneCharWiderThanMiddleWidth > width) { 12 | return middle; 13 | } 14 | if (middleWidth < width) { 15 | min = middle + 1; 16 | } else { 17 | max = middle - 1; 18 | } 19 | } 20 | 21 | return -1; 22 | } 23 | 24 | function breakLinesForCanvas(context, text, width, font) { 25 | var result = []; 26 | if (font) { 27 | context.font = font; 28 | } 29 | var textArray = text.split('\r\n'); 30 | for (let i = 0; i < textArray.length; i++) { 31 | let item = textArray[i]; 32 | var breakPoint = 0; 33 | while ((breakPoint = findBreakPoint(item, width, context)) !== -1) { 34 | result.push(item.substr(0, breakPoint)); 35 | item = item.substr(breakPoint); 36 | } 37 | if (item) { 38 | result.push(item); 39 | } 40 | } 41 | return result; 42 | } 43 | Page({ 44 | 45 | /** 46 | * 页面的初始数据 47 | */ 48 | data: { 49 | id: 0, 50 | info: {} 51 | }, 52 | 53 | /** 54 | * 生命周期函数--监听页面加载 55 | */ 56 | onLoad: function(options) { 57 | wx.setNavigationBarColor({ 58 | frontColor: '#ffffff', 59 | backgroundColor: '#010101', 60 | animation: { 61 | duration: 400, 62 | timingFunc: 'easeIn' 63 | } 64 | }) 65 | console.log(options) 66 | let id = options.id; 67 | var self = this; 68 | self.setData({ 69 | id 70 | }); 71 | wx.getStorage({ 72 | key: 'shareInfo', 73 | success: function(res) { 74 | let info = JSON.parse(res.data) 75 | self.setData({ 76 | info 77 | }); 78 | self.drawInit(info); 79 | } 80 | }) 81 | }, 82 | canvasIdErrorCallback: function(e) { 83 | console.error(e.detail.errMsg) 84 | }, 85 | /** 86 | * 生命周期函数--监听页面初次渲染完成 87 | */ 88 | onReady: function(e) {}, 89 | /** 90 | * 绘制图片 91 | */ 92 | drawInit: function(info) { 93 | var contentTitle = info.title; 94 | var contentStr = info.intro; 95 | var that = this 96 | var res = wx.getSystemInfoSync(); 97 | var canvasWidth = res.windowWidth; 98 | // 获取canvas的的宽 自适应宽(设备宽/750) px 99 | var Rpx = (canvasWidth / 375).toFixed(2); 100 | //画布高度 -底部按钮高度 101 | var canvasHeight = res.windowHeight - Rpx * 59; 102 | // 使用 wx.createContext 获取绘图上下文 context 103 | var context = wx.createCanvasContext('secondCanvas') 104 | //设置行高 105 | var lineHeight = Rpx * 30; 106 | //左边距 107 | var paddingLeft = Rpx * 20; 108 | //右边距 109 | var paddingRight = Rpx * 20; 110 | //当前行高 111 | var currentLineHeight = Rpx * 20; 112 | //背景颜色默认填充 113 | context.fillStyle = "#f8f8f8"; 114 | context.fillRect(0, 0, canvasWidth + Rpx * 2, canvasHeight); 115 | //标题内容颜色默认 116 | context.fillStyle = "#fff"; 117 | //高度减去 图片高度 118 | context.fillRect(Rpx * 15, Rpx * 15, canvasWidth - Rpx * 30, canvasHeight); 119 | //设置标题 120 | var resultTitle = breakLinesForCanvas(context, contentTitle, canvasWidth - paddingLeft - paddingRight, `${(Rpx * 20).toFixed(0)}px PingFangSC-Regular`); 121 | //字体颜色 122 | context.fillStyle = '#000000'; 123 | resultTitle.forEach(function(line, index) { 124 | currentLineHeight += Rpx * 30; 125 | context.fillText(line, paddingLeft, currentLineHeight); 126 | }); 127 | //设置 来源 浏览量 128 | var source = `来源:${info.source == 1 ? info.author || "原创" : info.reprintSource || "转载"}` 129 | var browsingVolume = `浏览量:${info.browseCount||0}`; 130 | currentLineHeight += Rpx * 30; 131 | // context.measureText(text).width 132 | context.font = `${(Rpx * 15).toFixed(0)}px PingFangSC-Regular`; 133 | //字体颜色 134 | context.fillStyle = '#999999'; 135 | context.fillText(source, paddingLeft, currentLineHeight); 136 | context.setTextAlign('right'); 137 | context.fillText(browsingVolume, canvasWidth - paddingRight, currentLineHeight); 138 | //恢复左对齐 139 | context.setTextAlign('left'); 140 | //画分割线 141 | currentLineHeight += Rpx * 15; 142 | context.setLineDash([Rpx * 6, Rpx * 3.75]); 143 | context.moveTo(paddingLeft, currentLineHeight); 144 | context.lineTo(canvasWidth - paddingRight, currentLineHeight); 145 | context.strokeStyle = '#cccccc'; 146 | context.stroke(); 147 | //设置内容 148 | var result = breakLinesForCanvas(context, contentStr || '无内容', canvasWidth - paddingLeft - paddingRight, `${(Rpx * 16).toFixed(0)}px PingFangSC-Regular`); 149 | console.log(result); 150 | //字体颜色 151 | context.fillStyle = '#666666'; 152 | result.forEach(function(line, index) { 153 | currentLineHeight += Rpx * 30; 154 | context.fillText(line, paddingLeft, currentLineHeight); 155 | }); 156 | //无广告位 生成文章详情二维码 157 | apiHelper.paramData.cmd = "studyAbroadNews/getQrCode"; //cmd 158 | apiHelper.paramData.param = { 159 | id: that.data.id, 160 | width: 200, 161 | page: "pages/content/content", 162 | colorR: 0, 163 | colorG: 0, 164 | colorB: 0, 165 | isHyaline: true 166 | }; 167 | apiHelper.post((res) => { 168 | if (res.State == 0 && typeof(res.Value) == "string") { 169 | context.drawImage('/imgs/nocode.png', paddingLeft - Rpx * 5, canvasHeight - Rpx * 115, canvasWidth - paddingLeft - paddingRight + Rpx * 10, Rpx * 115); 170 | wx.downloadFile({ 171 | url: res.Value, //仅为示例,并非真实的资源 172 | success: function(res) { 173 | // 只要服务器有响应数据,就会把响应内容写入文件并进入 success 回调,业务需要自行判断是否下载到了想要的内容 174 | if (res.statusCode === 200) { 175 | context.drawImage(res.tempFilePath, Rpx * 30, canvasHeight - Rpx * 115 + Rpx * 10, Rpx * 100, Rpx * 100); 176 | context.draw(); 177 | } 178 | }, 179 | fail: function(err) { 180 | console.error(err) 181 | context.drawImage('/imgs/code.png', paddingLeft - Rpx * 5, canvasHeight - Rpx * 115, canvasWidth - paddingLeft - paddingRight + Rpx * 10, Rpx * 115); 182 | context.draw(); 183 | } 184 | }) 185 | } else { 186 | context.drawImage('/imgs/code.png', paddingLeft - Rpx * 5, canvasHeight - Rpx * 115, canvasWidth - paddingLeft - paddingRight + Rpx * 10, Rpx * 115); 187 | context.draw(); 188 | } 189 | }); 190 | }, 191 | saveImg: function() { 192 | var that = this; 193 | wx.canvasToTempFilePath({ 194 | canvasId: 'secondCanvas', 195 | fileType: 'jpg', 196 | success: function(res) { 197 | console.log(res.tempFilePath) // 返回图片路径 198 | wx.showLoading({ 199 | title: '保存中...', 200 | mask: true 201 | }); 202 | wx.saveImageToPhotosAlbum({ 203 | filePath: res.tempFilePath, 204 | success: function(res) { 205 | wx.showToast({ 206 | title: '保存成功', 207 | icon: 'success', 208 | duration: 2000 209 | }) 210 | }, 211 | fail: function(res) { 212 | wx.hideLoading() 213 | console.log(res) 214 | } 215 | }) 216 | } 217 | }) 218 | }, 219 | /** 220 | * 生命周期函数--监听页面显示 221 | */ 222 | onShow: function() { 223 | 224 | }, 225 | 226 | /** 227 | * 生命周期函数--监听页面隐藏 228 | */ 229 | onHide: function() { 230 | 231 | }, 232 | 233 | /** 234 | * 生命周期函数--监听页面卸载 235 | */ 236 | onUnload: function() { 237 | 238 | }, 239 | 240 | /** 241 | * 页面相关事件处理函数--监听用户下拉动作 242 | */ 243 | onPullDownRefresh: function() { 244 | 245 | }, 246 | 247 | /** 248 | * 页面上拉触底事件的处理函数 249 | */ 250 | onReachBottom: function() { 251 | 252 | }, 253 | 254 | 255 | /** 256 | * 用户点击右上角分享 257 | */ 258 | onShareAppMessage: function(res) { 259 | if (res.from === 'button') { 260 | // 来自页面内转发按钮 261 | console.log(res.target) 262 | } 263 | return { 264 | title: this.data.info.title, 265 | path: '/pages/content/content?id=' + this.data.id, 266 | success: function(res) { 267 | // 转发成功 268 | }, 269 | fail: function(res) { 270 | // 转发失败 271 | } 272 | } 273 | } 274 | }) -------------------------------------------------------------------------------- /pages/contentShare/contentShare.json: -------------------------------------------------------------------------------- 1 | {} -------------------------------------------------------------------------------- /pages/contentShare/contentShare.wxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /pages/contentShare/contentShare.wxss: -------------------------------------------------------------------------------- 1 | /* pages/contentShare/contentShare.wxss */ 2 | 3 | .content-share{ 4 | height: 100%; 5 | width: 100%; 6 | position: fixed; 7 | padding-bottom:120rpx; 8 | box-sizing: border-box; 9 | } 10 | 11 | canvas { 12 | /* border: 1px solid red; */ 13 | box-sizing: border-box; 14 | } 15 | 16 | .foot-button { 17 | height: 120rpx; 18 | width: 100%; 19 | background: #010101; 20 | bottom: 0; 21 | left: 0; 22 | position: absolute; 23 | } 24 | 25 | .foot-button button { 26 | background-color: rgba(255, 255, 255, 0.2); 27 | border-radius: 100rpx; 28 | width: 580rpx; 29 | height: 84rpx; 30 | position: absolute; 31 | top: 50%; 32 | margin-top: -42rpx; 33 | left: 50%; 34 | margin-left: -290rpx; 35 | font-size: 32rpx; 36 | color: #fff; 37 | line-height: 84rpx; 38 | } 39 | -------------------------------------------------------------------------------- /pages/index/index.js: -------------------------------------------------------------------------------- 1 | // pages/index/index.js 2 | var apiHelper = require("../../utils/api.js"); 3 | var util = require("../../utils/util.js"); 4 | let app = getApp(); 5 | Page({ 6 | /** 7 | * 页面的初始数据 8 | */ 9 | data: { 10 | isIphoneX: app.globalData.isIphoneX ? true : false, 11 | currentPageIndex: 1,//当前请求全局页数 12 | currentDate: util.getLocalTime(),//当前请求日期 13 | currentDateIsNoData: true,//当前天是否还有数据 14 | isBusy: false,//是否正在请求数据中 15 | fastScroll: true,//第一次滚动加载 16 | array: [],//日期结构数据 17 | newsArray: []//所有文章存放数组 18 | }, 19 | toPage: function (event) { 20 | wx.navigateTo({ 21 | url: `/pages/content/content?id=${event.currentTarget.id}` 22 | }) 23 | }, 24 | /** 25 | * 生命周期函数--监听页面加载 26 | */ 27 | onLoad: function (options) { 28 | this.getListNew(this.data.currentPageIndex); 29 | }, 30 | 31 | //滚动加载 new 32 | scrolltolowerNewEvent: function (e) { 33 | if (!this.data.isBusy) { 34 | //查看当天是否还有数据 35 | if (this.data.currentDateIsNoData) { 36 | this.data.currentPageIndex = this.data.newsArray[this.data.newsArray.length-1].order; 37 | this.getListNew(this.data.currentPageIndex); 38 | } else { 39 | wx.showToast({ 40 | title: '没有数据了', 41 | icon: 'none', 42 | duration: 500 43 | }) 44 | } 45 | } 46 | }, 47 | /* new */ 48 | getListNew(pageIndex, pageSize = 10) { 49 | this.data.isBusy = true; 50 | var self = this; 51 | apiHelper.paramData.cmd = "news"; //cmd 52 | apiHelper.paramData.loadingState = false; 53 | apiHelper.paramData.param = { 54 | pageIndex, 55 | pageSize 56 | }; 57 | apiHelper.post((res) => { 58 | if (res.State == 0) { 59 | res.Value=res.Value.data; 60 | if (res.Value.length == 0) { 61 | //标识数据已被全部请求完 62 | self.data.currentDateIsNoData = false; 63 | } else { 64 | self.data.newsArray = self.data.newsArray.concat(res.Value); 65 | //数据 剩余条数不超过请求条数,说明下一页已没有数据 66 | if (res.Value.length < pageSize) { 67 | //标识数据已被全部请求完 68 | self.data.currentDateIsNoData = false; 69 | } else { 70 | let array = res.Value; 71 | for (let i = 0; i < array.length; i++) { 72 | // console.log(array[i].publishDate) 73 | let pushdate = array[i].updatedAt.substr(0, 10); 74 | // console.log(pushdate) 75 | pushdate = util.getLocalTime(0, new Date(pushdate)); 76 | if (pushdate == util.getLocalTime()) { 77 | pushdate = "今天"; 78 | } else if (pushdate == util.getLocalTime(-1)) { 79 | pushdate = "昨天"; 80 | } 81 | let index = self.data.array.findIndex(item => { return item.date == pushdate }); 82 | if (index != -1) { 83 | //如果有数据,数组 84 | if (res.Value.length > 0) { 85 | self.data.array[index].array.push(array[i]) 86 | } 87 | else { 88 | //标识当天数据已被全部请求完 89 | self.data.currentDateIsNoData = false; 90 | self.data.currentPageIndex = 1; 91 | } 92 | } else { 93 | self.data.array.push({ 94 | date: pushdate, 95 | array: [array[i]] 96 | }) 97 | } 98 | } 99 | self.data.currentDateIsNoData = true; 100 | } 101 | } 102 | } 103 | self.setData({ 104 | array: self.data.array 105 | }); 106 | this.data.isBusy = false; 107 | },'get'); 108 | }, 109 | /** 110 | * 生命周期函数--监听页面初次渲染完成 111 | */ 112 | onReady: function () { 113 | 114 | }, 115 | 116 | /** 117 | * 生命周期函数--监听页面显示 118 | */ 119 | onShow: function () { 120 | 121 | }, 122 | 123 | /** 124 | * 生命周期函数--监听页面隐藏 125 | */ 126 | onHide: function () { 127 | 128 | }, 129 | 130 | /** 131 | * 生命周期函数--监听页面卸载 132 | */ 133 | onUnload: function () { 134 | 135 | }, 136 | 137 | /** 138 | * 页面相关事件处理函数--监听用户下拉动作 139 | */ 140 | onPullDownRefresh: function () { 141 | console.log("xial") 142 | // wx.startPullDownRefresh() 143 | //在标题栏中显示加载 144 | // wx.showNavigationBarLoading() 145 | }, 146 | 147 | /** 148 | * 页面上拉触底事件的处理函数 149 | */ 150 | onReachBottom: function () { 151 | 152 | }, 153 | 154 | /** 155 | * 用户点击右上角分享 156 | */ 157 | onShareAppMessage: function (res) { 158 | if (res.from === 'button') { 159 | // 来自页面内转发按钮 160 | console.log(res.target) 161 | } 162 | return { 163 | title: '测试', 164 | path: '/pages/index/index', 165 | success: function (res) { 166 | // 转发成功 167 | }, 168 | fail: function (res) { 169 | // 转发失败 170 | } 171 | } 172 | } 173 | 174 | }) -------------------------------------------------------------------------------- /pages/index/index.json: -------------------------------------------------------------------------------- 1 | {} -------------------------------------------------------------------------------- /pages/index/index.wxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | {{item.date}} 5 | 6 | 7 | {{itemContent.title}} 8 | 9 | 10 | {{itemContent.summary}} 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /pages/index/index.wxss: -------------------------------------------------------------------------------- 1 | /* pages/index/index.wxss */ 2 | 3 | .index { 4 | position: fixed; 5 | width: 100%; 6 | height: 100%; 7 | /* background-image: url(http://aojixiaoxi.ks3-cn-beijing.ksyun.com/smallroutine/GPAApplet.png); 8 | background-size: contain; 9 | background-repeat: no-repeat; 10 | background-position: top center; */ 11 | background: #f8f8f8; 12 | display: flex; 13 | flex-direction: column; 14 | align-items: center; /*垂直居中*//* justify-content: center; 水平居中 */ 15 | } 16 | 17 | .index .list { 18 | padding: 0 20rpx; 19 | box-sizing: border-box; 20 | } 21 | 22 | .index .list .title { 23 | padding-left: 15rpx; 24 | margin: 40rpx 0 40rpx 0; 25 | display: block; 26 | box-sizing: border-box; 27 | font-size: 60rpx; 28 | color: #333; 29 | } 30 | 31 | .index .list .content { 32 | padding: 40rpx; 33 | box-sizing: border-box; 34 | background: #fff; 35 | border: 1px solid #eaeaea; 36 | box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.08); 37 | font-size: 25rpx; 38 | line-height: 50rpx; 39 | color: #000; 40 | text-align: justify; 41 | margin-bottom: 20rpx; 42 | } 43 | .index .list .content .title{ 44 | font-size: 30rpx; 45 | line-height: 60rpx; 46 | color: #000; 47 | } 48 | 49 | .index .list .content:last-child { 50 | margin-bottom: 0; 51 | } 52 | 53 | .index .list .content_hover { 54 | background: #e8e8e8; 55 | } 56 | -------------------------------------------------------------------------------- /project.config.json: -------------------------------------------------------------------------------- 1 | { 2 | "description": "项目配置文件。", 3 | "setting": { 4 | "urlCheck": false, 5 | "es6": true, 6 | "postcss": true, 7 | "minified": true, 8 | "newFeature": true 9 | }, 10 | "compileType": "miniprogram", 11 | "libVersion": "2.0.9", 12 | "appid": "wxf9c81770b8ce723a", 13 | "projectname": "News", 14 | "isGameTourist": false, 15 | "simulatorType": "wechat", 16 | "simulatorPluginLibVersion": {}, 17 | "condition": { 18 | "search": { 19 | "current": -1, 20 | "list": [] 21 | }, 22 | "conversation": { 23 | "current": -1, 24 | "list": [] 25 | }, 26 | "game": { 27 | "currentL": -1, 28 | "list": [] 29 | }, 30 | "miniprogram": { 31 | "current": -1, 32 | "list": [] 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /sitemap.json: -------------------------------------------------------------------------------- 1 | { 2 | "desc": "关于本文件的更多信息,请参考文档 https://developers.weixin.qq.com/miniprogram/dev/framework/sitemap.html", 3 | "rules": [{ 4 | "action": "allow", 5 | "page": "*" 6 | }] 7 | } -------------------------------------------------------------------------------- /utils/api.js: -------------------------------------------------------------------------------- 1 | var CryptoJS = require('../libs/aes'); 2 | var CONFIG = require('../config'); 3 | function Encrypt(word, key, iv) { 4 | var srcs = CryptoJS.enc.Utf8.parse(word); 5 | var encrypted = CryptoJS.AES.encrypt(srcs, key, { iv: iv, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7 }); 6 | //return encrypted.ciphertext.toString(); 7 | return encrypted.toString(); 8 | } 9 | 10 | function Decrypt(word, key, iv) { 11 | var encryptedHexStr = CryptoJS.enc.Hex.parse(word); 12 | var srcs = CryptoJS.enc.Base64.stringify(encryptedHexStr); 13 | var decrypt = CryptoJS.AES.decrypt(srcs, key, { iv: iv, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7 }); 14 | var decryptedStr = decrypt.toString(CryptoJS.enc.Utf8); 15 | return decryptedStr.toString(); 16 | } 17 | 18 | function post(cb, requestMethod = "post") { 19 | //check reqData 20 | var key = CryptoJS.enc.Utf8.parse(CONFIG.key); 21 | var iv = CryptoJS.enc.Utf8.parse(CONFIG.iv); 22 | 23 | var host = CONFIG.host + this.paramData.cmd; 24 | var requestData = this.paramData.param; 25 | var sign = Encrypt(JSON.stringify(requestData), key, iv); 26 | sign = encodeURIComponent(sign); 27 | var sendData = `key=${sign}`; 28 | var self = this; 29 | // console.log(`${host}?${sendData}`); 30 | wx.getNetworkType({ 31 | success: function (res) { 32 | // 返回网络类型, 有效值: 33 | // wifi/2g/3g/4g/unknown(Android下不常见的网络类型)/none(无网络) 34 | var networkType = res.networkType 35 | if (networkType != "none") { 36 | 37 | //检查是否需要加载动画 38 | if (self.loadingState) { 39 | wx.showLoading({ 40 | // title: '正在请求...', 41 | mask: true 42 | }); 43 | // wx.showToast({ 44 | // title: 'loading...', 45 | // image: '/imgs/loading.gif', 46 | // duration: 1000 * 30, 47 | // mask: true 48 | // }) 49 | } 50 | self.loadingState = true; 51 | wx.request({ 52 | url: host, 53 | data: requestData, 54 | method: requestMethod, // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT 55 | header: { 56 | 'content-type': 'application/x-www-form-urlencoded', 57 | 'source': "2",//来源 1留学2gpa 58 | }, // 设置请求的 header 59 | success: function (res) { 60 | // success 61 | }, 62 | fail: function (ex) { 63 | // fail 64 | console.log(ex); 65 | }, 66 | complete: function (response) { 67 | //关闭加载动画 68 | wx.hideLoading(); 69 | // wx.hideToast(); 70 | 71 | var resData = { 72 | State: 0, 73 | Value: {}, 74 | Msg: "" 75 | } 76 | if (response.errMsg != "request:ok") { 77 | resData.State = 1; 78 | resData.Value = {}; 79 | resData.Msg = "系统错误,请稍后重试!"; 80 | } else if (response.statusCode == 200) { 81 | resData = response.data; 82 | } 83 | // console.log(resData) 84 | typeof cb == "function" && cb(resData) 85 | if (resData.State == 1) { 86 | wx.showModal({ 87 | title: '错误提示', 88 | content: resData.Msg, 89 | showCancel: false, 90 | success: function (res) { 91 | 92 | } 93 | }); 94 | } 95 | } 96 | }); 97 | } else { 98 | wx.showModal({ 99 | title: '温馨提示', 100 | content: "请检查您的手机网络是否打开!", 101 | showCancel: false, 102 | success: function (res) { 103 | 104 | } 105 | }); 106 | } 107 | } 108 | }) 109 | } 110 | module.exports = { 111 | paramData: { 112 | "param": {}, 113 | "cmd": "", 114 | "loadingState": true 115 | }, 116 | post: post 117 | } -------------------------------------------------------------------------------- /utils/common.wxs: -------------------------------------------------------------------------------- 1 | var formatTime = function (date) { 2 | const year = date.getFullYear() 3 | const month = date.getMonth() + 1 4 | const day = date.getDate() 5 | const hour = date.getHours() 6 | const minute = date.getMinutes() 7 | const second = date.getSeconds() 8 | 9 | return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':') 10 | } 11 | 12 | var formatNumber = function (n) { 13 | n = n.toString() 14 | return n[1] ? n : '0' + n 15 | } 16 | 17 | /* 18 | *单位转换 19 | */ 20 | var unitChange = function (int, unit = false) { 21 | return int > 10000 ? (int / 10000).toFixed(1) + (unit ? '' : '万') : int; 22 | } 23 | /* 24 | *阿拉伯数字转换为简写汉字 25 | */ 26 | var Arabia_To_SimplifiedChinese = function (Num) { 27 | Num = Num.toString(); 28 | for (i = Num.length - 1; i >= 0; i--) { 29 | Num = Num.replace(",", "")//替换Num中的“,” 30 | Num = Num.replace(" ", "")//替换Num中的空格 31 | } 32 | if (isNaN(Num)) { //验证输入的字符是否为数字 33 | //alert("请检查小写金额是否正确"); 34 | return; 35 | } 36 | //字符处理完毕后开始转换,采用前后两部分分别转换 37 | part = Num.split("."); 38 | newchar = ""; 39 | //小数点前进行转化 40 | for (i = part[0].length - 1; i >= 0; i--) { 41 | if (part[0].length > 10) { 42 | //alert("位数过大,无法计算"); 43 | return ""; 44 | }//若数量超过拾亿单位,提示 45 | tmpnewchar = "" 46 | perchar = part[0].charAt(i); 47 | switch (perchar) { 48 | case "0": tmpnewchar = "零" + tmpnewchar; break; 49 | case "1": tmpnewchar = "一" + tmpnewchar; break; 50 | case "2": tmpnewchar = "二" + tmpnewchar; break; 51 | case "3": tmpnewchar = "三" + tmpnewchar; break; 52 | case "4": tmpnewchar = "四" + tmpnewchar; break; 53 | case "5": tmpnewchar = "五" + tmpnewchar; break; 54 | case "6": tmpnewchar = "六" + tmpnewchar; break; 55 | case "7": tmpnewchar = "七" + tmpnewchar; break; 56 | case "8": tmpnewchar = "八" + tmpnewchar; break; 57 | case "9": tmpnewchar = "九" + tmpnewchar; break; 58 | } 59 | switch (part[0].length - i - 1) { 60 | case 0: tmpnewchar = tmpnewchar; break; 61 | case 1: if (perchar != 0) tmpnewchar = tmpnewchar + "十"; break; 62 | case 2: if (perchar != 0) tmpnewchar = tmpnewchar + "百"; break; 63 | case 3: if (perchar != 0) tmpnewchar = tmpnewchar + "千"; break; 64 | case 4: tmpnewchar = tmpnewchar + "万"; break; 65 | case 5: if (perchar != 0) tmpnewchar = tmpnewchar + "十"; break; 66 | case 6: if (perchar != 0) tmpnewchar = tmpnewchar + "百"; break; 67 | case 7: if (perchar != 0) tmpnewchar = tmpnewchar + "千"; break; 68 | case 8: tmpnewchar = tmpnewchar + "亿"; break; 69 | case 9: tmpnewchar = tmpnewchar + "十"; break; 70 | } 71 | newchar = tmpnewchar + newchar; 72 | } 73 | //替换所有无用汉字,直到没有此类无用的数字为止 74 | while (newchar.search("零零") != -1 || newchar.search("零亿") != -1 || newchar.search("亿万") != -1 || newchar.search("零万") != -1) { 75 | newchar = newchar.replace("零亿", "亿"); 76 | newchar = newchar.replace("亿万", "亿"); 77 | newchar = newchar.replace("零万", "万"); 78 | newchar = newchar.replace("零零", "零"); 79 | } 80 | //替换以“一十”开头的,为“十” 81 | if (newchar.indexOf("一十") == 0) { 82 | newchar = newchar.substring(1); 83 | } 84 | //替换以“零”结尾的,为“” 85 | if (newchar.lastIndexOf("零") == newchar.length - 1) { 86 | newchar = newchar.substring(0, newchar.length - 1); 87 | } 88 | return newchar; 89 | } 90 | module.exports = { 91 | Arabia_To_SimplifiedChinese: Arabia_To_SimplifiedChinese, 92 | formatTime: formatTime, 93 | unitChange: unitChange 94 | } 95 | -------------------------------------------------------------------------------- /utils/util.js: -------------------------------------------------------------------------------- 1 | const formatTime = date => { 2 | const year = date.getFullYear() 3 | const month = date.getMonth() + 1 4 | const day = date.getDate() 5 | const hour = date.getHours() 6 | const minute = date.getMinutes() 7 | const second = date.getSeconds() 8 | 9 | return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':') 10 | } 11 | 12 | const formatNumber = n => { 13 | n = n.toString() 14 | return n[1] ? n : '0' + n 15 | } 16 | 17 | function getLocalTime(days = 0, date = new Date()) { 18 | var d = new Date(date); 19 | d.setDate(d.getDate() + days); 20 | var m = d.getMonth() + 1; 21 | return d.getFullYear() + '-' + m + '-' + d.getDate(); 22 | } 23 | module.exports = { 24 | formatTime: formatTime, 25 | getLocalTime: getLocalTime 26 | } 27 | --------------------------------------------------------------------------------