diff --git a/.gitignore b/.gitignore index 14ea590..6562434 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ $RECYCLE.BIN/ .Spotlight-V100 .TemporaryItems .Trashes +.vscode # Node.js node_modules/ diff --git a/app.js b/app.js new file mode 100644 index 0000000..03491f3 --- /dev/null +++ b/app.js @@ -0,0 +1,41 @@ +/* + * @Description: app.js + * @Author: LiuJia + * @LastEditors: LiuJia + * @Date: 2019-03-18 19:28:49 + * @LastEditTime: 2019-03-18 20:02:24 + */ + +const core = require('utils/core.js'); + +App({ + + /** + * @description: onLaunch + * @param {type} + */ + onLaunch(options) { + + }, + + + /** + * @description: onShow + * @param {type} + */ + onShow(options) { + core.keepScreenOn(); //当保持手机屏幕常亮 + core.checkUpdata(); //检测小程序更新 + }, + + + /** + * @description: 引用js文件 + * @param {String} fileName:utils目录下的js文件名称 + * @return: fileName.js + */ + requirejs: function (fileName) { + return require(`utils/${fileName}.js`); + }, + +}); \ No newline at end of file diff --git a/app.json b/app.json new file mode 100644 index 0000000..ac8ac53 --- /dev/null +++ b/app.json @@ -0,0 +1,12 @@ +{ + "pages":[ + "pages/index/index", + "pages/login/index" + ], + "window":{ + "backgroundTextStyle":"light", + "navigationBarBackgroundColor": "#fff", + "navigationBarTitleText": "coderiver", + "navigationBarTextStyle":"black" + } +} diff --git a/app.less b/app.less new file mode 100644 index 0000000..ea3bc12 --- /dev/null +++ b/app.less @@ -0,0 +1,17 @@ +page { + width: 100%; + max-width: 100%; + overflow-x: hidden; + font-size: 24rpx; + background: white; + font-family: "pingFang SC" "pingFang" Arial, Helvetica, sans-serif; + } + + view{ + box-sizing: border-box; + } + + navigator{ + box-sizing: border-box; + display: block; + } \ No newline at end of file diff --git a/app.wxss b/app.wxss new file mode 100644 index 0000000..09917b6 --- /dev/null +++ b/app.wxss @@ -0,0 +1,17 @@ +page { + width: 100%; + max-width: 100%; + overflow-x: hidden; + font-size: 24rpx; + background: white; + font-family: "pingFang SC" "pingFang" Arial, Helvetica, sans-serif; +} +view { + -moz-box-sizing: border-box; + box-sizing: border-box; +} +navigator { + -moz-box-sizing: border-box; + box-sizing: border-box; + display: block; +} diff --git a/pages/index/index.js b/pages/index/index.js new file mode 100644 index 0000000..4348d08 --- /dev/null +++ b/pages/index/index.js @@ -0,0 +1,78 @@ +/* + * @Description: 首页 + * @Author: LiuJia + * @LastEditors: LiuJia + * @Date: 2019-03-18 19:24:20 + * @LastEditTime: 2019-03-18 20:16:11 + */ + + +const app = getApp(); +const core = app.requirejs('core'); + + +Page({ + + /** + * 页面的初始数据 + */ + data: { + + }, + + /** + * 生命周期函数--监听页面加载 + */ + onLoad: function (options) { + + }, + + /** + * 生命周期函数--监听页面初次渲染完成 + */ + onReady: function () { + + }, + + /** + * 生命周期函数--监听页面显示 + */ + onShow: function () { + + }, + + /** + * 生命周期函数--监听页面隐藏 + */ + onHide: function () { + + }, + + /** + * 生命周期函数--监听页面卸载 + */ + onUnload: function () { + + }, + + /** + * 页面相关事件处理函数--监听用户下拉动作 + */ + onPullDownRefresh: function () { + + }, + + /** + * 页面上拉触底事件的处理函数 + */ + onReachBottom: function () { + + }, + + /** + * 用户点击右上角分享 + */ + onShareAppMessage: function () { + + } +}) \ No newline at end of file diff --git a/pages/index/index.json b/pages/index/index.json new file mode 100644 index 0000000..077404a --- /dev/null +++ b/pages/index/index.json @@ -0,0 +1,3 @@ +{ + +} \ No newline at end of file diff --git a/pages/index/index.less b/pages/index/index.less new file mode 100644 index 0000000..23b7126 --- /dev/null +++ b/pages/index/index.less @@ -0,0 +1,8 @@ +.title{ + width: 100%; + text-align: center; + color: #333; + font-size: 52rpx; + font-weight: bold; + margin-top: 100rpx; +} \ No newline at end of file diff --git a/pages/index/index.wxml b/pages/index/index.wxml new file mode 100644 index 0000000..017969e --- /dev/null +++ b/pages/index/index.wxml @@ -0,0 +1 @@ +CodeRiver开源项目 \ No newline at end of file diff --git a/pages/index/index.wxss b/pages/index/index.wxss new file mode 100644 index 0000000..384e495 --- /dev/null +++ b/pages/index/index.wxss @@ -0,0 +1,8 @@ +.title { + width: 100%; + text-align: center; + color: #333; + font-size: 52rpx; + font-weight: bold; + margin-top: 100rpx; +} diff --git a/pages/login/index.js b/pages/login/index.js new file mode 100644 index 0000000..00fe89d --- /dev/null +++ b/pages/login/index.js @@ -0,0 +1,76 @@ +/* + * @Description: 登录页面 + * @Author: LiuJia + * @LastEditors: LiuJia + * @Date: 2019-03-18 20:15:10 + * @LastEditTime: 2019-03-18 20:15:50 + */ + + const app = getApp(); + const core = app.requirejs('core'); + +Page({ + + /** + * 页面的初始数据 + */ + data: { + + }, + + /** + * 生命周期函数--监听页面加载 + */ + onLoad: function (options) { + + }, + + /** + * 生命周期函数--监听页面初次渲染完成 + */ + onReady: function () { + + }, + + /** + * 生命周期函数--监听页面显示 + */ + onShow: function () { + + }, + + /** + * 生命周期函数--监听页面隐藏 + */ + onHide: function () { + + }, + + /** + * 生命周期函数--监听页面卸载 + */ + onUnload: function () { + + }, + + /** + * 页面相关事件处理函数--监听用户下拉动作 + */ + onPullDownRefresh: function () { + + }, + + /** + * 页面上拉触底事件的处理函数 + */ + onReachBottom: function () { + + }, + + /** + * 用户点击右上角分享 + */ + onShareAppMessage: function () { + + } +}) \ No newline at end of file diff --git a/pages/login/index.json b/pages/login/index.json new file mode 100644 index 0000000..0e0dcd2 --- /dev/null +++ b/pages/login/index.json @@ -0,0 +1,3 @@ +{ + +} \ No newline at end of file diff --git a/pages/login/index.less b/pages/login/index.less new file mode 100644 index 0000000..e69de29 diff --git a/pages/login/index.wxml b/pages/login/index.wxml new file mode 100644 index 0000000..6166f01 --- /dev/null +++ b/pages/login/index.wxml @@ -0,0 +1,2 @@ + +pages/login/index.wxml diff --git a/pages/login/index.wxss b/pages/login/index.wxss new file mode 100644 index 0000000..e69de29 diff --git a/project.config.json b/project.config.json new file mode 100644 index 0000000..3fce5bd --- /dev/null +++ b/project.config.json @@ -0,0 +1,40 @@ +{ + "description": "项目配置文件", + "packOptions": { + "ignore": [] + }, + "setting": { + "urlCheck": true, + "es6": true, + "postcss": true, + "minified": true, + "newFeature": true, + "autoAudits": false + }, + "compileType": "miniprogram", + "libVersion": "2.6.2", + "appid": "wx663c19c59130d433", + "projectname": "coderiver-mini-program", + "debugOptions": { + "hidedInDevtools": [] + }, + "isGameTourist": false, + "condition": { + "search": { + "current": -1, + "list": [] + }, + "conversation": { + "current": -1, + "list": [] + }, + "game": { + "currentL": -1, + "list": [] + }, + "miniprogram": { + "current": -1, + "list": [] + } + } +} \ No newline at end of file diff --git a/utils/config.js b/utils/config.js new file mode 100644 index 0000000..74adeb1 --- /dev/null +++ b/utils/config.js @@ -0,0 +1,17 @@ +/* + * @Description: 全局配置文件 + * @Author: LiuJia + * @LastEditors: LiuJia + * @Date: 2019-03-18 19:29:00 + * @LastEditTime: 2019-03-18 19:32:09 + */ + +const CURRENT_ENV = 'dev'; //当前环境配置, 测试环境:dev 正式环境:build +const DEV_HOST_URL = 'https://www.xxx.com'; //测试环境API地址 +const BUILD_HOST_URL = 'https://www.xxx.com'; //正式环境API地址 +const VERSION = '/api/v1'; //接口版本号 +const HOST_URL = CURRENT_ENV === 'dev' ? `${DEV_HOST_URL}${VERSION}` : `${BUILD_HOST_URL}${VERSION}`; //API地址 + +module.exports = { + HOST_URL: HOST_URL, +}; \ No newline at end of file diff --git a/utils/core.js b/utils/core.js new file mode 100644 index 0000000..57324a0 --- /dev/null +++ b/utils/core.js @@ -0,0 +1,234 @@ +/* + * @Description: 核心方法 + * @Author: LiuJia + * @LastEditors: LiuJia + * @Date: 2019-03-18 19:28:49 + * @LastEditTime: 2019-03-18 20:23:20 + */ + +const config = require('./config.js'); //引入config.js + + + +/** + * @description: 函数方法中参数校验,如果没有传参,则抛出错误 + * @param {type} + */ +const required = () => { + throw new Error('参数不完整'); +}; + + + +/** + * @description: 小程序检测更新 + * @param {type} + */ +const checkUpdata = () => { + const updateManager = wx.getUpdateManager(); + updateManager.onCheckForUpdate(function (res) { + //console.log(res); + }); + updateManager.onUpdateReady(function () { + wx.showModal({ + title: '更新提示', + content: '新版本已经准备好,点击确定重启应用', + showCancel: false, //不显示'取消'按钮 + success: function (res) { + if (res.confirm) { + updateManager.applyUpdate(); + } + } + }); + }); + updateManager.onUpdateFailed(function () {}); +}; + + +/** + * @description: get请求 + * @param {String} url 接口地址 + * @param {Object} params 请求参数 + */ +const get = (url, params) => { + const promise = new Promise((resolve, reject) => { + wx.request({ + url: `${config.HOST_URL}${url}`, + method: 'GET', + data: params, + header: { + 'content-type': 'application/json' + }, + dataType: 'json', + success: resolve, + fail: reject, + }); + }); + return promise; +}; + + + +/** + * @description: post请求 + * @param {String} url 接口地址 + * @param {Object} params 请求参数 + */ +const post = (url, params) => { + const promise = new Promise((resolve, reject) => { + wx.request({ + url: `${config.HOST_URL}${url}`, + method: 'POST', + data: params, + header: { + 'Accept': 'application/json', + 'content-type': 'application/json', + }, + dataType: 'json', + success: resolve, + fail: reject, + }); + }); + return promise; +}; + + + +/** + * @description: 获取url中特定参数的值 + * @param {String} 必填 url 链接地址 + * @param {String} 必填 name 参数名称 + * @return {String} 参数的值 + */ +const getQueryByName = (url = required(), name = required()) => { + const reg = new RegExp(`[?&]${name}=([^&#]+)`); + const query = url.match(reg); + return query ? query[1] : null; +}; + + + +/** + * @description: 11位手机号码正则表达式 + * @param {String} phone 手机号码 + * @return {Booleans} true 手机号码正确 false 手机号码错误 + */ +const phoneReg = (phone = required()) => { + const re = /^[1][3,4,5,6,7,8,9][0-9]{9}$/; + if (re.test(phone)) { + return true; + } else { + return false; + } +}; + + + +/** + * @description: 返回上一页 + * @param {Number} num 返回上一级页面的页面数,不传参的情况下,默认为1 + * @param {Number} time 等待多少毫秒返回上一页,不填写的情况下默认为0 + */ +const back = (num, time) => { + const _num = num || 1; + const _time = time || 0; + setTimeout(function () { + wx.navigateBack({ + delta: _num, + }); + }, _time); +}; + + +/** + * @description: 保留数字小数点后N位, 如N=2时, 3.1415处理后为 3.14 , 8.7896处理后位8.78 + * @param {Number/String} 必填 num 原数字 + * @param {Number} 必填 digit 想保留小数点后几位 + * @return {Number/String} finallNum 处理过的新数字 + */ +const numFixed = (num = required(), digit = required()) => { + const tempNum = String(num); + const tempDigit = Number(digit); + const re = new RegExp(`([0-9]+\.[0-9]{${tempDigit}})[0-9]*`); + const finallNum = Number(tempNum.replace(re, "$1")); + return finallNum; +}; + + + +/** + * @description: showModal + * @param {String} 必填 title 模态窗标题 + * @param {String} 必填 content 模态窗提示内容 + * @return promis + */ +const showModal = (title = required(), content = required()) => { + const promise = new Promise((resolve, reject) => { + wx.showModal({ + title: title, + content: content, + success: resolve, + fail: reject, + }); + }); + return promise; +}; + + + +/** + * @description: 显示带有遮罩层的loading动画 + * @param {String} title 提示内容 + */ +const showLoading = (title) => { + const _title = title || ''; + wx.showLoading({ + title: _title, + mask: true, + }); +}; + + + +/** + * @description: toast + * @param {String} title 提示内容 必填 + * @param {String} icon toast图标样式,默认为'none',可选'success' + * @param {Number} time toast持续显示的时间 + */ +const toast = (title = required(), time, icon) => { + const _time = time || 2000; + const _icon = icon || 'none'; + + const promise = new Promise((resolve, reject) => { + wx.showToast({ + title: title, + icon: _icon, + duration: _time, + mask: true, + success: () => { + setTimeout(() => { + resolve(); + }, _time); + }, + fail: () => { + reject(); + }, + }); + }); + return promise; +}; + + +module.exports = { + checkUpdata: checkUpdata, //小程序检测更新 + get: get, //get请求 + post: post, //post请求 + getQueryByName: getQueryByName, //获取url中特定参数的值 + phoneReg: phoneReg, //手机号码验证 + back: back, //返回上一页 + numFixed: numFixed, //保留数字小数点后N位 + showModal: showModal, //模态弹窗 + showLoading: showLoading, //显示加载遮罩层 + toast: toast, //出现提示 +}; \ No newline at end of file diff --git a/utils/event.js b/utils/event.js new file mode 100644 index 0000000..57c6c36 --- /dev/null +++ b/utils/event.js @@ -0,0 +1,36 @@ +let events = {}; + +function on(name, self, callback) { + let tuple = [self, callback]; + let callbacks = events[name]; + if (Array.isArray(callbacks)) { + callbacks.push(tuple); + } + else { + events[name] = [tuple]; + } +} + +function remove(name, self) { + let callbacks = events[name]; + if (Array.isArray(callbacks)) { + events[name] = callbacks.filter((tuple) => { + return tuple[0] != self; + }) + } +} + +function emit(name, data) { + let callbacks = events[name]; + if (Array.isArray(callbacks)) { + callbacks.map((tuple) => { + let self = tuple[0]; + let callback = tuple[1]; + callback.call(self, data); + }) + } +} + +exports.on = on; +exports.remove = remove; +exports.emit = emit; \ No newline at end of file