first commit

master
lixin 4 years ago
commit 215b9d6f08

@ -0,0 +1,38 @@
// app.js
let utils = require('utils/util');
App({
onLaunch() {
// 获取用户信息
wx.getSetting({
success: res => {
if (res.authSetting['scope.userInfo']) {
// 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
wx.getUserInfo({
success: res => {
// 可以将 res 发送给后台解码出 unionId
this.globalData.userInfo = res.userInfo
// 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
// 所以此处加入 callback 以防止这种情况
if (this.userInfoReadyCallback) {
this.userInfoReadyCallback(res)
}
}
})
}
}
})
},
globalData: {
url: 'http://192.168.1.107:8080/wx/api',
token: '',
code: '',
// 用户状态 2需要提交审核1跳转到禁止访问
status: 2,
// 审核状态0 跳转到正在审核
flag: 0,
userInfo: null,
address: ''
},
utils
})

@ -0,0 +1,15 @@
{
"pages": [
"pages/index/index",
"pages/record/record",
"pages/order/order"
],
"window": {
"backgroundTextStyle": "light",
"navigationBarBackgroundColor": "#fff",
"navigationBarTitleText": "病案申请",
"navigationBarTextStyle": "black"
},
"style": "v2",
"sitemapLocation": "sitemap.json"
}

@ -0,0 +1,105 @@
/**app.wxss**/
@import "colorui/main.wxss";
@import "colorui/icon.wxss";
.container {
margin-top: 200px;
box-sizing: border-box;
}
.nav-list {
display: flex;
flex-wrap: wrap;
padding: 0px 40rpx 0px;
justify-content: space-between;
}
.nav-li {
padding: 30rpx;
border-radius: 12rpx;
width: 45%;
margin: 0 2.5% 40rpx;
position: relative;
z-index: 1;
}
.nav-li::after {
content: "";
position: absolute;
z-index: -1;
background-color: inherit;
width: 100%;
height: 100%;
left: 0;
bottom: -10%;
border-radius: 10rpx;
opacity: 0.2;
transform: scale(0.9, 0.9);
}
.nav-li.cur {
color: #fff;
background: rgb(94, 185, 94);
box-shadow: 4rpx 4rpx 6rpx rgba(94, 185, 94, 0.4);
}
.nav-title {
font-size: 32rpx;
font-weight: 300;
}
.nav-title::first-letter {
font-size: 40rpx;
margin-right: 4rpx;
}
.nav-name {
font-size: 28rpx;
text-transform: Capitalize;
margin-top: 20rpx;
position: relative;
}
.nav-name::before {
content: "";
position: absolute;
display: block;
width: 40rpx;
height: 6rpx;
background: #fff;
bottom: 0;
right: 0;
opacity: 0.5;
}
.nav-name::after {
content: "";
position: absolute;
display: block;
width: 100rpx;
height: 1px;
background: #fff;
bottom: 0;
right: 40rpx;
opacity: 0.3;
}
.nav-name::first-letter {
font-weight: bold;
font-size: 36rpx;
margin-right: 1px;
}
.nav-li text {
position: absolute;
right: 30rpx;
top: 30rpx;
font-size: 52rpx;
width: 60rpx;
height: 60rpx;
text-align: center;
line-height: 60rpx;
}
.text-light {
font-weight: 300;
}

@ -0,0 +1,184 @@
/*
Animation 微动画
基于ColorUI组建库的动画模块 by 文晓港 2019年3月26日19:52:28
*/
/* css 滤镜 控制黑白底色gif的 */
.gif-black{
mix-blend-mode: screen;
}
.gif-white{
mix-blend-mode: multiply;
}
/* Animation css */
[class*=animation-] {
animation-duration: .5s;
animation-timing-function: ease-out;
animation-fill-mode: both
}
.animation-fade {
animation-name: fade;
animation-duration: .8s;
animation-timing-function: linear
}
.animation-scale-up {
animation-name: scale-up
}
.animation-scale-down {
animation-name: scale-down
}
.animation-slide-top {
animation-name: slide-top
}
.animation-slide-bottom {
animation-name: slide-bottom
}
.animation-slide-left {
animation-name: slide-left
}
.animation-slide-right {
animation-name: slide-right
}
.animation-shake {
animation-name: shake
}
.animation-reverse {
animation-direction: reverse
}
@keyframes fade {
0% {
opacity: 0
}
100% {
opacity: 1
}
}
@keyframes scale-up {
0% {
opacity: 0;
transform: scale(.2)
}
100% {
opacity: 1;
transform: scale(1)
}
}
@keyframes scale-down {
0% {
opacity: 0;
transform: scale(1.8)
}
100% {
opacity: 1;
transform: scale(1)
}
}
@keyframes slide-top {
0% {
opacity: 0;
transform: translateY(-100%)
}
100% {
opacity: 1;
transform: translateY(0)
}
}
@keyframes slide-bottom {
0% {
opacity: 0;
transform: translateY(100%)
}
100% {
opacity: 1;
transform: translateY(0)
}
}
@keyframes shake {
0%,
100% {
transform: translateX(0)
}
10% {
transform: translateX(-9px)
}
20% {
transform: translateX(8px)
}
30% {
transform: translateX(-7px)
}
40% {
transform: translateX(6px)
}
50% {
transform: translateX(-5px)
}
60% {
transform: translateX(4px)
}
70% {
transform: translateX(-3px)
}
80% {
transform: translateX(2px)
}
90% {
transform: translateX(-1px)
}
}
@keyframes slide-left {
0% {
opacity: 0;
transform: translateX(-100%)
}
100% {
opacity: 1;
transform: translateX(0)
}
}
@keyframes slide-right {
0% {
opacity: 0;
transform: translateX(100%)
}
100% {
opacity: 1;
transform: translateX(0)
}
}

@ -0,0 +1,54 @@
const app = getApp();
Component({
/**
* 组件的一些选项
*/
options: {
addGlobalClass: true,
multipleSlots: true
},
/**
* 组件的对外属性
*/
properties: {
bgColor: {
type: String,
default: ''
},
isCustom: {
type: [Boolean, String],
default: false
},
isBack: {
type: [Boolean, String],
default: false
},
bgImage: {
type: String,
default: ''
},
},
/**
* 组件的初始数据
*/
data: {
StatusBar: app.globalData.StatusBar,
CustomBar: app.globalData.CustomBar,
Custom: app.globalData.Custom
},
/**
* 组件的方法列表
*/
methods: {
BackPage() {
wx.navigateBack({
delta: 1
});
},
toHome(){
wx.reLaunch({
url: '/pages/index/index',
})
}
}
})

@ -0,0 +1,4 @@
{
"component": true,
"usingComponents": {}
}

@ -0,0 +1,16 @@
<view class="cu-custom" style="height:{{CustomBar}}px">
<view class="cu-bar fixed {{bgImage!=''?'none-bg text-white bg-img':''}} {{bgColor}}" style="height:{{CustomBar}}px;padding-top:{{StatusBar}}px;{{bgImage?'background-image:url(' + bgImage+')':''}}">
<view class="action" bindtap="BackPage" wx:if="{{isBack}}">
<text class="cuIcon-back"></text>
<slot name="backText"></slot>
</view>
<view class="action border-custom" wx:if="{{isCustom}}" style="width:{{Custom.width}}px;height:{{Custom.height}}px;margin-left:calc(750rpx - {{Custom.right}}px)">
<text class="cuIcon-back" bindtap="BackPage"></text>
<text class="cuIcon-homefill" bindtap="toHome"></text>
</view>
<view class="content" style="top:{{StatusBar}}px">
<slot name="content"></slot>
</view>
<slot name="right"></slot>
</view>
</view>

@ -0,0 +1 @@
/* colorui/components/cu-custom.wxss */

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB

19
package-lock.json generated

@ -0,0 +1,19 @@
{
"requires": true,
"lockfileVersion": 1,
"dependencies": {
"@types/wechat-miniprogram": {
"version": "3.2.0",
"resolved": "https://registry.npm.taobao.org/@types/wechat-miniprogram/download/@types/wechat-miniprogram-3.2.0.tgz",
"integrity": "sha1-a0A0FVhW0xzZ80Lv0hfbwn6oD7k="
},
"@vant/weapp": {
"version": "1.5.3",
"resolved": "https://registry.npm.taobao.org/@vant/weapp/download/@vant/weapp-1.5.3.tgz",
"integrity": "sha1-X6PCNzL/3rhck5tPRc/Fiy64BfQ=",
"requires": {
"@types/wechat-miniprogram": "^3.0.0"
}
}
}
}

