Browse Source

init

jw-featrue-zhanlibiao
mk 2 years ago
commit
e778e2d7a4
  1. 31
      .eslintrc.js
  2. 12
      app.js
  3. 63
      app.json
  4. 10
      app.wxss
  5. BIN
      images/home/information.png
  6. BIN
      images/home/informationSelected.png
  7. BIN
      images/home/message.png
  8. BIN
      images/home/messageSelected.png
  9. BIN
      images/home/mine.png
  10. BIN
      images/home/mineSelected.png
  11. BIN
      images/home/work.png
  12. BIN
      images/home/workSelected.png
  13. BIN
      images/login/hi.png
  14. BIN
      images/login/password.png
  15. BIN
      images/login/user.png
  16. 48
      pages/index/index.js
  17. 4
      pages/index/index.json
  18. 0
      pages/index/index.wxml
  19. 19
      pages/index/index.wxss
  20. 66
      pages/information/information.js
  21. 4
      pages/information/information.json
  22. 2
      pages/information/information.wxml
  23. 1
      pages/information/information.wxss
  24. 130
      pages/login/login.js
  25. 5
      pages/login/login.json
  26. 15
      pages/login/login.wxml
  27. 77
      pages/login/login.wxss
  28. 18
      pages/logs/logs.js
  29. 4
      pages/logs/logs.json
  30. 6
      pages/logs/logs.wxml
  31. 8
      pages/logs/logs.wxss
  32. 66
      pages/message/message.js
  33. 3
      pages/message/message.json
  34. 2
      pages/message/message.wxml
  35. 1
      pages/message/message.wxss
  36. 66
      pages/mine/mine.js
  37. 4
      pages/mine/mine.json
  38. 2
      pages/mine/mine.wxml
  39. 1
      pages/mine/mine.wxss
  40. 66
      pages/work/work.js
  41. 4
      pages/work/work.json
  42. 2
      pages/work/work.wxml
  43. 1
      pages/work/work.wxss
  44. 52
      project.config.json
  45. 21
      project.private.config.json
  46. 7
      sitemap.json
  47. 66
      subpages/addhouse/pages/addhouse/addhouse.js
  48. 3
      subpages/addhouse/pages/addhouse/addhouse.json
  49. 2
      subpages/addhouse/pages/addhouse/addhouse.wxml
  50. 1
      subpages/addhouse/pages/addhouse/addhouse.wxss
  51. 15
      utils/api.js
  52. 34
      utils/checkVersion.js
  53. 24
      utils/config.js
  54. 68
      utils/request.js
  55. 26
      utils/util.js

31
.eslintrc.js

@ -0,0 +1,31 @@
/*
* Eslint config file
* Documentation: https://eslint.org/docs/user-guide/configuring/
* Install the Eslint extension before using this feature.
*/
module.exports = {
env: {
es6: true,
browser: true,
node: true,
},
ecmaFeatures: {
modules: true,
},
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
},
globals: {
wx: true,
App: true,
Page: true,
getCurrentPages: true,
getApp: true,
Component: true,
requirePlugin: true,
requireMiniProgram: true,
},
// extends: 'eslint:recommended',
rules: {},
}

12
app.js

@ -0,0 +1,12 @@
// app.js
App({
onLaunch: function () {
//显示红字,badge
},
globalData: {
userInfo: null
},
globalData: {
userInfo: null
}
})

63
app.json

@ -0,0 +1,63 @@
{
"pages": [
"pages/index/index",
"pages/logs/logs",
"pages/login/login",
"pages/message/message",
"pages/work/work",
"pages/information/information",
"pages/mine/mine"
],
"subPackages":[
{
"root": "subpages/addhouse",
"name": "addhouse",
"pages": [
"pages/addhouse/addhouse"
]
}
],
"window": {
"backgroundTextStyle": "light",
"navigationBarBackgroundColor": "#fff",
"navigationBarTitleText": "WeChat",
"navigationBarTextStyle": "black"
},
"tabBar": {
"color": "#2c2c2c",
"selectedColor": "#e40031",
"backgroundColor": "#FFFFFF",
"borderStyle": "white",
"list": [
{
"pagePath": "pages/index/index",
"text": "消息",
"iconPath": "images/home/message.png",
"selectedIconPath": "images/home/messageSelected.png"
},
{
"pagePath": "pages/work/work",
"text": "工作",
"iconPath": "images/home/work.png",
"selectedIconPath": "images/home/workSelected.png"
},
{
"pagePath": "pages/information/information",
"text": "数据",
"iconPath": "images/home/information.png",
"selectedIconPath": "images/home/informationSelected.png"
},
{
"pagePath": "pages/mine/mine",
"text": "我的",
"iconPath": "images/home/mine.png",
"selectedIconPath": "images/home/mineSelected.png"
}
]
},
"networkTimeout": {
"request": 60000
},
"style": "v2",
"sitemapLocation": "sitemap.json"
}

10
app.wxss

@ -0,0 +1,10 @@
/**app.wxss**/
.container {
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-between;
padding: 200rpx 0;
box-sizing: border-box;
}

BIN
images/home/information.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 293 B

BIN
images/home/informationSelected.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 272 B

BIN
images/home/message.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 315 B

BIN
images/home/messageSelected.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 318 B

BIN
images/home/mine.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 383 B

BIN
images/home/mineSelected.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 380 B

BIN
images/home/work.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 304 B

BIN
images/home/workSelected.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 307 B

BIN
images/login/hi.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

BIN
images/login/password.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

BIN
images/login/user.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

48
pages/index/index.js

@ -0,0 +1,48 @@
// index.js
// 获取应用实例
const app = getApp()
Page({
data: {
motto: 'Hello World',
userInfo: {},
hasUserInfo: false,
canIUse: wx.canIUse('button.open-type.getUserInfo'),
canIUseGetUserProfile: false,
canIUseOpenData: wx.canIUse('open-data.type.userAvatarUrl') && wx.canIUse('open-data.type.userNickName') // 如需尝试获取用户信息可改为false
},
// 事件处理函数
bindViewTap() {
wx.navigateTo({
url: '../logs/logs'
})
},
onLoad() {
if (wx.getUserProfile) {
this.setData({
canIUseGetUserProfile: true
})
}
},
getUserProfile(e) {
// 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认,开发者妥善保管用户快速填写的头像昵称,避免重复弹窗
wx.getUserProfile({
desc: '展示用户信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
success: (res) => {
console.log(res)
this.setData({
userInfo: res.userInfo,
hasUserInfo: true
})
}
})
},
getUserInfo(e) {
// 不推荐使用getUserInfo获取用户信息,预计自2021年4月13日起,getUserInfo将不再弹出弹窗,并直接返回匿名的用户个人信息
console.log(e)
this.setData({
userInfo: e.detail.userInfo,
hasUserInfo: true
})
}
})

4
pages/index/index.json

@ -0,0 +1,4 @@
{
"usingComponents": {},
"navigationBarTitleText": "消息"
}

0
pages/index/index.wxml

19
pages/index/index.wxss

@ -0,0 +1,19 @@
/**index.wxss**/
.userinfo {
display: flex;
flex-direction: column;
align-items: center;
color: #aaa;
}
.userinfo-avatar {
overflow: hidden;
width: 128rpx;
height: 128rpx;
margin: 20rpx;
border-radius: 50%;
}
.usermotto {
margin-top: 200px;
}

66
pages/information/information.js

