master
lion 2 years ago
parent 8cd13fecbe
commit 59fa7f4c49

@ -8,9 +8,6 @@
export default {
onLaunch: function() {
var that = this;
util.getOpenidInfo(function(res) {
console.log(res);
}, true);
const updateManager = uni.getUpdateManager();
updateManager.onCheckForUpdate(function(res) {
console.log(res.hasUpdate)

File diff suppressed because it is too large Load Diff

@ -0,0 +1,436 @@
<template>
<view class="canvasBox">
<template v-if="isUse">
<view class="box">
<view class="line"></view>
<view class="angle"></view>
</view>
<view class="box2" v-if="isUseTorch">
<view class="track" @click="openTrack">
<svg
t="1653920715959"
class="icon"
viewBox="0 0 1024 1024"
version="1.1"
xmlns="http://www.w3.org/2000/svg"
p-id="1351"
width="32"
height="32"
>
<path
d="M651.353043 550.479503H378.752795L240.862609 364.315031c-3.688944-4.897391-5.660621-10.876025-5.660621-17.045466v-60.040745c0-15.773416 12.847702-28.621118 28.621118-28.621118h502.459627c15.773416 0 28.621118 12.847702 28.621118 28.621118v59.977143c0 6.105839-1.971677 12.084472-5.660621 17.045466l-137.890187 186.228074zM378.752795 598.308571v398.024348c0 15.328199 12.402484 27.667081 27.667081 27.667081h217.266087c15.328199 0 27.667081-12.402484 27.66708-27.667081V598.308571H378.752795z m136.300124 176.942112c-14.564969 0-26.331429-11.76646-26.331428-26.331428v-81.283975c0-14.564969 11.76646-26.331429 26.331428-26.331429 14.564969 0 26.331429 11.76646 26.331429 26.331429v81.283975c0 14.564969-11.76646 26.331429-26.331429 26.331428zM512 222.608696c-17.554286 0-31.801242-14.246957-31.801242-31.801243V31.801242c0-17.554286 14.246957-31.801242 31.801242-31.801242s31.801242 14.246957 31.801242 31.801242v159.006211c0 17.554286-14.246957 31.801242-31.801242 31.801243zM280.932174 205.881242c-9.47677 0-18.889938-4.197764-25.122981-12.275279L158.242981 67.991056a31.864845 31.864845 0 0 1 5.597019-44.648944 31.864845 31.864845 0 0 1 44.648944 5.597018l97.502609 125.551305a31.864845 31.864845 0 0 1-5.597019 44.648944c-5.787826 4.579379-12.656894 6.741863-19.46236 6.741863zM723.987081 205.881242c-6.805466 0-13.674534-2.162484-19.462361-6.678261a31.794882 31.794882 0 0 1-5.597018-44.648944l97.566211-125.551304a31.794882 31.794882 0 0 1 44.648944-5.597019 31.794882 31.794882 0 0 1 5.597019 44.648944l-97.566211 125.551305c-6.360248 8.077516-15.709814 12.27528-25.186584 12.275279z"
fill="#ffffff"
p-id="1352"
></path>
</svg>
{{ trackStatus ? '关闭闪光灯' : '打开闪光灯' }}
</view>
</view>
<view class="mask1 mask" :style="'height:' + maskHeight + 'px;'"></view>
<view
class="mask2 mask"
:style="'width:' + maskWidth + 'px;top:' + maskHeight + 'px;height:' + canvasHeight + 'px'"
></view>
<view class="mask3 mask" :style="'height:' + maskHeight + 'px;'"></view>
<view
class="mask4 mask"
:style="'width:' + maskWidth + 'px;top:' + maskHeight + 'px;height:' + canvasHeight + 'px'"
></view>
</template>
<template v-else>
<slot name="error">
<view class="error">
<view class="on1">相机权限被拒绝请尝试如下操作</view>
<view>· 刷新页面后重试</view>
<view>· 在系统中检测当前App或浏览器的相机权限是否被禁用</view>
<view>· 如果依然不能体验建议在微信中打开链接</view>
</view>
</slot>
</template>
</view>
</template>
<script>
import jsQR from '../mumu-getQrcode/jsQR.js'
export default {
props: {
continue: {
type: Boolean,
default: false // false true
},
exact: {
type: String,
default: 'environment' // environment user
},
size: {
type: String,
default: 'whole' // whole balf
},
definition: {
type: Boolean,
default: false // fasle true
}
},
data() {
return {
windowWidth: 0,
windowHeight: 0,
video: null,
canvas2d: null,
canvas2d2: null,
canvasWidth: 200,
canvasHeight: 200,
maskWidth: 0,
maskHeight: 0,
inter: 0,
track: null,
isUseTorch: false,
trackStatus: false,
isParse: false,
isUse: true
}
},
mounted() {
if (origin.indexOf('https') === -1) throw '请在 https 环境中使用摄像头组件。'
this.windowWidth = document.documentElement.clientWidth || document.body.clientWidth
this.windowHeight = document.documentElement.clientHeight || document.body.clientHeight
this.windowHeight = this.size === 'whole' ? this.windowHeight : this.windowHeight / 2
this.isParse = true
this.$nextTick(() => {
this.createMsk()
this.openScan()
})
},
destroyed() {
this.closeCamera()
},
methods: {
openScan() {
const width = this.transtion(this.windowHeight)
const height = this.transtion(this.windowWidth)
const videoParam = {
audio: false,
video: {
facingMode: { exact: this.exact },
width,
height
}
}
navigator.mediaDevices
.getUserMedia(videoParam)
.then(stream => {
this.video = document.createElement('video')
this.video.width = this.windowWidth
this.video.height = this.windowHeight
const canvas = document.createElement('canvas')
canvas.id = 'canvas'
canvas.width = this.transtion(this.canvasWidth)
canvas.height = this.transtion(this.canvasHeight)
canvas.style = 'display:none;'
//canvas.style = 'position: fixed;top: 0;z-index: 999;left:0'
this.canvas2d = canvas.getContext('2d')
//
const canvasBox = document.querySelector('.canvasBox')
canvasBox.append(this.video)
canvasBox.append(canvas)
canvasBox.style = `width:${this.windowWidth}px;height:${this.windowHeight}px;`
// canvas
const canvas2 = document.createElement('canvas')
canvas2.id = 'canvas2'
canvas2.width = this.canvasWidth
canvas2.height = this.canvasHeight
canvas2.style = 'position: absolute;top: 50%;left: 50%;z-index: 20;transform: translate(-50%, -50%);'
this.canvas2d2 = canvas2.getContext('2d')
canvasBox.append(canvas2)
this.video.srcObject = stream
this.video.setAttribute('playsinline', true)
this.video.play()
this.tick()
this.track = stream.getVideoTracks()[0]
setTimeout(() => {
this.isUseTorch = this.track.getCapabilities().torch || null
}, 500)
})
.catch(err => {
this.isUse = false
this.$emit('error', err)
})
},
closeCamera() {
this.isParse = false
if (this.video && this.video.srcObject) {
this.video.srcObject.getTracks().forEach(track => {
track.stop()
})
}
},
tick() {
if (!this.isParse) return
if (this.video.readyState === this.video.HAVE_ENOUGH_DATA) {
this.canvas2d.drawImage(
this.video,
this.transtion(this.maskWidth),
this.transtion(this.maskHeight),
this.transtion(200),
this.transtion(200),
0,
0,
this.transtion(this.canvasWidth),
this.transtion(this.canvasHeight)
)
const imageData = this.canvas2d.getImageData(
0,
0,
this.transtion(this.canvasWidth),
this.transtion(this.canvasHeight)
)
const code = jsQR(imageData.data, imageData.width, imageData.height, {
inversionAttempts: 'dontInvert'
})
this.canvas2d2.clearRect(0, 0, this.canvasWidth, this.canvasHeight)
if (code) {
this.drawLine(code.location.topLeftCorner, code.location.topRightCorner)
this.drawLine(code.location.topRightCorner, code.location.bottomRightCorner)
this.drawLine(code.location.bottomRightCorner, code.location.bottomLeftCorner)
this.drawLine(code.location.bottomLeftCorner, code.location.topLeftCorner)
if (code.data) {
this.getData(code.data)
}
}
}
requestAnimationFrame(this.tick)
},
drawLine(begin, end, color = '#FF3B58') {
this.canvas2d2.beginPath()
this.canvas2d2.moveTo(this.nutranstion(begin.x), this.nutranstion(begin.y))
this.canvas2d2.lineTo(this.nutranstion(end.x), this.nutranstion(end.y))
this.canvas2d2.lineWidth = 4
this.canvas2d2.strokeStyle = color
this.canvas2d2.stroke()
},
getData(data) {
this.$emit('success', data)
if (!this.continue) {
this.closeCamera()
}
},
openTrack() {
this.trackStatus = !this.trackStatus
this.track.applyConstraints({
advanced: [{ torch: this.trackStatus }]
})
},
createMsk() {
this.maskWidth = this.windowWidth / 2 - this.canvasWidth / 2
this.maskHeight = this.windowHeight / 2 - this.canvasHeight / 2
},
transtion(number) {
return this.definition ? number * 2.8 : number * 1.8
},
nutranstion(number) {
return this.definition ? number / 2.8 : number / 1.8
}
}
}
</script>
<style scoped>
page {
background-color: #333333;
}
.canvasBox {
width: 100vw;
height: 100vh;
position: relative;
background-image: linear-gradient(
0deg,
transparent 24%,
rgba(32, 255, 77, 0.1) 25%,
rgba(32, 255, 77, 0.1) 26%,
transparent 27%,
transparent 74%,
rgba(32, 255, 77, 0.1) 75%,
rgba(32, 255, 77, 0.1) 76%,
transparent 77%,
transparent
),
linear-gradient(
90deg,
transparent 24%,
rgba(32, 255, 77, 0.1) 25%,
rgba(32, 255, 77, 0.1) 26%,
transparent 27%,
transparent 74%,
rgba(32, 255, 77, 0.1) 75%,
rgba(32, 255, 77, 0.1) 76%,
transparent 77%,
transparent
);
background-size: 3rem 3rem;
background-position: -1rem -1rem;
z-index: 10;
background-color: #1110;
}
.box {
width: 200px;
height: 200px;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
overflow: hidden;
border: 0.1rem solid rgba(0, 255, 51, 0.2);
z-index: 11;
}
.line {
height: calc(100% - 2px);
width: 100%;
background: linear-gradient(180deg, rgba(0, 255, 51, 0) 43%, #00ff33 211%);
border-bottom: 3px solid #00ff33;
transform: translateY(-100%);
animation: radar-beam 2s infinite alternate;
animation-timing-function: cubic-bezier(0.53, 0, 0.43, 0.99);
animation-delay: 1.4s;
}
.box:after,
.box:before,
.angle:after,
.angle:before {
content: '';
display: block;
position: absolute;
width: 3vw;
height: 3vw;
z-index: 12;
border: 0.2rem solid transparent;
}
.box:after,
.box:before {
top: 0;
border-top-color: #00ff33;
}
.angle:after,
.angle:before {
bottom: 0;
border-bottom-color: #00ff33;
}
.box:before,
.angle:before {
left: 0;
border-left-color: #00ff33;
}
.box:after,
.angle:after {
right: 0;
border-right-color: #00ff33;
}
@keyframes radar-beam {
0% {
transform: translateY(-100%);
}
100% {
transform: translateY(0);
}
}
.msg {
text-align: center;
padding: 20rpx 0;
}
.box2 {
width: 300px;
height: 200px;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
z-index: 20;
}
.track {
position: absolute;
bottom: -100px;
left: 50%;
transform: translateX(-50%);
z-index: 20;
color: #fff;
display: flex;
flex-direction: column;
align-items: center;
}
.mask {
position: absolute;
z-index: 10;
background-color: rgba(0, 0, 0, 0.55);
}
.mask1 {
top: 0;
left: 0;
right: 0;
}
.mask2 {
right: 0;
}
.mask3 {
right: 0;
left: 0;
bottom: 0;
}
.mask4 {
left: 0;
}
.error {
color: #fff;
padding: 40rpx;
font-size: 24rpx;
background-color: #333333;
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 550rpx;
border-radius: 20rpx;
}
.error .on1 {
font-size: 30rpx;
}
</style>

@ -46,6 +46,11 @@
"sdkConfigs" : {}
}
},
"h5" : {
"devServer" : {
"https" : true
}
},
/* */
"quickapp" : {},
/* */

@ -3,43 +3,30 @@
"^u-(.*)": "uview-ui/components/u-$1/u-$1.vue"
},
"pages": [ //pageshttps://uniapp.dcloud.io/collocation/pages
{
"path": "pages/index/index",
"style": {
"navigationBarTitleText": "访客核销"
}
},
{
"path": "pages/index/scancode",
"style": {
"navigationBarTitleText": "访客核销"
}
},
{
"path": "pages/index/cancel",
"style": {
"navigationBarTitleText": "访客核销"
}
}
],
"globalStyle": {
"navigationBarTextStyle": "black",
"navigationBarTitleText": "微信基础",
"navigationBarTitleText": "访客核销",
"navigationBarBackgroundColor": "#F8F8F8",
"backgroundColor": "#F8F8F8"
},
"tabBar": {
"color": "#351C1B",
"selectedColor": "#351C1B",
"backgroundColor": "#fdf9f5",
"list": [{
"pagePath": "pages/index/index",
"text": "首页",
"iconPath": "/static/img/icon_nav_home.png",
"selectedIconPath": "/static/img/icon_nav_home_on.png"
},
{
"pagePath": "pages/guide/index",
"text": "参观指南",
"iconPath": "/static/img/icon_nav_guide.png",
"selectedIconPath": "/static/img/icon_nav_guide_on.png"
},
{
"pagePath": "pages/map/map",
"text": "展馆导航",
"iconPath": "/static/img/icon_nav_map.png",
"selectedIconPath": "/static/img/icon_nav_map_on.png"
},
{
"pagePath": "pages/mine/index",
"text": "个人中心",
"iconPath": "/static/img/icon_nav_user.png",
"selectedIconPath": "/static/img/icon_nav_user_on.png"
}
]
}
}

@ -0,0 +1,80 @@
<template>
<view class="wrap">
<view class="cancelcode">
<view>核销码{{code}}</view>
<u-button @click='cancelcode' type="primary" text="核销" color='deepskyblue'></u-button>
</view>
<view class="cancelinfo">
<view>访客信息</view>
<view>
<view>姓名</view>
<view>访问日期</view>
<view>访问时段</view>
<view>访问事由</view>
<view>拜访单位</view>
<view>受访人</view>
<view>受访科室</view>
</view>
</view>
</view>
</template>
<script>
export default {
data() {
return {
code:''
}
},
onLoad(options) {
this.code = options.code
},
methods: {
cancelcode(){
uni.showToast({
icon: "none",
title: '核销成功',
duration: 3000
})
setTimeout(function(){
uni.navigateTo({
url:'/pages/index/index'
})
},500)
}
}
}
</script>
<style scoped>
.wrap{
padding:30rpx
}
.cancelcode{
/* display: flex;
justify-content: space-between; */
}
.cancelcode view{
margin-bottom:30rpx;
font-size: 36rpx;
}
/deep/ .cancelcode .u-button__text{
font-size: 36rpx!important;
}
.cancelinfo{
font-size: 36rpx;
margin-top:30rpx
}
.cancelinfo view{
color:#ddd;
margin-bottom:30rpx
}
.cancelinfo view view{
color:#333
}
</style>

@ -0,0 +1,70 @@
<template>
<view class="wrap">
<view class="scan" @click="toscan">
扫码
</view>
<view>
<view>今日访客</view>
<view class="list">
<view class='listitem'>
<text>张三</text>
<text>9:00</text>
<text>未核销</text>
</view>
<view class='listitem'>
<text>张三</text>
<text>9:00</text>
<text>已核销</text>
</view>
</view>
</view>
</view>
</template>
<script>
export default {
data() {
return {
}
},
onLoad() {
},
methods: {
toscan(){
uni.navigateTo({
url:'/pages/index/scancode'
})
}
}
}
</script>
<style scoped>
.wrap{
height:90vh;
min-height: 90vh;
padding:30rpx;
}
.scan {
width: 200rpx;
height: 200rpx;
border-radius: 200rpx;
background-color: deepskyblue;
line-height: 200rpx;
color: #fff;
font-size: 36rpx;
box-shadow: 0 0 0px 4px lightskyblue;
margin: 30rpx auto;
text-align: center;
}
.list{
height:65vh;
margin-top:20rpx
}
.listitem{
display: flex;
justify-content: space-between;
padding:20rpx;
border-bottom:1px solid #ccc
}
</style>

@ -0,0 +1,45 @@
<template>
<view>
<mumu-getQrcode @success='qrcodeSucess' @error="qrcodeError"></mumu-getQrcode>
</view>
</template>
<script>
import mumuGetQrcode from '../../components/mumu-getQrcode/mumu-getQrcode.vue'
//
export default {
components: {
mumuGetQrcode
},
onLoad() {
},
methods: {
qrcodeSucess(data) {
uni.showToast({
icon: "none",
title: '扫码成功',
duration: 3000
})
setTimeout(function(){
uni.navigateTo({
url:'/pages/index/cancel?code='+data
})
},500)
},
qrcodeError(err) {
console.log(err)
// alert(err)
uni.showModal({
title: '摄像头授权失败',
content: '摄像头授权失败,请检测当前浏览器是否有摄像头权限。',
success: () => {
// uni.navigateBack({})
}
})
}
}
}
</script>
<style></style>

@ -1,565 +1,98 @@
import md5 from "./md5.min";
const HOSTARR = {
'development': 'http://leyitest.ali251.langye.net',
'production': 'https://leyiyuyue.szgmbwg.org.cn'
}; // 审核状态
const HOST = HOSTARR[process.env
.NODE_ENV]; //"https://tiantianxinye.365care.langye.net/";//HOSTARR[process.env.NODE_ENV];//
const formatTime = date => {
const year = date.getFullYear();
const month = date.getMonth() + 1;
const day = date.getDate();
return [year, month, day].map(formatNumber).join('-');
};
const user_info_key = "userInfo_token";
const user_key = "userInfo";
const getUserInfo = (cb, refresh) => {
cb = cb || function() {}
refresh = refresh || false
if (!refresh) {
let user_info = uni.getStorageSync(user_key)
if (!isNull(user_info)) {
cb(user_info)
return
}
}
request({
api: '/api/mobile/user/show',
utilSuccess: function(res) {
uni.setStorageSync(user_key, res)
cb(res)
},
utilFail: function(res) {}
})
}
const getOpenidInfo = (cb, refresh) => {
cb = cb || function() {}
refresh = refresh || false
if (!refresh) {
let user_info = uni.getStorageSync(user_info_key)
if (!isNull(user_info)) {
cb(user_info)
return
}
}
uni.login({
provider: 'weixin',
success: (res) => {
console.log(res.code);
let url = HOST + '/api/mobile/user/login?code=' + res.code;
uni.request({
url: url,
method: 'GET',
success: result => {
let user_info = result.data
uni.setStorageSync(user_info_key, user_info)
cb(user_info)
}
});
}
});
}
const getUserProfile = (cb) => {
cb = cb || function() {}
wx.getUserProfile({
desc: '用于完善会员资料',
success: (res) => {
uni.setStorageSync('user_profile', res.userInfo)
cb(res.userInfo)
}
})
}
const formatTimeAll = 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;
}; // 快捷显示alert
const alert = msg => {
uni.showModal({
title: '',
content: msg,
showCancel: false
});
}; // 订单状态
const toast = msg => {
// setTimeout(function() {
// uni.showToast({
// icon: "none",
// title: msg,
// duration: 2000
// })
// }, 2000)
uni.showModal({
title: '',
content: msg,
showCancel: false
});
}; // 订单状态
const orderStatusDic = {
'0': '待确认',
'10': '待派单',
'20': '进行中',
'100': '已完成'
}; // 审核状态
const auditStatusDic = {
'0': '待审核',
'1': '已审核',
'-1': '已拒绝'
}; // 请求封装
const request = options => {
if (!options.customLoading) {
uni.showLoading({
title: '正在加载'
});
} else {
// 当前页面请求数量+1
// if (options.bindThis) {
// options.bindThis.setData({
// //loadingCount: options.bindThis.data.loadingCount + 1
// });
// }
}
options.url = HOST + options.api;
options.header = {
...options.header,
//'Accept': 'application/json',
//'Connection': 'keep-alive'
//'content-type': 'application/json'
}; // 如果已登录,请求中拼openId
var access_token = uni.getStorageSync(user_info_key).token;
if (isLogin()) {
options.data = {
...options.data,
'token': access_token
};
} // 如果是POST方法
if (options.method == 'POST' && !isNull(access_token)) {
// 拼时间戳
options.data.ts = new Date().getTime();
}
uni.request({
...options,
success: function(res) {
uni.hideLoading();
if (res.statusCode != 200) {
if (options.utilFail != undefined) {
if (res.statusCode == 401) {
uni.clearStorageSync();
uni.navigateTo({
url: '/pages/login/login'
});
} else {
options.utilFail('TODO: 特殊处理非200错误(' + res.statusCode + ')');
}
}
} else {
if (res.data.hasOwnProperty("errcode")) {
if (options.utilFail != undefined) {
options.utilFail(res.data.errmsg || '接口发生未知错误');
} else {
options.utilFail(res.data.errmsg);
}
} else {
if (options.utilSuccess != undefined) {
options.utilSuccess(res.data);
}
}
}
},
fail: options.utilFail,
complete: function(res) {
if (!options.customLoading) {
uni.hideNavigationBarLoading();
} else {
// 当前页面请求数量-1
// if (options.bindThis) {
// options.bindThis.setData({
// loadingCount: options.bindThis.data.loadingCount - 1
// });
// }
}
}
});
}; // 提交formID封装
const payOrder = (orderID, orderType, success, fail) => {
uni.request({
url: HOST + 'WxPay/ToPay?openId=' + uni.getStorageSync(user_info_key).WeChatOpenID +
'&orderId=' +
orderID + '&OrderType=' + orderType,
method: 'GET',
header: {
'content-type': 'application/json'
},
success: function(res) {
// 内容为空, 代表失败
if (res.data == '') {
fail('当前网络状况不好');
return;
} // 去掉转义字符
var pureStr = res.data.replace(/\\/g, '');
res.data = JSON.parse(pureStr);
var index = res.data.package.indexOf('=') + 1;
var prepayId = res.data.package.substring(index); // wxpay
uni.requestPayment({
timeStamp: res.data.timeStamp,
nonceStr: res.data.nonceStr,
package: res.data.package,
signType: res.data.signType,
paySign: res.data.paySign,
success: function(res) {
success(res); // 发送成功通知
request({
api: 'WxPay/PayTemplateMsg',
data: {
prepay_id: prepayId,
orderId: orderID,
isSuccess: 1,
failMsg: '',
xType: orderType
}
});
},
fail: function(res) {
fail(res);
var errMsg = res == 'requestPayment:fail cancel' ? '用户取消支付' :
res; // 发送失败通知
request({
api: 'WxPay/PayTemplateMsg',
data: {
prepay_id: prepayId,
orderId: orderID,
isSuccess: 0,
failMsg: errMsg,
xType: orderType
}
});
}
});
},
fail: function(err) {
fail('当前网络状况不好');
}
});
}; // 判断是否已登录同时有open-id和PhoneNum, 则认为已登录)
const isLogin = () => {
var userInfo = uni.getStorageSync(user_info_key);
return !isNull(userInfo.token);
}; // 判断是否为空
const isNull = p => {
return p == '' || p == undefined || p == null || p == 'undefined' || p == 'null';
}; // 正则
const phoneRegex = /^1[3456789]\d{9}$/;
const idCardRegex = /^\d{17}([0-9]|X)$/; // 去掉特殊字符
const filterSpecialChars = str => {
return str.replace(/[^\u4e00-\u9fa5a-zA-Z0-9\w]/g, '');
}; // 生成随机字符串
const randomStr = length => {
var ret = '';
var arr = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
'i', 'j',
'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C',
'D', 'E',
'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
'Y', 'Z'
];
for (var i = 0; i < length; i++) {
var randomIndex = Math.round(Math.random() * (arr.length - 1));
ret += arr[randomIndex];
}
return ret;
}; // proType对应的中文描述
const weekdayArr = ['周日', '周一', '周二', '周三', '周四', '周五', '周六']; // 是否合法的身份证
const isValidCardID = cardID => {
// Step1: 先判断格式
if (!idCardRegex.test(cardID)) return false; // Step2: 校验最后一位
var code = cardID.split(''); //加权因子
var factor = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]; //校验位
var parity = [1, 0, 'X', 9, 8, 7, 6, 5, 4, 3, 2];
var sum = 0;
var ai = 0;
var wi = 0;
for (var i = 0; i < 17; i++) {
ai = code[i];
wi = factor[i];
sum += ai * wi;
}
var last = parity[sum % 11];
return parity[sum % 11] == code[17];
const HOSTARR = {
'development': '',
'production': ''
};
const shareInfo = {
title:"",
imageUrl:"/static/share.jpg"
}
/**
* UTF16和UTF8转换对照表
* U+00000000 U+0000007F 0xxxxxxx
* U+00000080 U+000007FF 110xxxxx 10xxxxxx
* U+00000800 U+0000FFFF 1110xxxx 10xxxxxx 10xxxxxx
* U+00010000 U+001FFFFF 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
* U+00200000 U+03FFFFFF 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
* U+04000000 U+7FFFFFFF 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
*/
var Base64 = {
// 转码表
table: ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',
'T', 'U',
'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
'o', 'p',
'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8',
'9', '+',
'/'
],
UTF16ToUTF8: function(str) {
var res = [],
len = str.length;
for (var i = 0; i < len; i++) {
var code = str.charCodeAt(i);
if (code > 0x0000 && code <= 0x007F) {
// 单字节这里并不考虑0x0000因为它是空字节
// U+00000000 U+0000007F 0xxxxxxx
res.push(str.charAt(i));
} else if (code >= 0x0080 && code <= 0x07FF) {
// 双字节
// U+00000080 U+000007FF 110xxxxx 10xxxxxx
// 110xxxxx
var byte1 = 0xC0 | code >> 6 & 0x1F; // 10xxxxxx
var byte2 = 0x80 | code & 0x3F;
res.push(String.fromCharCode(byte1), String.fromCharCode(byte2));
} else if (code >= 0x0800 && code <= 0xFFFF) {
// 三字节
// U+00000800 U+0000FFFF 1110xxxx 10xxxxxx 10xxxxxx
// 1110xxxx
var byte1 = 0xE0 | code >> 12 & 0x0F; // 10xxxxxx
var byte2 = 0x80 | code >> 6 & 0x3F; // 10xxxxxx
var byte3 = 0x80 | code & 0x3F;
res.push(String.fromCharCode(byte1), String.fromCharCode(byte2), String.fromCharCode(
byte3));
} else if (code >= 0x00010000 && code <= 0x001FFFFF) { // 四字节
// U+00010000 U+001FFFFF 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
} else if (code >= 0x00200000 && code <= 0x03FFFFFF) { // 五字节
// U+00200000 U+03FFFFFF 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
} else
/** if (code >= 0x04000000 && code <= 0x7FFFFFFF)*/
{ // 六字节
// U+04000000 U+7FFFFFFF 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
}
}
return res.join('');
},
UTF8ToUTF16: function(str) {
var res = [],
len = str.length;
var i = 0;
for (var i = 0; i < len; i++) {
var code = str.charCodeAt(i); // 对第一个字节进行判断
if ((code >> 7 & 0xFF) == 0x0) {
// 单字节
// 0xxxxxxx
res.push(str.charAt(i));
} else if ((code >> 5 & 0xFF) == 0x6) {
// 双字节
// 110xxxxx 10xxxxxx
var code2 = str.charCodeAt(++i);
var byte1 = (code & 0x1F) << 6;
var byte2 = code2 & 0x3F;
var utf16 = byte1 | byte2;
res.push(Sting.fromCharCode(utf16));
} else if ((code >> 4 & 0xFF) == 0xE) {
// 三字节
// 1110xxxx 10xxxxxx 10xxxxxx
var code2 = str.charCodeAt(++i);
var code3 = str.charCodeAt(++i);
var byte1 = code << 4 | code2 >> 2 & 0x0F;
var byte2 = (code2 & 0x03) << 6 | code3 & 0x3F;
utf16 = (byte1 & 0x00FF) << 8 | byte2;
res.push(String.fromCharCode(utf16));
} else if ((code >> 3 & 0xFF) == 0x1E) { // 四字节
// 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
} else if ((code >> 2 & 0xFF) == 0x3E) { // 五字节
// 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
} else
/** if (((code >> 1) & 0xFF) == 0x7E)*/
{ // 六字节
// 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
}
}
return res.join('');
},
encode: function(str) {
if (!str) {
return '';
}
var utf8 = this.UTF16ToUTF8(str); // 转成UTF8
var i = 0; // 遍历索引
var len = utf8.length;
var res = [];
while (i < len) {
var c1 = utf8.charCodeAt(i++) & 0xFF;
res.push(this.table[c1 >> 2]); // 需要补2个=
if (i == len) {
res.push(this.table[(c1 & 0x3) << 4]);
res.push('==');
break;
}
var c2 = utf8.charCodeAt(i++); // 需要补1个=
if (i == len) {
res.push(this.table[(c1 & 0x3) << 4 | c2 >> 4 & 0x0F]);
res.push(this.table[(c2 & 0x0F) << 2]);
res.push('=');
break;
}
var c3 = utf8.charCodeAt(i++);
res.push(this.table[(c1 & 0x3) << 4 | c2 >> 4 & 0x0F]);
res.push(this.table[(c2 & 0x0F) << 2 | (c3 & 0xC0) >> 6]);
res.push(this.table[c3 & 0x3F]);
}
return res.join('');
},
decode: function(str) {
if (!str) {
return '';
}
var len = str.length;
var i = 0;
var res = [];
while (i < len) {
var code1 = this.table.indexOf(str.charAt(i++));
var code2 = this.table.indexOf(str.charAt(i++));
var code3 = this.table.indexOf(str.charAt(i++));
var code4 = this.table.indexOf(str.charAt(i++));
var c1 = code1 << 2 | code2 >> 4;
var c2 = (code2 & 0xF) << 4 | code3 >> 2;
var c3 = (code3 & 0x3) << 6 | code4;
res.push(String.fromCharCode(c1));
if (code3 != 64) {
res.push(String.fromCharCode(c2));
}
if (code4 != 64) {
res.push(String.fromCharCode(c3));
}
}
return this.UTF8ToUTF16(res.join(''));
}
};
module.exports = {
HOST: HOST,
formatTime: formatTime,
formatTimeAll: formatTimeAll,
formatNumber: formatNumber,
alert: alert,
getOpenidInfo: getOpenidInfo,
request: request,
payOrder: payOrder,
isLogin: isLogin,
isNull: isNull,
phoneRegex: phoneRegex,
idCardRegex: idCardRegex,
filterSpecialChars: filterSpecialChars,
randomStr: randomStr,
weekdayArr: weekdayArr,
Base64: Base64,
orderStatusDic: orderStatusDic,
auditStatusDic: auditStatusDic,
getUserProfile: getUserProfile,
getUserInfo: getUserInfo,
toast: toast,
isValidCardID:isValidCardID,
shareInfo:shareInfo
const HOST = HOSTARR[process.env
.NODE_ENV]; //"https://tiantianxinye.365care.langye.net/";//HOSTARR[process.env.NODE_ENV];//
const request = options => {
if (!options.customLoading) {
//if(false){
uni.showLoading({
title: '正在加载'
});
} else {
// 当前页面请求数量+1
if (options.bindThis) {
//options.bindThis.loadingCount=options.bindThis.data.loadingCount + 1;
}
}
options.url = HOST + options.api;
options.header = {
...options.header,
//'Accept': 'application/json',
//'Connection': 'keep-alive'
//'content-type': 'application/json'
}; // 如果已登录,请求中拼openId
if (options.method == 'POST') {
// 拼时间戳
options.data.ts = new Date().getTime();
}
uni.request({
...options,
success: function(res) {
uni.hideLoading();
if (res.statusCode != 200) {
if (options.utilFail != undefined) {
if (res.statusCode == 401) {
} else {
options.utilFail('TODO: 特殊处理非200错误(' + res.statusCode + ')');
}
}
} else {
if (!isNull(res.data.errorcode) || res.data.errorcode == 0) {
if (options.utilFail != undefined) {
options.utilFail(res.data.errormsg || '接口发生未知错误');
} else {
options.utilFail(res.data.errormsg);
}
} else {
if (options.utilSuccess != undefined) {
options.utilSuccess(res.data);
}
}
}
},
fail: function(res) {
uni.hideLoading();
options.utilFail(res);
},
complete: function(res) {
if (!options.customLoading) {
uni.hideNavigationBarLoading();
} else {
// 当前页面请求数量-1
if (options.bindThis) {
//options.bindThis.setData({
//loadingCount: options.bindThis.data.loadingCount - 1
//});
}
}
}
});
}; // 提交formID封装
const isNull = p => {
return p == '' || p == undefined || p == null || p == 'undefined' || p == 'null';
}; // 正则
const alert = msg => {
uni.showModal({
title: '',
content: msg,
showCancel: false
});
}; // 订单状态
module.exports = {
HOST: HOST,
request: request,
isNull:isNull,
alert:alert
};

Loading…
Cancel
Save