From cd7cf5116770fa19ebc33055f1af297f1b777dff Mon Sep 17 00:00:00 2001 From: LiuJia <460705950@qq.com> Date: Mon, 18 Mar 2019 20:08:34 +0800 Subject: [PATCH 1/4] init --- .gitignore | 1 + app.js | 41 +++++++ app.json | 11 ++ app.less | 17 +++ app.wxss | 17 +++ pages/index/index.js | 65 ++++++++++++ pages/index/index.json | 3 + pages/index/index.less | 8 ++ pages/index/index.wxml | 1 + pages/index/index.wxss | 8 ++ project.config.json | 40 +++++++ utils/config.js | 17 +++ utils/core.js | 236 +++++++++++++++++++++++++++++++++++++++++ utils/event.js | 36 +++++++ 14 files changed, 501 insertions(+) create mode 100644 app.js create mode 100644 app.json create mode 100644 app.less create mode 100644 app.wxss create mode 100644 pages/index/index.js create mode 100644 pages/index/index.json create mode 100644 pages/index/index.less create mode 100644 pages/index/index.wxml create mode 100644 pages/index/index.wxss create mode 100644 project.config.json create mode 100644 utils/config.js create mode 100644 utils/core.js create mode 100644 utils/event.js 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..15026e3 --- /dev/null +++ b/app.json @@ -0,0 +1,11 @@ +{ + "pages":[ + "pages/index/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..370adb4 --- /dev/null +++ b/pages/index/index.js @@ -0,0 +1,65 @@ +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/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..0a4007f --- /dev/null +++ b/utils/core.js @@ -0,0 +1,236 @@ +/* + * @Description: 核心方法 + * @Author: LiuJia + * @LastEditors: LiuJia + * @Date: 2019-03-18 19:28:49 + * @LastEditTime: 2019-03-18 20:01:39 + */ + +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 From dc89e4301fd0e71b2729cb832981692ca239f63b Mon Sep 17 00:00:00 2001 From: LiuJia <460705950@qq.com> Date: Mon, 18 Mar 2019 20:16:25 +0800 Subject: [PATCH 2/4] update --- app.json | 2 ++ pages/index/index.js | 13 ++++++++ pages/login/index.js | 76 ++++++++++++++++++++++++++++++++++++++++++ pages/login/index.json | 3 ++ pages/login/index.less | 0 pages/login/index.wxml | 2 ++ pages/login/index.wxss | 0 7 files changed, 96 insertions(+) create mode 100644 pages/login/index.js create mode 100644 pages/login/index.json create mode 100644 pages/login/index.less create mode 100644 pages/login/index.wxml create mode 100644 pages/login/index.wxss diff --git a/app.json b/app.json index 15026e3..5ed92dd 100644 --- a/app.json +++ b/app.json @@ -1,6 +1,8 @@ { "pages":[ + "pages/login/index", "pages/index/index" + ], "window":{ "backgroundTextStyle":"light", diff --git a/pages/index/index.js b/pages/index/index.js index 370adb4..4348d08 100644 --- a/pages/index/index.js +++ b/pages/index/index.js @@ -1,3 +1,16 @@ +/* + * @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({ /** 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 From d0b3628c15e25dff5f31e393261ffbd75a413fe3 Mon Sep 17 00:00:00 2001 From: LiuJia <460705950@qq.com> Date: Mon, 18 Mar 2019 20:17:30 +0800 Subject: [PATCH 3/4] update --- app.json | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app.json b/app.json index 5ed92dd..ac8ac53 100644 --- a/app.json +++ b/app.json @@ -1,8 +1,7 @@ { "pages":[ - "pages/login/index", - "pages/index/index" - + "pages/index/index", + "pages/login/index" ], "window":{ "backgroundTextStyle":"light", From 6f980828b6209af690c19afb1d0c97ed87d70c6e Mon Sep 17 00:00:00 2001 From: LiuJia <460705950@qq.com> Date: Mon, 18 Mar 2019 20:23:27 +0800 Subject: [PATCH 4/4] update --- utils/core.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/utils/core.js b/utils/core.js index 0a4007f..57324a0 100644 --- a/utils/core.js +++ b/utils/core.js @@ -3,7 +3,7 @@ * @Author: LiuJia * @LastEditors: LiuJia * @Date: 2019-03-18 19:28:49 - * @LastEditTime: 2019-03-18 20:01:39 + * @LastEditTime: 2019-03-18 20:23:20 */ const config = require('./config.js'); //引入config.js @@ -132,7 +132,6 @@ const phoneReg = (phone = required()) => { const back = (num, time) => { const _num = num || 1; const _time = time || 0; - setTimeout(function () { wx.navigateBack({ delta: _num, @@ -217,7 +216,6 @@ const toast = (title = required(), time, icon) => { }, }); }); - return promise; }; @@ -231,6 +229,6 @@ module.exports = { back: back, //返回上一页 numFixed: numFixed, //保留数字小数点后N位 showModal: showModal, //模态弹窗 - showLoading: showLoading, //显示加载遮罩层 - toast: toast, //出现提示 + showLoading: showLoading, //显示加载遮罩层 + toast: toast, //出现提示 }; \ No newline at end of file pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy