第一版原生小程序dome

This commit is contained in:
yahui.xue 2021-06-30 09:56:35 +08:00
parent a3a01d79f7
commit db3c4eba04
58 changed files with 1768 additions and 0 deletions

133
app.js Normal file
View File

@ -0,0 +1,133 @@
const util=require('./utils/js/util')
import { postRequest, getRequest } from "./utils/js/request"
import { platformInfo, queryInfo, signIn } from "./utils/js/locales"
App({
onLaunch(query) {
// 展示本地存储能力
const logs = wx.getStorageSync('logs') || []
logs.unshift(Date.now())
wx.setStorageSync('logs', logs)
let scene = '';
if (query.query.q) {
let url = decodeURIComponent(query.query.q)
scene = util.getQueryString(url,'bind')
wx.setStorageSync('bind', scene)
}
// 获取用户信息
// wx.getSetting({
// success: res => {
// if (res.authSetting['scope.userInfo']) {
// // 已经授权,可以直接调用 getUserProfile 获取头像昵称,不会弹框
// wx.getUserProfile({
// desc: '用于展示头像',
// success: (res) => {
// // 可以将 res 发送给后台解码出 unionId
// this.globalData.userInfo = res.userInfo
// }
// })
// }
// }
// })
},
onShow() {
this.upDataApp();
},
// 存储公共信息
globalData: {
uploadUrl: "https://office-ssl.iilink.cn/coconut", // 开发环境
// uploadUrl: "https://office-ssl.iilink.cn/coconut-uat", // 测试环境
// uploadUrl: 'https://cherry.amtcloud.cn/cherry-api', // 生产
systemConfiguration: {
backgroundColor: '#01ae42'
},
id: '', // 商铺id shop_id
actor: '', // 用户身份 代采buyer 销售seller 游客visitor
platformInfo: {}, // 平台信息
buyerItem: { // 买家信息
gmtOrder: '',
memberId: '',
name: ''
},
info: {}, // login获取的数据
userInfo: {}, // 授权的昵称和logo
user_info: {}, // 信息里的昵称和logo
member_info: {}, // 认证信息
operator_info: {}, //
behaviorRecord: 0, // 认证 操作记录
authentication: { // 认证信息缓存
personal: {
name: '',
card_number: '',
id_main: '',
id_extra: '',
id_card: [],
},
enterprise: {
corporation_name: '',
unified_tax_code: '',
business_licence: '',
enterprise: [],
}
}
},
// 小程序登录
loginCloudBird: function (scene) {
let app = this
// wx.login({
// success: res => {
// let data = {
// code: res.code,
// }
// postRequest('/v1/p/login', data).then(res => {
// wx.setStorageSync('tokenKey', res.data.token);
//用户类型 代采buyer 销售seller 游客visitor
// wx.setStorageSync('actor', res.data.info.actor); // res.data.actor buyer seller
// app.globalData.actor = res.data.info.actor;
// app.globalData.info = res.data.info;
// platformInfo(app);
wx.reLaunch({
url: '/pages/home/home',
})
// }).catch(err => {
// signIn(err);
// })
// }
// })
},
//版本更新
upDataApp: function () {
if (wx.canIUse('getUpdateManager')) { //判断当前微信版本是否支持版本更新
const updateManager = wx.getUpdateManager();
updateManager.onCheckForUpdate(function (res) {
if (res.hasUpdate) { // 请求完新版本信息的回调
updateManager.onUpdateReady(function () {
wx.showModal({
title: '更新提示',
content: '新版本已经准备好,是否重启应用?',
success: function (res) {
// res: {errMsg: "showModal: ok", cancel: false, confirm: true}
if (res.confirm) {
// 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
updateManager.applyUpdate()
}
}
})
});
updateManager.onUpdateFailed(function () {
// 新的版本下载失败
wx.showModal({
title: '已经有新版本了哟~',
content: '新版本已经上线啦~,请您删除当前小程序,重新搜索打开哟~',
})
})
}
})
} else {
wx.showModal({ // 如果希望用户在最新版本的客户端上体验您的小程序,可以这样子提示
title: '提示',
content: '当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。'
})
}
}
})

48
app.json Normal file
View File

@ -0,0 +1,48 @@
{
"pages":[
"pages/firstpage/firstpage",
"pages/home/home",
"pages/order/order",
"pages/index/index",
"pages/authorizationPage/index",
"pages/openAuthentication/index"
],
"window":{
"backgroundTextStyle":"light",
"navigationBarTextStyle": "white",
"navigationBarBackgroundColor": "#01ae42"
},
"tabBar": {
"selectedColor":"#01ae42",
"list": [
{
"pagePath":"pages/home/home",
"text": "供应商",
"iconPath":"./utils/images/shouye1.png",
"selectedIconPath":"./utils/replace-images/shouye.png"
}, {
"pagePath": "pages/order/order",
"text": "订单",
"iconPath":"./utils/images/dingdan1.png",
"selectedIconPath":"./utils/replace-images/dingdan.png"
}, {
"pagePath": "pages/index/index",
"text": "个人中心",
"iconPath":"./utils/images/gerenzhongxin1.png",
"selectedIconPath":"./utils/replace-images/gerenzhongxin.png"
}
]
},
"style": "v2",
"sitemapLocation": "sitemap.json",
"useExtendedLib": {
"kbone": true,
"weui": true
},
"usingComponents": {
"mp-navigation-bar": "weui-miniprogram/navigation-bar/navigation-bar",
"i-load-more": "components/load-more/index",
"i-no-data": "components/no-data-available/index"
}
}

44
app.wxss Normal file
View File

@ -0,0 +1,44 @@
/**app.wxss**/
.container {
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-between;
padding: 200rpx 0;
box-sizing: border-box;
}
button {
color: #ffffff !important;
background-color: #01ae42!important;
}
.i-background-color{
background-color: #01ae42 !important;
}
.i-color{
color: #01ae42 !important;
}
.i-border-color{
border: 2rpx solid #01ae42 !important;
}
.i-border-color-left{
border-left: 15rpx solid #01ae42;
}
.i-border-bottom{
border-bottom: 8rpx solid #01ae42;
}
.i-transparent-color{
background: #01ae4220;
}
/* 小众的颜色 */
.i-yellow-background-color{
background: #ffb565 !important;
}
.i-yellow-border-color{
border: 2rpx solid #ffb565 !important;
}
.i-yellow-color{
color: #ffb565 !important;
}

View File

@ -0,0 +1,14 @@
Component({
externalClasses: ['i-class'],
properties: {
loading: {
type: Boolean,
value: true
},
tip: {
type: String,
value: ''
}
},
});

View File

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

View File

@ -0,0 +1,8 @@
<view class="i-class i-load-more {{ loading ? '' : 'i-load-more-line' }}">
<view class="i-load-more-loading" wx:if="{{ loading }}"></view>
<view class="i-load-more-tip">
<view wx:if="{{ tip !== '' }}">{{ tip }}</view>
<view wx:elif="{{ tip === '' && loading }}">正在加载</view>
<view class="i-load-more-empty" wx:else></view>
</view>
</view>

View File

@ -0,0 +1,79 @@
.i-load-more {
width: 65%;
margin: 1.5em auto;
line-height: 1.6em;
font-size: 14px;
text-align: center
}
.i-load-more-loading {
display: inline-block;
margin-right: 12px;
vertical-align: middle;
width: 14px;
height: 14px;
background: 0 0;
border-radius: 50%;
border: 2px solid #e9eaec;
border-color: #e9eaec #e9eaec #e9eaec #2d8cf0;
animation: btn-spin .6s linear;
animation-iteration-count: infinite
}
.i-load-more-tip {
display: inline-block;
vertical-align: middle;
color: #495060
}
.i-load-more-line {
border-top: 1px solid #dddee1;
display: flex;
border-top: 0
}
.i-load-more-line::before {
position: relative;
top: -1px;
-webkit-box-flex: 1;
-webkit-flex: 1;
flex: 1;
content: '';
border-top: 1px solid #dddee1
}
.i-load-more-line::after {
position: relative;
top: -1px;
-webkit-box-flex: 1;
-webkit-flex: 1;
flex: 1;
content: '';
border-top: 1px solid #dddee1
}
.i-load-more-line .i-load-more-tip {
position: relative;
padding: 0 .55em
}
.i-load-more-empty {
width: 4px;
height: 4px;
border-radius: 50%;
background-color: #e5e5e5;
display: inline-block;
position: relative;
vertical-align: 0;
top: -.16em
}
@keyframes btn-spin {
0% {
transform: rotate(0)
}
100% {
transform: rotate(360deg)
}
}

View File

@ -0,0 +1,38 @@
Component({
externalClasses: ['i-class'],
data: {
loading: false
},
// properties: {
// tip: {
// type: String,
// value: ''
// }
// },
// 在组件实例刚刚被创建时执行
created: function() {
let that = this;
setTimeout(function() {
that.setData({ loading: true })
}, 2000)
},
// 在组件在视图层布局完成后执行
// ready: function() {
// },
pageLifetimes: {
// 页面被展示
show: function() {
let that = this;
setTimeout(function() {
that.setData({ loading: true })
}, 1000)
},
// 页面被隐藏
hide: function() {
this.setData({ loading: false })
},
// 页面尺寸变化
resize: function(size) {
}
}
});

View File

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

View File

@ -0,0 +1,5 @@
<view wx:if="{{loading === true}}" class="no_data_available">
<image class="_image" src="../../utils/images/no_data_available.png" alt="暂无数据"></image>
<view class="no_data">暂无数据</view>
</view>
<view wx:else class="no_data_available da"></view>

View File

@ -0,0 +1,12 @@
.no_data_available {
height: 350rpx;
text-align: center;
padding-top: 100rpx;
}
.no_data_available ._image{
width: 300rpx;
height: 200rpx;
}
.no_data{
color: #999999;
}

13
package-lock.json generated Normal file
View File

@ -0,0 +1,13 @@
{
"name": "cherry_mini",
"version": "1.0.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"umtrack-wx": {
"version": "2.6.2",
"resolved": "https://registry.npmjs.org/umtrack-wx/-/umtrack-wx-2.6.2.tgz",
"integrity": "sha512-EdxHh5pW7TYhE8A7AUzqLBXV+P6Sk3y86iBnAbq/7IFd3Bwl0LoQZ+lA6aMAnd1Ylxe+68uO7xekKMS2NLB5xQ=="
}
}
}

18
package.json Normal file
View File

@ -0,0 +1,18 @@
{
"name": "cherry_mini",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "https://gitea.amtcloud.cn/tokamak/cherry_mini.git"
},
"author": "",
"license": "ISC",
"dependencies": {
"umtrack-wx": "^2.6.2"
}
}

View File

@ -0,0 +1,99 @@
import { postRequest, getRequest, putRequest } from '../../utils/js/request'
import { queryLogin, queryInfo, signIn } from '../../utils/js/locales'
let app = getApp();
Page({
data: {
userInfo: {},
logo: '',
hasUserInfo: false,
canIUseGetUserProfile: false,
},
onLoad: function (options) {
this.setData({
userInfo: {},
logo: app.globalData.info.logo,
hasUserInfo: false,
canIUseGetUserProfile: false
})
},
onShow: function () {
if (wx.getUserProfile) {
this.setData({
canIUseGetUserProfile: true
})
}
},
getUserProfile(e) {
// 推荐使用wx.getUserProfile获取用户信息开发者每次通过该接口获取用户个人信息均需用户确认
// 开发者妥善保管用户快速填写的头像昵称,避免重复弹窗
let that = this;
wx.getUserProfile({
desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
success: (res) => {
putRequest('/v1/p/info', { nick: res.userInfo.nickName, logo: res.userInfo.avatarUrl }).then(res => {
}).catch(err => {
signIn(err)
})
app.globalData.userInfo = res.userInfo
wx.setStorageSync('nickName', res.userInfo.nickName);
wx.setStorageSync('avatarUrl', res.userInfo.avatarUrl);
this.setData({
hasUserInfo: true,
logo: res.userInfo.avatarUrl,
userInfo: res.userInfo
})
}
})
},
getUserInfo(e) {
// 不推荐使用getUserInfo获取用户信息预计自2021年4月13日起getUserInfo将不再弹出弹窗并直接返回匿名的用户个人信息
app.globalData.userInfo = e.detail.userInfo
this.setData({
hasUserInfo: true,
userInfo: e.detail.userInfo
})
},
// 点击用户登录
decryptPhoneNumber(e) {
let that = this;
wx.checkSession({
success (item) {
if (e.detail.encryptedData) {
let data = {
encrypt: e.detail.encryptedData,
errMsg: e.detail.errMsg,
iv: e.detail.iv,
name: that.data.userInfo.nickName ? that.data.userInfo.nickName : ('肉仔仔' + e.detail.iv.substring(6,13))
}
wx.showLoading({ title: '授权中' })
postRequest('/v1/m/cert/phone/encrypt',data).then(res => {
setTimeout(function () {
queryLogin(app)
}, 3000);
setTimeout(function () {
queryInfo(app)
wx.showToast({ icon: 'none', title: '授权成功!', duration: 2000 })
}, 4000);
setTimeout(function () {
wx.hideLoading();
wx.reLaunch({
url: '/pages/index/index'
})
}, 5000);
}).catch(err => {
wx.hideLoading();
signIn(err)
})
}
},
fail () {
// session_key 已经失效,需要重新执行登录流程
wx.login({ })
}
})
},
// /** 用户点击右上角分享 */
// onShareAppMessage: function () {
// return { path: "pages/firstpage/firstpage?from=share" }
// }
})