@ -0,0 +1,22 @@
Component({
options: {
addGlobalClass: true,
},
/**
* 页面的初始数据
*/
data: {
elements: [{
title: '病历申请',
name: 'record',
color: 'cyan',
icon: 'newsfill'
},{
title: '申请记录',
name: 'order',
color: 'blue',
icon: 'order'
}]
},
})

@ -0,0 +1,3 @@
{
"component": true
}

@ -0,0 +1,15 @@
<scroll-view scroll-y class="scrollPage" >
<view class="container">
<view class='nav-list'>
<navigator open-type="navigate" hover-class='none' url="/pages/{{item.name}}/{{item.name}}" class="nav-li bg-{{item.color}}" wx:for="{{elements}}" wx:key>
<view class="nav-title">{{item.title}}</view>
<view class="nav-name">{{item.name}}</view>
<text class='cuIcon-{{item.icon}}'></text>
</navigator>
</view>
</view>
<button class="action bg-red round shadow" open-type="contact">
<view class="cuIcon-service"></view>
客服
</button>
</scroll-view>

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

@ -0,0 +1,26 @@
// index.js
// 获取应用实例
const app = getApp()
Page({
data: {
status: 3,
flag:1,
interval: null
},
onLoad() {
let that=this
that.setData({
interval:setInterval(() => {
app.utils.util.getSessionId(that.bindData)
}, 1000)});
},
bindData(){
this.setData({
status: app.globalData.status,
flag: app.globalData.flag
})
if(this.data.interval){
clearInterval(this.data.interval)
}
}
})

@ -0,0 +1,7 @@
{
"usingComponents": {
"home":"../home/home",
"verify":"../verify/verify",
"verify-loading": "../verify-loading/verify-loading"
}
}

@ -0,0 +1,9 @@
<home wx:if="{{status===0&&flag===1}}"></home>
<verify wx:if="{{status===2}}" bind:reflush="bindData"></verify>
<verify-loading wx:if="{{(status===0&&flag===0)||status===1}}" bind:reflush="bindData"></verify-loading>
<view wx:if="{{status===3}}">
<view class="bg-white">
<image src="/images/loading-1.gif" mode="aspectFit" class="gif-white response" style="height: 98vh"></image>
</view>
</view>

@ -0,0 +1 @@
/**index.wxss**/

@ -0,0 +1,117 @@
// pages/order/order.js
const app=getApp();
Page({
/**
* 页面的初始数据
*/
data: {
TabCur: 0,
scrollLeft:0,
tabItem: ['全部','申请中','已完成'],
page: 1,
listData: [],
hasNext: true,
keyword: '',
textContent: ''
},
tabSelect(e) {
this.setData({
TabCur: e.currentTarget.dataset.id,
scrollLeft: (e.currentTarget.dataset.id-1)*60,
page: 1,
listData: [],
hasNext: true
})
this.loadData()
},
getKeyword(e){
this.setData({
keyword: e.detail.value
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.loadData()
},
searchData(){
this.setData({
page: 1,
listData: [],
hasNext: true
})
this.loadData()
},
loadNextData(){
let that=this;
if(!that.data.hasNext)
return
let nextPage=that.data.page+1;
that.setData({
page: nextPage
})
that.loadData()
},
loadData(){
let that=this;
let status = null;
if(that.data.TabCur===1){
status=0
}else if(that.data.TabCur===2){
status=1
}
app.utils.util.request({
url:'/orderList',
data:{
keyword: that.data.keyword,
status: status,
page: that.data.page
},
success: function(res){
if(res.data.length){
res.data.forEach(e => {
that.data.listData.push(e)
});
that.setData({
listData: that.data.listData
})
}else{
wx.showModal({
title: '提示',
content: '暂无更多数据',
showCancel: false
})
that.setData({
hasNext: false
})
}
}
})
},
hideModal(e) {
this.setData({
modalName: null
})
},
showDownUrl(e){
console.log(e.currentTarget.dataset.downurl)
this.setData({
textContent: e.currentTarget.dataset.downurl,
modalName: e.currentTarget.dataset.target
})
},
copyText(){
let that=this;
wx.setClipboardData({
//准备复制的数据内容
data: that.data.textContent,
success: function (res) {
wx.showToast({
title: '复制成功',
});
}
});
}
})

@ -0,0 +1,4 @@
{
"usingComponents": {},
"navigationBarTitleText":"病案申请-记录"
}

@ -0,0 +1,53 @@
<view class="cu-bar search bg-white">
<view class="search-form round">
<text class="cuIcon-search"></text>
<input type="text" placeholder="输入病案号或姓名" bindinput="getKeyword"></input>
</view>
<view class="action">
<button class="cu-btn bg-green shadow-blur round" style="width:20vw" bindtap="loadData">搜索</button>
</view>
</view>
<scroll-view scroll-x class="bg-white nav">
<view class="flex text-center">
<view class="cu-item flex-sub {{index==TabCur?'text-orange cur':''}}" wx:for="{{tabItem}}" wx:key="index" bindtap="tabSelect" data-id="{{index}}">
{{tabItem[index]}}
</view>
</view>
</scroll-view>
<scroll-view scroll-y style="height:calc(100vh - 194rpx)" bindscrolltolower="loadNextData">
<view class="cu-list menu-avatar">
<view class="cu-item" wx:for="{{listData}}" wx:key="id" style="height:172rpx">
<text class="cu-avatar lg cuIcon-form" style="height:130rpx"></text>
<view class="content">
<view class="text-grey text-lg">{{item.mrNumber}}</view>
<view class="text-gray">患者:{{item.patientName}},就诊次数:{{item.times}}</view>
<view class="text-gray text-sm">出院日期:{{item.dischargeDate}}</view>
</view>
<view class="action" style="width:200rpx">
<view class="text-grey text-xs">{{item.type}}</view>
<view class="cu-tag round bg-grey" wx:if="{{item.type==='原件寄回'||item.status!=='已完成'}}">{{item.status}}</view>
<view class="cu-tag round bg-grey" wx:if="{{item.type==='电子扫描件'&&item.status==='已完成'}}" bindtap="showDownUrl" data-target="Modal" data-downurl="{{item.downUrl}}">下载地址</view>
</view>
</view>
</view>
</scroll-view>
<view class="cu-modal {{modalName=='Modal'?'show':''}}">
<view class="cu-dialog">
<view class="cu-bar bg-white justify-end">
<view class="content">下载地址</view>
<view class="action" bindtap="hideModal">
<text class="cuIcon-close text-red"></text>
</view>
</view>
<view class="padding-xl">
<text>{{textContent}}</text>
</view>
<view class="cu-bar bg-white justify-end">
<view class="action">
<button class="cu-btn line-green text-green" bindtap="hideModal" size="mini">取消</button>
<button class="cu-btn bg-green margin-left" bindtap="copyText" size="mini">复制</button>
</view>
</view>
</view>
</view>

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

@ -0,0 +1,67 @@
const app=getApp();
Page({
/**
* 页面的初始数据
*/
data: {
index: '1',
picker: ['病案原件寄回', '电子版扫描件'],
date: '2018-12-25',
address: ''
},
onLoad:function(){
this.setData({
address: app.globalData.address
})
},
PickerChange(e) {
console.log(this.data.index);
this.setData({
index: e.detail.value
})
},
submitForm(e){
// 验证参数
let formData=e.detail.value;
if(!formData.mrNumber){
wx.showToast({
title: '病案号必填',
icon: 'error',
})
return;
}
if(!formData.patientName){
wx.showToast({
title: '患者姓名必填',
icon: 'error',
})
return;
}
if(!formData.times){
wx.showToast({
title: '就诊次数必填',
icon: 'error',
})
return;
}
if(formData.type==='0'&&!formData.address){
wx.showToast({
title: '寄送地址必填',
icon: 'error',
})
return;
}
// 请求接口
app.utils.util.request({
url: '/order',
data: formData,
success: function(res){
// 跳转页面
wx.reLaunch({
url:"../order/order"
})
}
})
},
})

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

@ -0,0 +1,36 @@
<form bindsubmit="submitForm">
<view class="cu-form-group margin-top">
<view class="title">申请类型</view>
<picker bindchange="PickerChange" value="{{index}}" range="{{picker}}" name="type">
<view class="picker">
{{index?picker[index]:'请选择'}}
</view>
</picker>
</view>
<view class="cu-form-group margin-top">
<view class="title">病案号</view>
<input placeholder="请输入病案号" name="mrNumber"></input>
</view>
<view class="cu-form-group">
<view class="title">患者姓名</view>
<input placeholder="请输入患者姓名" name="patientName"></input>
</view>
<view class="cu-form-group">
<view class="title">就诊次数</view>
<input type="number" placeholder="请输入患者就诊次数" name="times"></input>
</view>
<view class="cu-form-group">
<view class="title">出院日期</view>
<picker mode="date" value="{{date}}" bindchange="DateChange" name="dischargeDate">
<view class="picker">
{{date}}
</view>
</picker>
</view>
<view class="cu-form-group" wx:if="{{index==0}}">
<view class="title">收货地址</view>
<input placeholder="请输入收货地址" name="address" value="{{address}}"></input>
</view>
<button class="cu-btn round shadow-blur button-hover block bg-blue margin-tb-lg lg" form-type="submit">提交</button>
</form>

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

@ -0,0 +1,37 @@
// pages/verify-loading/verify-loading.js
const app = getApp();
Component({
options: {
addGlobalClass: true,
},
/**
* 页面的初始数据
*/
data: {
canLogin: true,
inteval: null
},
lifetimes:{
attached: function(){
this.setData({
canLogin: app.globalData.status !== 1
})
let that=this;
this.data.inteval=setInterval(() => {
app.utils.util.request({
url: '/info',
success: function(res){
if(res.data.flag===1&&res.data.status===0){
app.globalData.status = res.data.status
app.globalData.flag = res.data.flag
that.triggerEvent('reflush')
}
}
})
}, 5000);
},
detached: function(){
clearInterval(this.data.inteval);
}
}
})

@ -0,0 +1,3 @@
{
"component": true
}

@ -0,0 +1,21 @@
<view class="flex cu-card case justify-center align-center" style="height:100vh">
<view class="cu-item shadow">
<view class="solids-bottom padding-xs flex align-center" wx:if="{{canLogin}}">
<view class="padding">
<text class="cuIcon-loading2 iconfont-spin"></text>
</view>
<view class="flex-sub">
<view class="padding">客服审核中。。。。。。</view>
</view>
</view>
<view class="solids-bottom padding-xs flex align-center" wx:if="{{!canLogin}}">
<view class="padding">
<text class="cuIcon-warnfill text-red text-lg"></text>
</view>
<view class="flex-sub">
<view class="padding">您的账号已被停用</view>
</view>
</view>
</view>
</view>

@ -0,0 +1 @@
/* pages/verify-loading/verify-loading.wxss */

@ -0,0 +1,102 @@
// pages/verify/verify.js
const app = getApp()
Component({
options: {
addGlobalClass: true,
},
/**
* 页面的初始数据
*/
data: {
userInfo: {},
hasUserInfo: false,
canIUse: wx.canIUse('button.open-type.getUserInfo'),
hospital: '',
name: '',
phone: ''
},
lifetimes:{
attached: function(){
if (app.globalData.userInfo) {
this.setData({
userInfo: app.globalData.userInfo,
hasUserInfo: true
})
}else if (this.data.canIUse) {
// 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
// 所以此处加入 callback 以防止这种情况
app.userInfoReadyCallback = res => {
this.setData({
userInfo: res.userInfo,
hasUserInfo: true
})
}
} else {
// 在没有 open-type=getUserInfo 版本的兼容处理
wx.getUserInfo({
success: res => {
app.globalData.userInfo = res.userInfo
this.setData({
userInfo: res.userInfo,
hasUserInfo: true
})
}
})
}
}
},
methods: {
signIn(e){
let formData=e.detail.value;
let userInfo=this.data.userInfo;
let that=this;
// 验证数据
if(!formData.hospital){
wx.showToast({
title: '医院名称必填',
icon: 'error',
})
return;
}
if(!formData.name){
wx.showToast({
title: '姓名必填',
icon: 'error',
})
return;
}
if(!formData.phone){
wx.showToast({
title: '手机号必填',
icon: 'error',
})
return;
}
app.utils.util.request({
url: '/signIn',
data: {
nickName: userInfo.nickName,
avatar: userInfo.avatarUrl,
gender: userInfo.gender,
phone: formData.phone,
hospital: formData.hospital,
name: formData.name
},
success: function(res) {
app.globalData.status = 0
that.triggerEvent("reflush")
}
})
},
getUserInfo(e) {
if (e.detail.userInfo) {
//用户按了允许授权按钮
app.globalData.userInfo = e.detail.userInfo
this.setData({
userInfo: e.detail.userInfo,
hasUserInfo: true
})
}
}
}
})

@ -0,0 +1,3 @@
{
"component": true
}

@ -0,0 +1,18 @@
<view class="flex cu-card case justify-center align-center" style="height:100vh" wx:if="{{!hasUserInfo && canIUse}}">
<button class="cu-btn text-green line-green block lg" open-type="getUserInfo" bindgetuserinfo="getUserInfo">点击授权</button>
</view>
<form wx:if="{{hasUserInfo}}" bindsubmit="signIn">
<view class="cu-form-group margin-top">
<view class="title">医院</view>
<input placeholder="请输入医院名称" focus="true" value="{{hospital}}" name="hospital"></input>
</view>
<view class="cu-form-group">
<view class="title">姓名</view>
<input placeholder="请输入您的姓名" value="{{name}}" name="name"></input>
</view>
<view class="cu-form-group">
<view class="title">手机</view>
<input type="number" placeholder="请输入您的手机号" value="{{phone}}" name="phone"></input>
</view>
<button class="cu-btn round shadow-blur button-hover block bg-blue margin-tb-lg lg" form-type="submit">提交</button>
</form>

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

@ -0,0 +1,75 @@
{
"description": "项目配置文件",
"packOptions": {
"ignore": []
},
"setting": {
"urlCheck": false,
"es6": true,
"enhance": false,
"postcss": true,
"preloadBackgroundData": false,
"minified": true,
"newFeature": false,
"coverView": true,
"nodeModules": false,
"autoAudits": false,
"showShadowRootInWxmlPanel": true,
"scopeDataCheck": false,
"uglifyFileName": false,
"checkInvalidKey": true,
"checkSiteMap": true,
"uploadWithSourceMap": true,
"compileHotReLoad": false,
"useMultiFrameRuntime": true,
"useApiHook": true,
"useApiHostProcess": true,
"babelSetting": {
"ignore": [],
"disablePlugins": [],
"outputPath": ""
},
"enableEngineNative": false,
"bundle": false,
"useIsolateContext": true,
"useCompilerModule": true,
"userConfirmedUseCompilerModuleSwitch": false,
"userConfirmedBundleSwitch": false,
"packNpmManually": false,
"packNpmRelationList": [],
"minifyWXSS": true
},
"compileType": "miniprogram",
"libVersion": "2.15.0",
"appid": "wxa35fbc494f55cdd1",
"projectname": "applyCase",
"debugOptions": {
"hidedInDevtools": []
},
"scripts": {},
"staticServerOptions": {
"baseURL": "",
"servePath": ""
},
"isGameTourist": false,
"condition": {
"search": {
"list": []
},
"conversation": {
"list": []
},
"game": {
"list": []
},
"plugin": {
"list": []
},
"gamePlugin": {
"list": []
},
"miniprogram": {
"list": []
}
}
}

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

@ -0,0 +1,97 @@
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}`
}
var util = {};
function getSessionId(suc,fail) {
wx.login({
success: r => {
// console.log(r);
// 发送 r.code 到后台换取 openId, sessionKey, unionId
wx.request({
url: getApp().globalData.url + '/autoLogin',
data: {
wxCode: r.code
},
header: {
"Content-Type": "application/x-www-form-urlencoded",
},
method: 'POST',
success: result => {
let resultData = result.data;
if (resultData.code===0) {
let data = resultData.data;
getApp().globalData.token = data.token;
getApp().globalData.status = data.status;
getApp().globalData.flag = data.flag;
getApp().globalData.address = data.address
}
if(suc && typeof suc === 'function'){
suc()
}
}
});
}
})
}
function myRequest(res) {
let host = getApp().globalData.url;
let token = getApp().globalData.token;
wx.request({
url: host + res.url,
data: res.data ? res.data : {},
header: {
"Content-Type": "application/json",
"token": token
},
method: res.method ? res.method : 'POST',
dataType: 'json',
success: function(data) {
if (data.data.code === 403) {
getSessionId();
return
}
if (data.data.code === 500) {
wx.showToast({
title: data.data.msg,
icon: 'error',
mask: true
})
return
}
if (typeof res.success == "function") {
res.success(data.data);
}
},
fail: function(data) {
if (typeof res.doFail == "function") {
res.doFail();
}
},
complete: function() {
if (typeof res.doComplete == "function") {
res.doComplete();
}
}
});
}
util.request = myRequest, util.getSessionId = getSessionId
module.exports = {
formatTime,
util
}
Loading…
Cancel
Save