@ -0,0 +1,66 @@
// pages/information/information.js
Page({
/**
* 页面的初始数据
*/
data: {
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})

4
pages/information/information.json

@ -0,0 +1,4 @@
{
"usingComponents": {},
"navigationBarTitleText": "数据"
}

2
pages/information/information.wxml

@ -0,0 +1,2 @@
<!--pages/information/information.wxml-->
<text>pages/information/information.wxml</text>

1
pages/information/information.wxss

@ -0,0 +1 @@
/* pages/information/information.wxss */

130
pages/login/login.js

@ -0,0 +1,130 @@
// pages/register/register.js
import {userLoginlog} from "../../utils/api"
Page({
/**
* 页面的初始数据
*/
data: {
formData:{
mobile:'',
password:'',
appId:'wxaf87b420b87e2d79'
}
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
handelBlurMobile(e){
this.setData({
'formData.mobile': e.detail.value
})
console.log(this.data.formData)
},
handelBlurPassword(e){
this.setData({
'formData.password': e.detail.value
})
console.log(this.data.formData)
},
handelClickSubmit(){
if(!this.data.formData.mobile){
wx.showToast({
title: '请填写手机号',
icon:'none',
duration:3000
})
return
}
if(!this.data.formData.password){
wx.showToast({
title: '请输入密码',
icon:'none',
duration:3000
})
return
}
wx.showLoading({
title:"登录中..."
})
const parm = {
wxCode :'',
...this.data.formData
}
wx.login({
success: (res) => {
parm.wxCode = res.code
userLoginlog(parm).then((res)=>{
wx.hideLoading()
console.log(res);
if(res.code == 0){
wx.switchTab({
url: '/pages/work/work',
})
}else{
wx.showToast({
title: res.msg,
icon:'none',
duration:2000
})
}
}).catch(err=>{
wx.hideLoading()
console.log(err);
})
},
})
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})

5
pages/login/login.json

@ -0,0 +1,5 @@
{
"navigationBarTitleText": "",
"usingComponents": {},
"navigationBarBackgroundColor": "#1673ee"
}

15
pages/login/login.wxml

@ -0,0 +1,15 @@
<!--pages/register/register.wxml-->
<view class="header">
<image src="../../images/login/hi.png" mode=""/>
<view->欢迎加入亿星社区</view->
</view>
<view class="login">
<view class="input_box">
<image src="../../images/login/user.png" mode=""/>
<input type="text" placeholder="请输入手机号" bindblur="handelBlurMobile" value="{{formData.mobile}}" confirm-type="next"/>
<image src="../../images/login/password.png" mode=""/>
<input type="text" confirm-type="go" password="true" placeholder="请输入密码" bindblur="handelBlurPassword" value="{{formData.password}}" />
</view>
<text wx:if="{{false}}">忘记密码</text>
<button bind:tap="handelClickSubmit">登录</button>
</view>

77
pages/login/login.wxss

@ -0,0 +1,77 @@
/* pages/register/register.wxss */
page {
width: 100%;
min-height: 100vh;
overflow-y: auto;
}
.header {
height: 400rpx;
width: 100%;
background: linear-gradient(180deg, #1673ee 0%, #66A6FD 63%, #F7F7F7 100%);
box-sizing: border-box;
padding: 100rpx 0rpx 100rpx 50rpx;
font-size: 40rpx;
color: #FFFFFF;
display: flex;
flex-direction: column;
}
.header image {
width: 106rpx;
height: 94rpx;
}
.header view {
margin-top:30rpx ;
}
.login{
width: 100%;
height: auto;
position: relative;
top: -90rpx;
border-radius: 60rpx 60rpx 0 0;
background-color: #fff;
box-sizing: border-box;
padding:80rpx 60rpx 0;
}
.login .input_box {
display: flex;
flex-direction: column;
width: 100%;
}
.login input{
width: auto;
height: 93rpx;
background: #F5F5FA;
border-radius: 47rpx;
padding-left: 80rpx;
}
.login image {
width: 46rpx;
height: 46rpx;
position: relative;
left: 20rpx;
top: 70rpx;
}
.login text{
display: inline-block;
font-size: 24rpx;
font-family: PingFang SC;
font-weight: 500;
color: #3E92FF;
margin-top: 36rpx;
padding-left: 20rpx;
}
.login button{
display: block;
background: linear-gradient(87deg, #81B5FB 0%, #3E92FF 100%);
border-radius: 43rpx;
width: auto !important;
color: #fff;
font-size: 32rpx;
font-family: PingFang SC;
margin: 85rpx 0 0 !important;
box-sizing: border-box;
font-weight: 300;
height: 86rpx;
line-height: 86rpx;
padding: 0 !important;
}

18
pages/logs/logs.js

@ -0,0 +1,18 @@
// logs.js
const util = require('../../utils/util.js')
Page({
data: {
logs: []
},
onLoad() {
this.setData({
logs: (wx.getStorageSync('logs') || []).map(log => {
return {
date: util.formatTime(new Date(log)),
timeStamp: log
}
})
})
}
})

4
pages/logs/logs.json

@ -0,0 +1,4 @@
{
"navigationBarTitleText": "查看启动日志",
"usingComponents": {}
}

6
pages/logs/logs.wxml

@ -0,0 +1,6 @@
<!--logs.wxml-->
<view class="container log-list">
<block wx:for="{{logs}}" wx:key="timeStamp" wx:for-item="log">
<text class="log-item">{{index + 1}}. {{log.date}}</text>
</block>
</view>

8
pages/logs/logs.wxss

@ -0,0 +1,8 @@
.log-list {
display: flex;
flex-direction: column;
padding: 40rpx;
}
.log-item {
margin: 10rpx;
}

66
pages/message/message.js

@ -0,0 +1,66 @@
// pages/message/message.js
Page({
/**
* 页面的初始数据
*/
data: {
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})

3
pages/message/message.json

@ -0,0 +1,3 @@
{
"usingComponents": {}
}

2
pages/message/message.wxml

@ -0,0 +1,2 @@
<!--pages/message/message.wxml-->
<text>pages/message/message.wxml</text>

1
pages/message/message.wxss

@ -0,0 +1 @@
/* pages/message/message.wxss */

66
pages/mine/mine.js

@ -0,0 +1,66 @@
// pages/mine/mine.js
Page({
/**
* 页面的初始数据
*/
data: {
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})

4
pages/mine/mine.json

@ -0,0 +1,4 @@
{
"usingComponents": {},
"navigationBarTitleText": "我的"
}

2
pages/mine/mine.wxml

@ -0,0 +1,2 @@
<!--pages/mine/mine.wxml-->
<text>pages/mine/mine.wxml</text>

1
pages/mine/mine.wxss

@ -0,0 +1 @@
/* pages/mine/mine.wxss */

66
pages/work/work.js

@ -0,0 +1,66 @@
// pages/work/work.js
Page({
/**
* 页面的初始数据
*/
data: {
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})

4
pages/work/work.json

@ -0,0 +1,4 @@
{
"usingComponents": {},
"navigationBarTitleText": "工作"
}

2
pages/work/work.wxml

@ -0,0 +1,2 @@
<!--pages/work/work.wxml-->
<text>pages/work/work.wxml</text>

1
pages/work/work.wxss

@ -0,0 +1 @@
/* pages/work/work.wxss */

52
project.config.json

@ -0,0 +1,52 @@
{
"description": "项目配置文件",
"packOptions": {
"ignore": [],
"include": []
},
"setting": {
"bundle": false,
"userConfirmedBundleSwitch": false,
"urlCheck": true,
"scopeDataCheck": false,
"coverView": true,
"es6": true,
"postcss": true,
"compileHotReLoad": false,
"lazyloadPlaceholderEnable": false,
"preloadBackgroundData": false,
"minified": true,
"autoAudits": false,
"newFeature": false,
"uglifyFileName": false,
"uploadWithSourceMap": true,
"useIsolateContext": true,
"nodeModules": false,
"enhance": true,
"useMultiFrameRuntime": true,
"useApiHook": true,
"useApiHostProcess": true,
"showShadowRootInWxmlPanel": true,
"packNpmManually": false,
"enableEngineNative": false,
"packNpmRelationList": [],
"minifyWXSS": true,
"showES6CompileOption": false,
"minifyWXML": true,
"babelSetting": {
"ignore": [],
"disablePlugins": [],
"outputPath": ""
},
"condition": false
},
"compileType": "miniprogram",
"libVersion": "2.19.4",
"appid": "wxaf87b420b87e2d79",
"projectname": "miniprogram-92",
"condition": {},
"editorSetting": {
"tabIndent": "insertSpaces",
"tabSize": 4
}
}

21
project.private.config.json

@ -0,0 +1,21 @@
{
"description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档:https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html",
"projectname": "epmet-work-minniprogram",
"setting": {
"compileHotReLoad": true,
"urlCheck": false
},
"condition": {
"miniprogram": {
"list": [
{
"name": "登录",
"pathName": "pages/login/login",
"query": "",
"launchMode": "default",
"scene": null
}
]
}
}
}

7
sitemap.json

@ -0,0 +1,7 @@
{
"desc": "关于本文件的更多信息,请参考文档 https://developers.weixin.qq.com/miniprogram/dev/framework/sitemap.html",
"rules": [{
"action": "allow",
"page": "*"
}]
}

66
subpages/addhouse/pages/addhouse/addhouse.js

@ -0,0 +1,66 @@
// subpages/addhouse/pages/addhouse/addhouse.js
Page({
/**
* 页面的初始数据
*/
data: {
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})

3
subpages/addhouse/pages/addhouse/addhouse.json

@ -0,0 +1,3 @@
{
"usingComponents": {}
}

2
subpages/addhouse/pages/addhouse/addhouse.wxml

@ -0,0 +1,2 @@
<!--subpages/addhouse/pages/addhouse/addhouse.wxml-->
<text>subpages/addhouse/pages/addhouse/addhouse.wxml</text>

1
subpages/addhouse/pages/addhouse/addhouse.wxss

@ -0,0 +1 @@
/* subpages/addhouse/pages/addhouse/addhouse.wxss */

15
utils/api.js

@ -0,0 +1,15 @@
var fly = require('./request.js')
module.exports = {
getInvitation:getInvitation,
userLoginlog:userLoginlog,
}
function getInvitation(id){
return fly.get(`app-user/user/ma/v3/getInvitation/${id}`)
}
/**
*小程序用户登录日志
*/
function userLoginlog (para) {
return fly.post('auth/gov/loginbypassword', para)
}

34
utils/checkVersion.js

@ -0,0 +1,34 @@
export default function checkVersion() {
return new Promise((resolve, reject) => {
if (wx.canIUse('getUpdateManager')) {
const updateManager = wx.getUpdateManager()
updateManager.onCheckForUpdate(res => {
if (res.hasUpdate) {
updateManager.onUpdateReady(() => {
wx.showModal({
title: '更新提示',
content: '新版本已经准备好, 是否重启应用',
success (successRes) {
if (successRes.confirm) {
updateManager.applyUpdate()
}
}
})
resolve(true)
})
updateManager.onUpdateFailed(() => {
wx.showModal({
title: '更新提示',
content: '新版本已经上线了,请您删除当前小程序,重新搜索打开~'
})
reject(false)
})
} else {
resolve(true)
}
})
} else {
reject(false)
}
})
}

24
utils/config.js

@ -0,0 +1,24 @@
module.exports = {
BASEURL: BASEURL,
WEBROOT: WEBROOT,
Token: getToken,
userId: ""
};
function BASEURL() {
// return 'https://epdc-shibei.elinkservice.cn/epdc-api/api/' // 正式环境
// return 'http://10.10.10.66:9094/epdc-api/api/' // 王童本地环境地址
return 'http://192.168.1.144/api/' // 测试环境
}
function WEBROOT() {
// return 'https://epdc-shibei.elinkservice.cn/epidemic/appraise.html#/cadre-list' // 街道干部评价h5地址
// return 'http://lihenian.gitee.io/epidemic/appraise.html#/cadre-list' // 街道干部评价h5地址测试环境
// https://lyljdgs.qingdaoshibei.cn/app/mobileapp/qlsb/index.aspx
return 'https://lyljdgs.qingdaoshibei.cn/app/mobileapp/qlsb/index.aspx'// 2020-05-20
}
function getToken() {
return wx.getStorageSync("token");
}

68
utils/request.js

@ -0,0 +1,68 @@
var global = require('./config.js')
const request = function (url, options) {
let token = wx.getStorageSync('token')
if (token==undefined || token==null) {
token = ''
}
return new Promise((resolve, reject) => {
wx.request({
url: `${global.BASEURL()}${url}`,
method: options.method,
data: options.method === 'GET' ? options.data : JSON.stringify(options.data),
header: {
'Content-Type': 'application/json; charset=UTF-8',
'Authorization': token
},
success (response) {
if (response.statusCode === 200) {
if(response.data.code===0){
resolve(response.data)
}else{
let errmsg = response.data.msg
if(errmsg==undefined || errmsg=='undefined' ){
errmsg = '未返回错误信息'
}
wx.showToast({
title: errmsg,
icon: 'none',
duration: 3000
})
reject(response.data)
}
} else {
wx.showToast({
title: '网络问题,请稍后再试。',
icon: 'none',
duration: 2000
})
reject(false)
}
},
fail (error) {
wx.showToast({
title: '网络问题,请稍后再试。',
icon: 'none',
duration: 2000
})
reject(error.data)
}
})
})
}
function get(url, options = {}) {
return request(url, { method: 'GET', data: options })
}
function post(url, options = {}) {
return request(url, { method: 'POST', data: options })
}
function put(url, options = {}) {
return request(url, { method: 'PUT', data: options })
}
module.exports = {
get: get,
post: post,
put: put
}

26
utils/util.js

@ -0,0 +1,26 @@
const formatTime = date => {
const year = date.getFullYear()
const month = date.getMonth() + 1
const day = date.getDate()
const hour = date.getHours()
const minute = date.getMinutes()
const second = date.getSeconds()
return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}
const formatNumber = n => {
n = n.toString()
return n[1] ? n : '0' + n
}
const formatRichText = html => {
let newContent= html.replace(/\<img/gi, '<img style="width:100%;height:auto;display:block;"');
return newContent
}
module.exports = {
formatTime: formatTime,
formatRichText: formatRichText
}
Loading…
Cancel
Save