View File

@ -0,0 +1,4 @@
{
"backgroundTextStyle":"dark",
"navigationBarTitleText": "登录"
}

View File

@ -0,0 +1,16 @@
<view>
<view wx:if="{{!logo}}" class="logo">
<image class="_image" src="../../utils/replace-images/logo.png"></image>
</view>
<view wx:else class="logo_mobile_image">
<image class="mobile_image" src="../../utils/images/moblie_image.png"></image>
<view class="_title">手机号验证</view>
</view>
<view wx:if="{{!logo}}" class="to-grant">
<button size="default" wx:if="{{canIUseGetUserProfile}}" bindtap="getUserProfile" class="to-grant-authorization">获取微信授权</button>
<button size="default" wx:else open-type="getUserInfo" bindgetuserinfo="getUserInfo" class="to-grant-authorization">获取微信授权</button>
</view>
<view wx:else>
<button class="to-grant-authorization" open-type="getPhoneNumber" bindgetphonenumber="decryptPhoneNumber">微信授权手机号登录</button>
</view>
</view>

View File

@ -0,0 +1,31 @@
.logo{
text-align: center;
}
.logo ._image{
width: 640rpx;
height: 480rpx;
}
._title{
width: 74%;
margin: auto;
color: #999999;
font-size: 28rpx;
margin-top: 40rpx;
}
.logo_mobile_image{
text-align: center;
padding-top: 220rpx;
text-align: center;
}
.logo_mobile_image .mobile_image{
width: 280rpx;
height: 280rpx;
}
.to-grant{
width: 100%;
}
.to-grant-authorization{
width: 80% !important;
margin: auto;
margin-top: 40rpx;
}

View File

@ -0,0 +1,71 @@
let app = getApp()
import { pageTitle } from '../../utils/js/replace'
Page({
/** 页面的初始数据 */
data: {
canLogin: true,
},
/** 生命周期函数--监听页面加载 */
onLoad: function (options) {
wx.setNavigationBarTitle({
title: `${pageTitle}`
})
wx.showLoading({ title: '加载中' })
},
/** 生命周期函数--监听页面显示 */
onShow: function () {
let startDate = new Date("2020/05/29 22:00:00");
let endDate = new Date("2020/05/30 22:00:00");
let d = new Date()
if(d >= startDate && d <= endDate){
this.setData({
canLogin : false
})
wx.showModal({
showCancel: false,
mask: true,
content:"给您带来不便敬请谅解 \r\n 预计恢复时间2020.05.30 22:00:00",
title:"系统更新维护中"
})
}
// 获取缓存里的扫码内容 登录
let bind = wx.getStorageSync('bind')
setTimeout(function () {
app.loginCloudBird(bind);
}, 1000)
},
/** 用户点击右上角分享 */
onShareAppMessage: function () {
return { path: "pages/firstpage/firstpage?from=share" }
},
gologin () {
if(!this.data.canLogin){
wx.showModal({
showCancel: false,
mask: true,
content:"给您带来不便敬请谅解 \r\n 预计恢复时间2020.05.30 22:00:00",
title:"系统更新维护中"
})
return;
}
wx.showModal({
title: '您还未登录',
content: '请先登录再进行操作!',
showCancel: true,//是否显示取消按钮
success: function (res) {
if (res.cancel) {
//点击取消
} else if (res.confirm) {
//点击确定
wx.navigateTo({
url: '../wxlogin/wxlogin'
})
}
}
})
}
})

View File

@ -0,0 +1 @@
{}

View File

@ -0,0 +1,3 @@
<view>
<view class="top-view" bindtap="gologin"></view>
</view>

View File

@ -0,0 +1,4 @@
page{
background-color: #F9F9FB;
font-family: PingFangSC-Regular;
}

19
pages/home/home.js Normal file
View File

@ -0,0 +1,19 @@
let app = getApp()
Page({
data: {
canLogin: true,
},
/** 生命周期函数--监听页面加载 */
onLoad: function (options) {
// wx.showLoading({ title: '加载中' })
},
/** 生命周期函数--监听页面显示 */
onShow: function () {
},
/** 用户点击右上角分享 */
onShareAppMessage: function () {
return { path: "pages/firstpage/firstpage?from=share" }
},
})

9
pages/home/home.json Normal file
View File

@ -0,0 +1,9 @@
{
"usingComponents": {
"mp-cells": "weui-miniprogram/cells/cells",
"mp-cell": "weui-miniprogram/cell/cell"
},
"backgroundTextStyle":"dark",
"navigationBarTitleText": "供应商",
"enablePullDownRefresh": true
}

3
pages/home/home.wxml Normal file
View File

@ -0,0 +1,3 @@
<view>
<view class="top-view" bindtap="gologin"></view>
</view>

4
pages/home/home.wxss Normal file
View File

@ -0,0 +1,4 @@
page{
background-color: #F9F9FB;
font-family: PingFangSC-Regular;
}

32
pages/index/index.js Normal file
View File

@ -0,0 +1,32 @@
let app = getApp()
Page({
data: {
canLogin: true,
},
/** 生命周期函数--监听页面加载 */
onLoad: function (options) {
wx.showLoading({ title: '加载中' })
},
/** 生命周期函数--监听页面显示 */
onShow: function () {
// 判断有没有授权
if (!app.globalData.user_info.mobile) {
wx.redirectTo({
url: '/pages/authorizationPage/index'
})
return
}
// 获取数据
this.getData();
},
// 获取数据
getData() {
},
/** 用户点击右上角分享 */
onShareAppMessage: function () {
return { path: "pages/firstpage/firstpage?from=share" }
},
})

7
pages/index/index.json Normal file
View File

@ -0,0 +1,7 @@
{
"usingComponents": {
"mp-cells": "weui-miniprogram/cells/cells",
"mp-cell": "weui-miniprogram/cell/cell"
},
"navigationBarTitleText": "个人中心"
}

3
pages/index/index.wxml Normal file
View File

@ -0,0 +1,3 @@
<view>
<view class="top-view" bindtap="gologin"></view>
</view>

4
pages/index/index.wxss Normal file
View File

@ -0,0 +1,4 @@
page{
background-color: #F9F9FB;
font-family: PingFangSC-Regular;
}

View File

@ -0,0 +1,291 @@
var app = getApp();
import { postRequest, getRequest, putRequest } from '../../utils/js/request'
import { queryLogin, queryInfo, signIn } from '../../utils/js/locales'
Page({
data: {
backgroundColor: '',
refund: '1',
selectFile: '',
uplaodFile: '',
corporation_name: '',
unified_tax_code: '',
business_licence: '',
contacts_name: '',
contacts_mobile: '',
enterprise: [],
name: '',
card_number: '',
id_main: '',
id_extra: '',
id_card: [],
isfront: '', // 上传的图片类型
openState: false, // 开户状态
},
/** 生命周期函数--监听页面加载 */
onLoad: function (options) {
this.setData({
openState: false,
selectFile: this.selectFile.bind(this),
uplaodFile: this.uplaodFile.bind(this),
uplaodFileEnterprise: this.uplaodFileEnterprise.bind(this),
backgroundColor: app.globalData.systemConfiguration.backgroundColor,
corporation_name: app.globalData.member_info.name,
name: app.globalData.operator_info.name
})
// 查询认证信息
// this.queryAuthenticationInformation()
},
onShow: function () {
const { corporation_name, name, } = this.data;
let enterprise = app.globalData.authentication.enterprise
let personal = app.globalData.authentication.personal
this.setData({
corporation_name: corporation_name ? corporation_name : enterprise.corporation_name,
unified_tax_code: enterprise.unified_tax_code,
business_licence: enterprise.business_licence,
enterprise: enterprise.enterprise,
name: name ? name : personal.name,
card_number: personal.card_number,
id_main: personal.id_main,
id_extra: personal.id_extra,
id_card: personal.id_card
})
},
// 查询认证信息 目前缺少 身份证号 企业统一税号 等
// queryAuthenticationInformation() {
// getRequest('/v1/m/my/cert',{}).then(res => {
// console.log(res)
// }).catch(err => {
// wx.hideLoading();
// signIn(err);
// })
// },
// 选择认证类型
radioChange(e) {
this.setData({ refund: e.detail.value })
},
// 选择图片时的过滤函数返回true表示图片有效 返回false可以阻止某次文件上传
selectFile(files) {
let tempFiles = files.tempFiles
if (tempFiles[0].size > (7 * 1024 * 1024)) {
wx.showToast({ title: '请选择小于7MB的图片', icon: 'none', duration: 2000 })
return false
}
},
// 上传企业执照图片,
uplaodFileEnterprise(files) {
// 文件上传的函数返回一个promise
return new Promise((resolve, reject) => {
let tempFilePaths = files.tempFilePaths;
let that = this;
wx.showLoading({ title: '正在上传...', mask: true })
wx.uploadFile({
url: 'https://tokamak.amtcloud.cn/uploader/v1/upload', //需要用HTTPS同时在微信公众平台后台添加服务器地址
filePath: tempFilePaths[0], //上传的文件本地地址
name: 'file',
success: function(res) {
let data = JSON.parse(res.data);
if (data.Code === 0) {
let _data = data.Data
that.setData({ business_licence: _data[0].Preview, enterprise: [ { url: _data[0].Preview } ] });
that.ocrLicense(_data[0].Preview);
resolve(_data)
} else {
wx.showToast({ icon: 'none', title: '上传失败', duration: 2000 })
reject(res)
}
},
fail: function(err) {
wx.hideLoading();
wx.showToast({ icon: 'none', title: '上传失败', duration: 2000 })
}
})
})
},
// 营业执照ocR
ocrLicense(preview) {
let that = this;
getRequest(`/v1/di/ocr/license?imageurl=${preview}`,{}).then(res => {
that.setData({
corporation_name: res.data.Name,
unified_tax_code: res.data.RegNum
})
wx.hideLoading();
}).catch(err => {
wx.hideLoading();
})
},
// 上传身份证照图片,
uplaodFile(files) {
// 文件上传的函数返回一个promise
return new Promise((resolve, reject) => {
let tempFilePaths = files.tempFilePaths;
let that = this;
wx.showLoading({ title: '正在上传...', mask: true })
wx.uploadFile({
url: 'https://tokamak.amtcloud.cn/uploader/v1/upload',
filePath: tempFilePaths[0], //上传的文件本地地址
name: 'file',
success: function(res) {
wx.hideLoading();
let data = JSON.parse(res.data);
if (data.Code === 0) {
let _data = data.Data
that.setData({ id_main: _data[0].Preview, id_extra: _data[0].Preview, id_card: [ { url: _data[0].Preview } ] });
resolve(_data)
} else {
wx.showToast({ icon: 'none', title: '上传失败', duration: 2000 })
reject(res)
}
},
fail: function(err) {
wx.hideLoading();
wx.showToast({ icon: 'none', title: '上传失败', duration: 2000 })
}
})
})
},
// 图片上传失败的事件
uploadError(e) {
console.log('upload error', e.detail)
},
// 图片上传成功的事件
uploadSuccess(e) {
wx.showToast({ icon: 'none', title: '上传图片失败,请删除后重新上传!', duration: 3000 })
},
// 删除图片
binddelete(e) {
if (this.data.refund === '1') {
this.setData({ business_licence: '', enterprise: [] })
} else {
this.setData({ id_main: '', id_extra: '', id_card: [] })
}
},
inputCorporationName(e) {
this.setData({ corporation_name: e.detail.value })
},
inputUnifiedTaxCode(e) {
this.setData({ unified_tax_code: e.detail.value })
},
inputContactsName(e) {
this.setData({ contacts_name: e.detail.value })
},
inputContactsMobile(e) {
this.setData({ contacts_mobile: e.detail.value })
},
inputName(e) {
this.setData({ name: e.detail.value })
},
inputCardNumber(e) {
this.setData({ card_number: e.detail.value })
},
// 提交
submit() {
const { refund, corporation_name, unified_tax_code, contacts_name, business_licence, name, card_number, id_main, id_extra } = this.data;
let that = this;
if (refund === '1') { // 认证公司企业
if (!business_licence) return wx.showToast({ icon: 'none', title: '请上传营业执照!', duration: 2000 })
if (!corporation_name) return wx.showToast({ icon: 'none', title: '请输入企业名称!', duration: 2000 })
if (!unified_tax_code) return wx.showToast({ icon: 'none', title: '请输入纳税人识别号!', duration: 2000 })
if (!contacts_name) return wx.showToast({ icon: 'none', title: '请输入联系人姓名!', duration: 2000 })
let data = {
corporation_name,
// main_business: [businessList[main_business]],
unified_tax_code,
business_licence,
contacts_name,
}
wx.showLoading({ title: '认证中' })
if (app.globalData.member_info.name && (app.globalData.member_info.name !== '')) {
putRequest('/v1/m/cert/enterprise', data).then(res => {
setTimeout(function() {
queryLogin(app);
}, 2000)
setTimeout(function() {
queryInfo(app);
wx.hideLoading();
app.globalData.authentication.enterprise = {
corporation_name: corporation_name,
unified_tax_code: unified_tax_code,
business_licence: business_licence,
enterprise: [ { url: business_licence } ]
}
that.setData({ openState: true })
}, 3000);
}).catch(err => {
signIn(err);
wx.hideLoading();
})
} else {
postRequest('/v1/m/cert/enterprise', data).then(res => {
setTimeout(function() {
queryLogin(app);
}, 2000)
setTimeout(function() {
queryInfo(app);
wx.hideLoading();
app.globalData.authentication.enterprise = {
corporation_name: corporation_name,
unified_tax_code: unified_tax_code,
business_licence: business_licence,
enterprise: [ { url: business_licence } ]
}
that.setData({ openState: true })
}, 3000);
}).catch(err => {
signIn(err);
wx.hideLoading();
})
}
} else if (refund === '2') { // 认证个人
if (!id_main) return wx.showToast({ icon: 'none', title: '请上传身份证正面!', duration: 2000 })
if (!id_extra) return wx.showToast({ icon: 'none', title: '请上传身份证反面!', duration: 2000 })
if (!name) return wx.showToast({ icon: 'none', title: '请输入姓名!', duration: 2000 })
if (!card_number) return wx.showToast({ icon: 'none', title: '请输入身份证号!', duration: 2000 })
let data = {
name: name,
card_number: card_number,
id_main: id_main,
id_extra: id_extra,
}
wx.showLoading({ title: '认证中' })
postRequest('/v1/m/cert/personal', data).then(res => {
setTimeout(function() {
queryLogin(app);
}, 2000)
setTimeout(function() {
queryInfo(app);
wx.hideLoading();
app.globalData.authentication.personal = {
name: name,
card_number: card_number,
id_main: id_main,
id_extra: id_extra,
id_card: [ { url: id_main } ]
}
that.setData({ openState: true })
}, 3000);
}).catch(err => {
signIn(err);
wx.hideLoading();
})
}
},
// 去开平安银行户
openAccount() {
let that = this;
app.globalData.behaviorRecord = 1;
setTimeout(function() {
that.setData({ openState: false })
wx.navigateBack({ delta: 1 })
}, 1000)
}
})

View File

@ -0,0 +1,8 @@
{
"usingComponents": {
"mp-cells": "weui-miniprogram/cells/cells",
"mp-cell": "weui-miniprogram/cell/cell",
"mp-uploader": "weui-miniprogram/uploader/uploader"
},
"navigationBarTitleText": "开通平安银行"
}

View File

@ -0,0 +1,82 @@
<view>
<view class="i-tabs-cell">
<view class="i-cell-left">认证类型</view>
<view class="i-cell-right">
<radio-group bindchange="radioChange">
<radio value="1" color="{{backgroundColor}}" checked="{{refund === '1'}}" class="_com">企业</radio>
<radio value="2" color="{{backgroundColor}}" checked="{{refund === '2'}}">个人</radio>
</radio-group>
</view>
</view>
<view wx:if="{{refund === '1'}}" class="">
<view class="i-tabs-cel">
<view class="i-upload-pictures">
<view wx:if="{{enterprise.length === 0}}" class="image_text">上传照片</view>
<mp-uploader bindsuccess="uploadSuccess" bindfail="uploadError" binddelete="binddelete" select="{{selectFile}}" upload="{{uplaodFileEnterprise}}" delete="{{true}}" files="{{enterprise}}" max-count="1" title="营业执照"></mp-uploader>
</view>
<!-- <image src="../../utils/static/images/required.png" class="_image"></image> -->
</view>
<view class="i-tabs-cel">
<view class="i-cell-left">企业名称</view>
<!-- <image src="../../utils/static/images/required.png" class="_image"></image> -->
<view class="i-cell-right">
<input class="weui-input" value="{{corporation_name}}" bindinput="inputCorporationName" maxlength="30" placeholder="请输入"/>
</view>
</view>
<view class="i-tabs-cel">
<view class="i-cell-left">纳税人识别号</view>
<view class="i-cell-right">
<input class="weui-input" value="{{unified_tax_code}}" bindinput="inputUnifiedTaxCode" maxlength="30" placeholder="请输入"/>
</view>
</view>
<!-- <view class="i-tabs-cel">
<view class="i-cell-left">联系人手机</view>
<view class="i-cell-right">
<input class="weui-input" value="{{contacts_mobile}}" bindinput="inputContactsMobile" maxlength="30" placeholder="请输入公司银行卡开户时的联系人姓名"/>
</view>
</view> -->
<view class="_text">* 证件信息识别如有偏差,请手动调整</view>
<view class="i-tabs-cel">
<view class="i-cell-left">联系人姓名</view>
<view class="i-cell-right">
<input class="weui-input" value="{{contacts_name}}" bindinput="inputContactsName" maxlength="30" placeholder="请输入公司银行卡开户时的联系人姓名"/>
</view>
</view>
</view>
<view wx:elif="{{refund === '2'}}" class="">
<view class="i-tabs-cel">
<view class="i-upload-pictures">
<text wx:if="{{id_card.length === 0}}" class="image_text">上传照片</text>
<mp-uploader bindsuccess="uploadSuccess" bindfail="uploadError" binddelete="binddelete" select="{{selectFile}}" upload="{{uplaodFile}}" files="{{id_card}}" max-count="1" title="身份证"></mp-uploader>
<!-- <view class="_text">证件信息识别如有偏差,请手动调整</view> -->
</view>
<!-- <image src="../../utils/static/images/required.png" class="_image"></image> -->
</view>
<view class="i-tabs-cel">
<view class="i-cell-left">姓名</view>
<!-- <image src="../../utils/static/images/required.png" class="_image"></image> -->
<view class="i-cell-right">
<input class="weui-input" value="{{name}}" bindinput="inputName" maxlength="30" placeholder="请输入"/>
</view>
</view>
<view class="i-tabs-cel">
<view class="i-cell-left">身份证号</view>
<!-- <image src="../../utils/static/images/required.png" class="_image"></image> -->
<view class="i-cell-right">
<input class="weui-input" value="{{card_number}}" bindinput="inputCardNumber" type="idcard" maxlength="18" placeholder="请输入"/>
</view>
</view>
</view>
<view class="i-page-section">
<button wx:if="{{refund === '1'}}" class="{{((corporation_name !== '') && (unified_tax_code !== '') && (business_licence !== '') && (contacts_name !== '')) ? '_button' : 'button_grey'}}" type="primary" bindtap="submit">下一步,输入 1 获取开户链接</button>
<button wx:elif="{{refund === '2'}}" class="{{((name !== '') && (card_number !== '') && (id_main !== '')) ? '_button' : 'button_grey'}}" type="primary" bindtap="submit">下一步,输入 1 获取开户链接</button>
</view>
<view wx:if="{{openState}}" class="mask">
<view class="head_center">
<view class="_center"><text>在客服对话框中,输入</text><text>1</text><text>获取开户链接</text></view>
<view bindtap="openAccount">
<button class="_button" type="primary" open-type="contact">我知道了</button>
</view>
</view>
</view>
</view>

View File

@ -0,0 +1,120 @@
page{
height: 100%;
background: #f1f1f1;
}
.i-tabs-cell{
display: flex;
justify-content: space-between;
padding: 30rpx 40rpx;
border-bottom: 2rpx solid #eeeeee;
background-color: #FFFFFF;
position: relative;
}
.i-tabs-cel{
padding: 30rpx 40rpx;
border-bottom: 2rpx solid #eeeeee;
background-color: #FFFFFF;
position: relative;
}
._text{
font-size: 26rpx;
color: rgba(49,104,233,0.6);
padding: 20rpx 40rpx;
background-color: #ffffff;
margin-bottom: 20rpx;
}
.i-tabs-cel ._image{
width: 50rpx;
height: 50rpx;
position: absolute;
top: 26rpx;
left: 0;
}
.i-upload-pictures{
position: relative;
}
.i-upload-pictures .image_text{
pointer-events: none;
position: absolute;
top: 220rpx;
left: 48rpx;
color: #999999;
font-size: 26rpx;
z-index: 90;
}
.i-upload-pictures .weui-uploader__file{
width: 300rpx;
height: 300rpx;
}
.i-tabs-cel .weui-uploader__input-box{
width: 200rpx;
height: 200rpx;
background: #fff;
border: 2rpx dashed #e2e2e2;
border-radius: 10rpx;
}
.weui-uploader__input-box::before {
top: 30%;
height: 46rpx;
}
.weui-uploader__input-box::after{
top: 30%;
width: 46rpx;
}
.i-cell-left{
width: 250rpx;
color: #999999;
font-size: 32rpx;
}
.i-cell-right ._com{
margin-right: 40rpx;
}
.weui-uploader__title{
font-size: 32rpx;
color: #999999;
margin-bottom: 20rpx;
}
.i-page-section ._button{
width: 85%;
margin: auto;
margin-top: 60rpx;
margin-bottom: 80rpx;
font-size: 36rpx;
}
.i-page-section .button_grey{
width: 85%;
margin: auto;
margin-top: 60rpx;
margin-bottom: 80rpx;
background-color: #999999 !important;
font-size: 36rpx;
}
/* 自定义弹窗 */
.mask {
position: fixed;
width: 100%;
height: 100%;
top: 0;
background: rgba(0, 0, 0, 0.6);
overflow: hidden;
z-index: 99;
}
.head_center{
margin: 50% 40rpx;
background-color: #ffffff;
padding: 30rpx 50rpx 60rpx 50rpx;
border-radius: 10rpx;
}
._center{
margin-bottom: 60rpx;
text-align: center;
font-size: 30rpx;
}
._center text:nth-child(2){
font-size: 90rpx;
font-weight: 700;
color: red;
margin: 0 10rpx;
}

33
pages/order/order.js Normal file
View File

@ -0,0 +1,33 @@
let app = getApp()
Page({
data: {
canLogin: true,
},
/** 生命周期函数--监听页面加载 */
onLoad: function (options) {
wx.showLoading({ title: '加载中' })
},
/** 生命周期函数--监听页面显示 */
onShow: function () {
// 判断有没有授权
if (!app.globalData.user_info.mobile) {
wx.redirectTo({
url: '/pages/authorizationPage/index'
})
return
}
// 获取数据
this.getData();
},
// 获取数据
getData() {
},
/** 用户点击右上角分享 */
onShareAppMessage: function () {
return { path: "pages/firstpage/firstpage?from=share" }
},
})

9
pages/order/order.json Normal file
View File

@ -0,0 +1,9 @@
{
"navigationBarTitleText": "我的订单",
"backgroundTextStyle":"dark",
"enablePullDownRefresh": true,
"usingComponents": {
"mp-icon": "weui-miniprogram/icon/icon",
"mp-navigation-bar": "weui-miniprogram/navigation-bar/navigation-bar"
}
}

3
pages/order/order.wxml Normal file
View File

@ -0,0 +1,3 @@
<view>
<view class="top-view" bindtap="gologin"></view>
</view>

4
pages/order/order.wxss Normal file
View File

@ -0,0 +1,4 @@
page{
background-color: #F9F9FB;
font-family: PingFangSC-Regular;
}

72
project.config.json Normal file
View File

@ -0,0 +1,72 @@
{
"description": "项目配置文件",
"packOptions": {
"ignore": []
},
"setting": {
"urlCheck": false,
"es6": true,
"enhance": false,
"postcss": true,
"preloadBackgroundData": false,
"minified": true,
"newFeature": false,
"coverView": true,
"nodeModules": true,
"autoAudits": false,
"showShadowRootInWxmlPanel": true,
"scopeDataCheck": false,
"uglifyFileName": false,
"checkInvalidKey": true,
"checkSiteMap": true,
"uploadWithSourceMap": true,
"compileHotReLoad": false,
"useMultiFrameRuntime": true,
"useApiHook": true,
"useApiHostProcess": false,
"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.16.0",
"appid": "wx1429ce8fccdd5005",
"projectname": "cherry_mini",
"debugOptions": {
"hidedInDevtools": []
},
"scripts": {},
"isGameTourist": false,
"condition": {
"plugin": {
"list": []
},
"game": {
"list": []
},
"gamePlugin": {
"list": []
},
"miniprogram": {
"list": [
{
"name": "pages/firstpage/firstpage",
"pathName": "pages/firstpage/firstpage",
"query": "bind=M001",
"scene": null
}
]
}
}
}

7
sitemap.json Normal file
View File

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

15
utils/css/public.wxss Normal file
View File

@ -0,0 +1,15 @@
.flex{
display: flex;
flex-direction: row;
justify-content:space-between;
}
.flex__item{
width: 48%;
height: 120rpx;
}
.mini-btn2{
font-weight: normal!important;
letter-spacing: 5rpx;
color: #FFF!important;
border-radius: 50rpx;
}

BIN
utils/images/dingdan1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.1 KiB

BIN
utils/images/shouye1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

79
utils/js/locales.js Normal file
View File

@ -0,0 +1,79 @@
import { getRequest, postRequest } from './request.js'
// 查询用户信息
function queryInfo(app) {
getRequest('/v1/m/info',{}).then(res => {
let user_info = {};
user_info.name = ''
user_info.user_id = ''
user_info.mobile = ''
let member_info = {};
member_info.name = ''
member_info.member_id = ''
member_info.rank = ''
member_info.vip_level = ''
member_info.type = ''
member_info.status = ''
let operator_info = {};
operator_info.mobile = ''
operator_info.operator_id = ''
operator_info.position = ''
operator_info.status = ''
app.globalData.user_info = res.data.user_info ? res.data.user_info : user_info
app.globalData.member_info = res.data.member_info ? res.data.member_info : member_info
app.globalData.operator_info = res.data.operator_info ? res.data.operator_info : operator_info
}).catch(err => {
console.log(err,'03')
})
}
// 查询平台信息
function platformInfo(app) {
getRequest('/v1/m/platform/info',{}).then(res => {
app.globalData.platformInfo = res.data
}).catch(err => {
console.log(err,'03')
})
}
// 重新登录
function queryLogin(app) {
wx.login({
success: function (loginRes) {
if (loginRes.errMsg === 'login:ok') {
postRequest('/v1/p/login',{ code: loginRes.code }).then(res => {
wx.setStorageSync('tokenKey', res.data.token);
wx.setStorageSync('actor', res.data.info.actor); // res.data.actor buyer seller
app.globalData.actor = res.data.info.actor
app.globalData.info = res.data.info
}).catch(err => {
console.log(err,'03')
})
}
}
})
}
// 登录过期处理
function signIn(err) {
if (err.statusCode === 401) {
wx.showToast({ title: '登录过期,重新加载小程序', icon: 'none', duration: 3000 })
setTimeout(function () {
// 获取缓存里的扫码内容 登录
let bind = wx.getStorageSync('bind')
app.loginCloudBird(bind);
}, 2000)
return
}
let errMsg = err.data ? err.data.error_message : '';
if (errMsg !== '') {
wx.showToast({ title: errMsg, icon: 'none', duration: 2000 })
}
}
module.exports = {
queryInfo,
platformInfo,
queryLogin,
signIn,
}

7
utils/js/replace.js Normal file
View File

@ -0,0 +1,7 @@
let pageTitle = '云禽助手'; // 页面标题
// "navigationBarTitleText": "云禽小助手"
module.exports = {
pageTitle,
}

148
utils/js/request.js Normal file
View File

@ -0,0 +1,148 @@
let tokenKey = "access-token";
// let serverUrl = "https://yapi.amtcloud.cn/mock/11/coconut"; // mock
// let serverUrl = "https://office-ssl.iilink.cn/coconut"; // 开发环境
// let serverUrl = "https://office-ssl.iilink.cn/coconut-uat"; // 测试环境
let serverUrl ='https://tokamak.amtcloud.cn/coconut'; // 生产
// 例外不用token的地址
let exceptionAddrArr = ['/login',];
//请求头处理函数
function CreateHeader(url, type) {
let header = {}
if (type == 'POST_PARAMS'){
header = {
'content-type': 'application/x-www-form-urlencoded'
}
}else{
header = {
'content-type': 'application/json'
}
}
if (exceptionAddrArr.indexOf(url) == -1) { //排除请求的地址不需要token的地址
let token = wx.getStorageSync('tokenKey');
// header.Authorization = token;
header['access-token'] = token;
}
return header;
}
//post请求数据在body中
function postRequest(url,data){
let header = CreateHeader(url,'POST');
return new Promise((resolve, reject) => {
wx.request({
url: serverUrl + url,
data: data,
header: header,
method: 'POST',
success: (res => {
if (200<=res.statusCode&&res.statusCode<300) {
//200: 服务端业务处理正常结束
resolve(res)
} else {
reject(res)
}
}),
fail: (res => {
reject(res)
})
})
})
}
//post请求数据按照query方式传给后端
function postParamsRequest(url, data) {
let header = CreateHeader(url,'POST_PARAMS');
let useurl = url;
return new Promise((resolve, reject) => {
wx.request({
url: serverUrl + useurl,
data: data,
header: header ,
method: 'POST',
success: (res => {
if (200<=res.statusCode&&res.statusCode<300) {
//200: 服务端业务处理正常结束
resolve(res)
} else {
reject(res)
}
}),
fail: (res => {
reject(res)
})
})
})
}
//get 请求
function getRequest(url, data) {
let header = CreateHeader(url, 'GET');
return new Promise((resolve, reject) => {
wx.request({
url: serverUrl + url,
data: data,
header: header,
method: 'GET',
success: (res => {
if (200<=res.statusCode&&res.statusCode<300) {
//200: 服务端业务处理正常结束
resolve(res)
} else {
reject(res)
}
}),
fail: (res => {
reject(res)
})
})
})
}
//put请求
function putRequest(url, data) {
let header = CreateHeader(url, 'PUT');
return new Promise((resolve, reject) => {
wx.request({
url: serverUrl + url,
data: data,
header: header,
method: 'PUT',
success: (res => {
if (200<=res.statusCode&&res.statusCode<300) {
//200: 服务端业务处理正常结束
resolve(res)
} else {
reject(res)
}
}),
fail: (res => {
reject(res)
})
})
})
}
//delete请求
function deleteRequest(url, data) {
let header = CreateHeader(url, 'DELETE');
return new Promise((resolve, reject) => {
wx.request({
url: serverUrl + url,
data: data,
header: header,
method: 'DELETE',
success: (res => {
if (200<=res.statusCode&&res.statusCode<300) {
//200: 服务端业务处理正常结束
resolve(res)
} else {
reject(res)
}
}),
fail: (res => {
reject(res)
})
})
})
}
module.exports.getRequest = getRequest;
module.exports.postRequest = postRequest;
module.exports.postParamsRequest = postParamsRequest;
module.exports.putRequest = putRequest;
module.exports.deleteRequest = deleteRequest;

162
utils/js/util.js Normal file
View File

@ -0,0 +1,162 @@
function formatTime(date,fmt) {
date = new Date(date);
var o = {
"M+": date.getMonth() + 1, //月份
"d+": date.getDate(), //日
"h+": date.getHours(), //小时
"m+": date.getMinutes(), //分
"s+": date.getSeconds(), //秒
"q+": Math.floor((date.getMonth() + 3) / 3), //季度
"S": date.getMilliseconds() //毫秒
};
if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
for (var k in o)
if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
return fmt;
}
function checkAuditTime(beginTime,endTime){
var nowDate = new Date();
var beginDate = new Date(nowDate);
var endDate = new Date(nowDate);
var beginIndex = beginTime.lastIndexOf("\:");
var beginHour = beginTime.substring(0,beginIndex);
var beginMinue = beginTime.substring(beginIndex+1,beginTime.length);
beginDate.setHours(beginHour,beginMinue, 0, 0);
var endIndex = endTime.lastIndexOf("\:");
var endHour = endTime.substring(0,endIndex);
var endMinue = endTime.substring(endIndex+1,endTime.length);
endDate.setHours(endHour, endMinue, 0, 0);
if(nowDate.getTime()-beginDate.getTime() >= 0 && nowDate.getTime() <= endDate.getTime()){
return true;
}else{
return false;
}
}
function formatNumber(n) {
n = n.toString()
return n[1] ? n : '0' + n
}
/**
* 时间戳转化为年
* number: 传入时间戳
* format返回格式支持自定义但参数必须与formateArr里保持一致
*/
function formatTimeTwo(number, format) {
number=new Date(number);
var formateArr = ['Y', 'M', 'D', 'h', 'm', 's'];
var returnArr = [];
var date = new Date(number * 1000);
returnArr.push(date.getFullYear());
returnArr.push(formatNumber(date.getMonth() + 1));
returnArr.push(formatNumber(date.getDate()));
returnArr.push(formatNumber(date.getHours()));
returnArr.push(formatNumber(date.getMinutes()));
returnArr.push(formatNumber(date.getSeconds()));
for (var i in returnArr) {
format = format.replace(formateArr[i], returnArr[i]);
}
return format;
}
//截图url参数
var getQueryString = function (url, name) {
var reg = new RegExp('(^|&|/?)' + name + '=([^&|/?]*)(&|/?|$)', 'i')
var r = url.substr(1).match(reg)
if (r != null) {
return r[2]
}
return null;
}
/**
** 加法函数用来得到精确的加法结果
** 说明javascript的加法结果会有误差在两个浮点数相加的时候会比较明显这个函数返回较为精确的加法结果
** 调用accAdd(arg1,arg2)
** 返回值arg1加上arg2的精确结果
**/
function addStringNumber(arg1, arg2) {
var r1, r2, m, c;
try {
r1 = arg1.toString().split(".")[1].length;
}
catch (e) {
r1 = 0;
}
try {
r2 = arg2.toString().split(".")[1].length;
}
catch (e) {
r2 = 0;
}
c = Math.abs(r1 - r2);
m = Math.pow(10, Math.max(r1, r2));
if (c > 0) {
var cm = Math.pow(10, c);
if (r1 > r2) {
arg1 = Number(arg1.toString().replace(".", ""));
arg2 = Number(arg2.toString().replace(".", "")) * cm;
} else {
arg1 = Number(arg1.toString().replace(".", "")) * cm;
arg2 = Number(arg2.toString().replace(".", ""));
}
} else {
arg1 = Number(arg1.toString().replace(".", ""));
arg2 = Number(arg2.toString().replace(".", ""));
}
return (((arg1 + arg2) / m) !== 0) ? ((arg1 + arg2) / m) : '0.00';
}
/**
** 减法函数用来得到精确的减法结果
** 说明javascript的减法结果会有误差在两个浮点数相减的时候会比较明显这个函数返回较为精确的减法结果
** 调用accSub(arg1,arg2)
** 返回值arg1加上arg2的精确结果
**/
function subtractStringNumber(arg1, arg2) {
var r1, r2, m, n;
try {
r1 = arg1.toString().split(".")[1].length;
}
catch (e) {
r1 = 0;
}
try {
r2 = arg2.toString().split(".")[1].length;
}
catch (e) {
r2 = 0;
}
m = Math.pow(10, Math.max(r1, r2)); //last modify by deeka //动态控制精度长度
n = (r1 >= r2) ? r1 : r2;
return (((arg1 * m - arg2 * m) / m).toFixed(n) !== 0) ? ((arg1 * m - arg2 * m) / m).toFixed(n) : '0.00';
}
/** 乘法函数,用来得到精确的乘法结果 说明javascript的乘法结果会有误差在两个浮点数相乘的时候会比较明显。这个函数返回较为精确的乘法结果。 调用accMul(arg1,arg2) 返回值arg1乘以 arg2的精确结果**/
function accMul(arg1, arg2) {
var m = 0, s1 = arg1.toString(), s2 = arg2.toString();
try {
m += s1.split(".")[1].length;
}
catch (e) {
}
try {
m += s2.split(".")[1].length;
}
catch (e) {
}
return Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m);
}
module.exports = {
formatTime,
checkAuditTime,
formatTimeTwo,
getQueryString,
addStringNumber,
subtractStringNumber,
accMul
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 196 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB