1
This commit is contained in:
@@ -17,16 +17,27 @@
|
||||
<script>
|
||||
export default {
|
||||
name: 'loginBottom',
|
||||
props:{
|
||||
checked:{
|
||||
type:Boolean,
|
||||
default:false
|
||||
}
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
count: 0,
|
||||
hotline: '4008-56-5355'
|
||||
}
|
||||
},
|
||||
watch:{
|
||||
checked(n){
|
||||
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
onChange() {
|
||||
this.count++
|
||||
this.$emit('onCheck', this.count % 2 != 0)
|
||||
onChange() {
|
||||
let checked = !this.checked
|
||||
this.$emit('onCheck', checked)
|
||||
},
|
||||
toAgree(link) {
|
||||
uni.navigateTo({
|
||||
|
||||
@@ -72,55 +72,45 @@
|
||||
|
||||
|
||||
<view class="margin-lg flex flex-direction text-center">
|
||||
|
||||
|
||||
|
||||
<button class="cu-btn round bg-main-oil lg text-lg" open-type="getPhoneNumber"
|
||||
<button v-if="checked" @click="decryptPhoneNumber" class="cu-btn round bg-main-oil lg text-lg" open-type="getPhoneNumber"
|
||||
@getphonenumber="decryptPhoneNumber">
|
||||
|
||||
|
||||
|
||||
<text class="cuIcon-weixin padding-right-xs"> </text>
|
||||
|
||||
|
||||
|
||||
<text>
|
||||
|
||||
|
||||
|
||||
微信用户一键登录
|
||||
|
||||
|
||||
|
||||
</text>
|
||||
|
||||
|
||||
|
||||
</button>
|
||||
|
||||
|
||||
|
||||
|
||||
<button v-else class="cu-btn round bg-main-oil lg text-lg" @click="$refs.popup.open('center')">
|
||||
<text class="cuIcon-weixin padding-right-xs"> </text>
|
||||
<text>
|
||||
微信用户一键登录
|
||||
</text>
|
||||
</button>
|
||||
<button class="cu-btn margin-top round lg" @tap="refuseEmpower">
|
||||
|
||||
|
||||
|
||||
输入手机号码登录
|
||||
|
||||
|
||||
|
||||
</button>
|
||||
<button class="cu-btn bg-0 margin-top round text-sm" @tap="refuseLogin">
|
||||
跳过
|
||||
</button>
|
||||
|
||||
</view>
|
||||
<loginBottom ref='loginBottom' :checked='checked' @onCheck="checkAgree" />
|
||||
|
||||
|
||||
|
||||
<!-- <loginBottom :check="loginOut" /> -->
|
||||
|
||||
|
||||
<uni-popup ref='popup'>
|
||||
<view class="protocol_body">
|
||||
<view class="protocol_header">
|
||||
使用协议及隐私保护
|
||||
</view>
|
||||
<view class="protocol_content">
|
||||
为了更好地保障您的合法权益,请您阅读并同意 <text style=" color: black; font-weight: 600;"
|
||||
@click="$refs.loginBottom.toAgree('zhongpinUserAgree')">《用户协议》</text> 与 <text
|
||||
style=" color: black; font-weight: 600;"
|
||||
@click="$refs.loginBottom.toAgree('zhongpinPrivacyAgreement')">《隐私政策》</text>。
|
||||
</view>
|
||||
<view class="protocol_footer">
|
||||
<button @click="$refs.popup.close()" class="protocol_footer_close">取消</button>
|
||||
<button @click="checked=true;$refs.popup.close();" class="protocol_footer_confirm">确定</button>
|
||||
</view>
|
||||
</view>
|
||||
</uni-popup>
|
||||
|
||||
</view>
|
||||
</template>
|
||||
@@ -138,6 +128,7 @@
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
checked: false,
|
||||
// imgsrc:require('../../../BagStation/static/img/login-bg.png'),
|
||||
userHandle: false,
|
||||
TabCur: 0,
|
||||
@@ -153,12 +144,12 @@
|
||||
sessionKey: '',
|
||||
nickName: '',
|
||||
loginOut: uni.getStorageSync('loginOut') ? true : false,
|
||||
scanningParams:null
|
||||
scanningParams: null
|
||||
}
|
||||
},
|
||||
onLoad(options) {
|
||||
uni.clearStorageSync()
|
||||
this.refreshLocation()
|
||||
// this.refreshLocation()
|
||||
uni.login({
|
||||
provider: 'weixin',
|
||||
success: (loginRes) => {
|
||||
@@ -166,7 +157,7 @@
|
||||
this.onceCode = code
|
||||
oilIdentityApi.sendCode(this.onceCode).then(res => {
|
||||
if (res.code === 20000) {
|
||||
if(options.scanningParams) {
|
||||
if (options.scanningParams) {
|
||||
// 用于扫码进入油站详情页面
|
||||
this.scanningParams = options.scanningParams
|
||||
}
|
||||
@@ -199,6 +190,9 @@
|
||||
})
|
||||
},
|
||||
methods: {
|
||||
checkAgree(val) {
|
||||
this.checked = val
|
||||
},
|
||||
refuseLogin() {
|
||||
uni.switchTab({
|
||||
url: '/pages/tabbar/home/home'
|
||||
@@ -232,6 +226,13 @@
|
||||
|
||||
|
||||
decryptPhoneNumber(e) {
|
||||
if (!this.checked) {
|
||||
uni.showToast({
|
||||
title: '请您阅读并同意协议',
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
if (e.detail.errMsg === 'getPhoneNumber:ok') {
|
||||
const data1 = {
|
||||
...e.detail,
|
||||
@@ -276,15 +277,14 @@
|
||||
uni.showToast({
|
||||
title: res.msg,
|
||||
icon: 'none',
|
||||
complete: (err) => {
|
||||
}
|
||||
complete: (err) => {}
|
||||
})
|
||||
}, 1000);
|
||||
if(this.scanningParams) {
|
||||
if (this.scanningParams) {
|
||||
uni.redirectTo({
|
||||
url: `/BagStation/pages/stationDetail/stationDetail?q=${this.scanningParams}`
|
||||
})
|
||||
return
|
||||
return
|
||||
}
|
||||
// 这里有问题
|
||||
uni.switchTab({
|
||||
@@ -297,6 +297,56 @@
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.protocol_footer_close {
|
||||
width: 185rpx;
|
||||
border-radius: 94rpx 94rpx 94rpx 94rpx;
|
||||
opacity: 1;
|
||||
border: 1px solid #000000;
|
||||
font-size: 26rpx;
|
||||
}
|
||||
|
||||
.protocol_footer_confirm {
|
||||
width: 185rpx;
|
||||
background: #1890FF;
|
||||
border-radius: 56rpx 56rpx 56rpx 56rpx;
|
||||
opacity: 1;
|
||||
font-size: 26rpx;
|
||||
color: #FFFFFF;
|
||||
}
|
||||
|
||||
.protocol_footer {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
color: #FFFFFF;
|
||||
}
|
||||
|
||||
.protocol_content {
|
||||
font-size: 32rpx;
|
||||
font-family: PingFang SC-Medium, PingFang SC;
|
||||
font-weight: 400;
|
||||
color: #666666;
|
||||
line-height: 46rpx;
|
||||
margin: 60rpx 0;
|
||||
}
|
||||
|
||||
.protocol_header {
|
||||
width: 330rpx;
|
||||
height: 32rpx;
|
||||
font-size: 36rpx;
|
||||
color: #000000;
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.protocol_body {
|
||||
background: #FFFFFF;
|
||||
border-radius: 20rpx 20rpx 20rpx 20rpx;
|
||||
opacity: 1;
|
||||
padding: 70rpx 50rpx;
|
||||
max-width: 634rpx;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.login-bg {
|
||||
width: 100%;
|
||||
}
|
||||
@@ -310,8 +360,9 @@
|
||||
height: 750rpx;
|
||||
background-color: #fff;
|
||||
}
|
||||
.bg-0{
|
||||
|
||||
.bg-0 {
|
||||
background-color: transparent;
|
||||
color: #555555;
|
||||
}
|
||||
</style>
|
||||
</style>
|
||||
@@ -409,16 +409,18 @@
|
||||
icon: 'none'
|
||||
})
|
||||
}, 1000);
|
||||
if(this.scanningParams) {
|
||||
console.log(this.scanningParams,'this.scanningParams')
|
||||
if(this.scanningParams&&this.scanningParams!=='null') {
|
||||
uni.redirectTo({
|
||||
url: `/BagStation/pages/stationDetail/stationDetail?q=${this.scanningParams}`
|
||||
})
|
||||
return
|
||||
}else{
|
||||
// 这里有问题
|
||||
uni.switchTab({
|
||||
url: '/pages/tabbar/home/home'
|
||||
})
|
||||
}
|
||||
// 这里有问题
|
||||
uni.switchTab({
|
||||
url: '/pages/tabbar/home/home'
|
||||
})
|
||||
|
||||
}
|
||||
},
|
||||
checkCompany() {
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
<view class="action " @tap="openMap">
|
||||
<view class="oil-main-color">
|
||||
<my-icon iconName="sy-der-icon.png" class="padding-right-xs text-sm"></my-icon>
|
||||
{{siteInfo.juli|distanceFilter}}
|
||||
{{(siteInfo.juli|distanceFilter)||'暂无信息'}}
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
@@ -23,7 +23,8 @@
|
||||
<view class="action " @tap="openMap">
|
||||
<view class="oil-main-color">
|
||||
<my-icon iconName="sy-der-icon.png" class="padding-right-xs text-sm"></my-icon>
|
||||
{{siteInfo.juli|distanceFilter}}
|
||||
<text v-if="!location">暂无信息</text>
|
||||
<text v-else >{{siteInfo.juli|distanceFilter}}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
@@ -49,7 +50,8 @@
|
||||
<view class="action " @tap="openMap">
|
||||
<view class="oil-main-color">
|
||||
<my-icon iconName="sy-der-icon.png" class="padding-right-xs text-sm"></my-icon>
|
||||
{{siteInfo.juli|distanceFilter}}
|
||||
<text v-if="!location">暂无信息</text>
|
||||
<text v-else >{{siteInfo.juli|distanceFilter}}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
@@ -161,6 +163,7 @@
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
location:null,
|
||||
showtitle:false,
|
||||
radio: 'B',
|
||||
mainURL: this.global.mainURL,
|
||||
@@ -168,9 +171,7 @@
|
||||
otherImgURL:this.global.otherImgURL,
|
||||
active: 0,
|
||||
ColorList: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
|
||||
siteInfo: {
|
||||
|
||||
},
|
||||
siteInfo: { },
|
||||
activeCur: '',
|
||||
activePay: null,
|
||||
qrcodePay: null,
|
||||
@@ -184,10 +185,9 @@
|
||||
},
|
||||
onUnload() {
|
||||
this.innerAudioContext && this.innerAudioContext.stop()
|
||||
},
|
||||
|
||||
|
||||
onLoad(option) {
|
||||
},
|
||||
onLoad(option) {
|
||||
this.location = uni.getStorageSync('location')
|
||||
// console.log('option',option)
|
||||
// let userInfo = uni.getStorageSync('user')
|
||||
// if(!userInfo && option.q) {
|
||||
@@ -212,11 +212,11 @@
|
||||
let siteInfos = uni.getStorageSync('siteInfo')
|
||||
var oilItem = JSON.parse(decodeURIComponent(siteInfos))
|
||||
}else{
|
||||
var oilItem = JSON.parse(decodeURIComponent(option.item))
|
||||
var oilItem = JSON.parse(decodeURIComponent(option.item));
|
||||
}
|
||||
|
||||
uni.setStorageSync('oilItem',oilItem)
|
||||
this.getSiteInfo(oilItem.siteId)
|
||||
console.log(oilItem,'oilItemoilItemoilItem')
|
||||
uni.setStorageSync('oilItem',oilItem)
|
||||
this.getSiteInfo(oilItem)
|
||||
this.siteId = oilItem.siteId
|
||||
if(oilItem.listTag == '万金油'){
|
||||
this.audioUrl = 'https://publicxingyou.oss-cn-hangzhou.aliyuncs.com/mp-oil/wanjinyou.mp3'
|
||||
@@ -227,9 +227,10 @@
|
||||
}else if(oilItem.listTag == '上汽联名卡'){
|
||||
this.audioUrl = 'https://publicxingyou.oss-cn-hangzhou.aliyuncs.com/mp-oil/shangqi.mp3'
|
||||
}
|
||||
this.ContextAudio(this.audioUrl)
|
||||
this.ContextAudio(this.audioUrl);
|
||||
|
||||
},
|
||||
methods: {
|
||||
methods: {
|
||||
obtainUrlPathParameterTarget(url) {
|
||||
let target = {}
|
||||
if(url.includes('?')) {
|
||||
@@ -278,19 +279,41 @@
|
||||
url: `/BagStation/pages/stationDetail/stieQr?siteId=${this.siteId}&activeChannelCode=${this.activeChannelCode}&secondChannelCode=${this.secondChannelCode}`
|
||||
})
|
||||
},
|
||||
getSiteInfo(id) {
|
||||
getSiteInfo(item) {
|
||||
let data2 = {
|
||||
...uni.getStorageSync('location'),
|
||||
siteId: id,
|
||||
siteId: item.siteId,
|
||||
clientBelong: "ZHONGPIN"
|
||||
}
|
||||
oilSiteApi.getSiteDetails(data2).then(res => {
|
||||
if (res.code == 20000) {
|
||||
this.siteInfo = res.data
|
||||
}
|
||||
})
|
||||
let user = uni.getStorageSync('user');
|
||||
if (user) {
|
||||
oilSiteApi.getSiteDetails(data2).then(res => {
|
||||
if (res.code == 20000) {
|
||||
this.siteInfo = Object.assign(item,res.data);
|
||||
}
|
||||
})
|
||||
} else {
|
||||
this.siteInfo = item;
|
||||
}
|
||||
|
||||
},
|
||||
makePay() {
|
||||
let user = uni.getStorageSync('user');
|
||||
if(!user){
|
||||
uni.showModal({
|
||||
title: '请您登录',
|
||||
content: "登录佰川加油才可以加油 |˛˙꒳˙)♡",
|
||||
confirmText: '去登陆',
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
uni.reLaunch({
|
||||
url: '../../../BagAuth/pages/login/login?loginType=true'
|
||||
})
|
||||
}
|
||||
}
|
||||
});
|
||||
return
|
||||
}
|
||||
if(this.siteInfo.juli > 1000 ){
|
||||
this.showtitle = true
|
||||
}else{
|
||||
|
||||
@@ -8,7 +8,9 @@
|
||||
<view class="action">
|
||||
<view class="text-grey text-sm " style="padding-top: 6rpx;">
|
||||
<!-- <my-icon iconName="sy-der-icon.png" class="padding-right-xs text-sm"></my-icon> -->
|
||||
{{siteItem.juli|distanceFilter}}
|
||||
<!-- {{siteItem.juli|distanceFilter}} -->
|
||||
<text v-if="!location">暂无信息</text>
|
||||
<text v-else >{{siteInfo.juli|distanceFilter}}</text>
|
||||
</view>
|
||||
</view>
|
||||
<view>
|
||||
@@ -70,6 +72,10 @@
|
||||
<script>
|
||||
export default {
|
||||
props: {
|
||||
location:{
|
||||
type:Object,
|
||||
default:()=>null
|
||||
},
|
||||
siteItem: {
|
||||
type: Object,
|
||||
default () {}
|
||||
|
||||
@@ -103,9 +103,7 @@
|
||||
},
|
||||
areaCodeList1: {
|
||||
type: Array,
|
||||
default () {
|
||||
return []
|
||||
}
|
||||
default:()=> []
|
||||
},
|
||||
menuList: {
|
||||
type: Array,
|
||||
@@ -124,7 +122,7 @@
|
||||
},
|
||||
mounted() {
|
||||
if(this.areaCodeList1.length == 0){
|
||||
this.areaCodeList = uni.getStorageSync('areaCodeList')
|
||||
this.areaCodeList = uni.getStorageSync('areaCodeList') || []
|
||||
}else{
|
||||
this.areaCodeList = this.areaCodeList1
|
||||
}
|
||||
|
||||
4
main.js
4
main.js
@@ -7,7 +7,7 @@ import cuCustom from './colorui/components/cu-custom.vue'
|
||||
import myIcon from '@/components/my-icon/my-icon.vue'
|
||||
import encode from '@/utils/encode'
|
||||
import global from '@/api/global.js'
|
||||
|
||||
import tools from '@/utils/tool.js'
|
||||
// import home from '@/pages/components/home/home.vue'
|
||||
// import user from '@/pages/components/user/user.vue'
|
||||
// import stationList from '@/pages/components/station/stationList.vue'
|
||||
@@ -25,7 +25,7 @@ Vue.component('my-icon', myIcon)
|
||||
Vue.component('cu-custom',cuCustom)
|
||||
Vue.component('my-empty',Empty)
|
||||
|
||||
|
||||
Vue.prototype.tools = tools;
|
||||
Vue.prototype.moneyIntercept = function(value){
|
||||
if (value != 'xxx.x') {
|
||||
return String(value).split('.')[1]&&String(value).split('.')[1].length>2? Number(`${String(value).split('.')[0]}.${String(value).split('.')[1].substring(0,1)}${ Number(String(value).split('.')[1].substring(1,2)) + 1}`) :Number(value).toFixed(2);
|
||||
|
||||
@@ -128,7 +128,7 @@
|
||||
</view> -->
|
||||
<view class=" ">
|
||||
<view class="" v-if="siteList.length>0">
|
||||
<site-item v-for="(item,index) in siteList" :key="item.id" :site-item="item" :first="index==0"
|
||||
<site-item :location='location' v-for="(item,index) in siteList" :key="item.id" :site-item="item" :first="index==0"
|
||||
:listHeight="listHeight" class="cu-list menu-avatar cu-item" @tap="toDetail(item)">
|
||||
</site-item>
|
||||
</view>
|
||||
@@ -159,6 +159,7 @@
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
location:null,
|
||||
swiperArray: [
|
||||
{
|
||||
src:this.global.starUrl+'banner.png',
|
||||
@@ -296,8 +297,6 @@
|
||||
},
|
||||
onLoad() {
|
||||
this.reverseGeocoder(this.location)
|
||||
this.refreshLocation()
|
||||
|
||||
// if (!uni.getStorageSync('filterData')) {
|
||||
// this.getFilterData()
|
||||
// }
|
||||
@@ -310,6 +309,7 @@
|
||||
}, 800);
|
||||
},
|
||||
onShow() {
|
||||
this.location = uni.getStorageSync('location')
|
||||
const token = uni.getStorageSync('Authorization')
|
||||
const openid = uni.getStorageSync('openid')
|
||||
if (token && openid) {
|
||||
@@ -320,9 +320,11 @@
|
||||
icon: "none"
|
||||
})
|
||||
}
|
||||
uni.navigateTo({
|
||||
// url: `/BagStation/orderDetail/orderDetail?id=XOILAWMP202107070000025117`
|
||||
})
|
||||
this.refreshLocation();
|
||||
|
||||
// uni.navigateTo({
|
||||
// url: `/BagStation/orderDetail/orderDetail?id=XOILAWMP202107070000025117`
|
||||
// })
|
||||
// uni.redirectTo({
|
||||
// url:'/BagStation/pages/makeOrder/makeOrder'
|
||||
// // url:'/BagStation/pages/makeOrder/payResult?status=success'
|
||||
@@ -395,11 +397,27 @@
|
||||
success: (res) => {
|
||||
uni.setStorageSync('location', res)
|
||||
},
|
||||
fail: () => {
|
||||
uni.getSetting({
|
||||
success: (res) => {
|
||||
if (!res.authSetting['scope.userLocation']) {
|
||||
uni.showModal({
|
||||
title: '请您打开定位权限',
|
||||
content: '用于获取您当前位置附近的油站',
|
||||
confirmText: '去设置',
|
||||
success: (resSec) => {
|
||||
if (resSec.confirm) {
|
||||
uni.openSetting({})
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
complete: () => {
|
||||
this.getSiteList()
|
||||
// // console.log('made')
|
||||
},
|
||||
|
||||
});
|
||||
},
|
||||
hideModel(name) {
|
||||
@@ -416,7 +434,7 @@
|
||||
oilSiteApi.getUserAuthInfo().then(res => {
|
||||
if (res.code === 20000) {
|
||||
this.getAmount()
|
||||
this.getSiteList()
|
||||
// this.getSiteList()
|
||||
// realStatus: 0 vehicleStatus: 0
|
||||
if (this.showAuthFrzen <= new Date().getTime()) {
|
||||
this.showAuthFrror = res.data.realStatus && res.data.vehicleStatus ? false :
|
||||
@@ -507,8 +525,8 @@
|
||||
currentPage: 1,
|
||||
pageSize: 10,
|
||||
params: { //类型:Object 必有字段 备注:// 筛选对象
|
||||
// longitude: 117.157817, // 必有字段 备注:// 当前位置经度
|
||||
// latitude: 31.802472, // 必有字段 备注:// 当前位置维度
|
||||
longitude: 117.157817, // 必有字段 备注:// 当前位置经度
|
||||
latitude: 31.802472, // 必有字段 备注:// 当前位置维度
|
||||
// siteBrand: "", // 备注:// 石油品牌 ( 1-中国石油 2-中国石化 3-壳牌 4-民营 5-中海油 6-京博 7-中化石油 8-其他 )
|
||||
// channelCode: "", // 备注:// 渠道编码 ( OIL:星油 WJY:万金油 LV:老吕(找油网) TY:团油 YDJY:一点加油(壳牌))
|
||||
// oilProductCode: "0#" // 备注:// 油号选择 ( 0# 92# 92#)
|
||||
@@ -518,9 +536,36 @@
|
||||
sort: "juli", //类型:String 必有字段 备注:// 智能排序 ( price:价格最低 juli:距离最近 ) 默认距离排序
|
||||
...uni.getStorageSync('location'),
|
||||
...this.filterData,
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
if (!uni.getStorageSync('user')) {
|
||||
oilSiteApi.readOnlySites(params).then(res => {
|
||||
this.getCount++
|
||||
if (res.code == 20000) {
|
||||
this.siteList = res.data.list
|
||||
} else {
|
||||
if (this.getCount == 1) {
|
||||
setTimeout(() => {
|
||||
this.getSiteList()
|
||||
}, 1000)
|
||||
}
|
||||
}
|
||||
})
|
||||
} else {
|
||||
oilSiteApi.getSiteLists(params).then(res => {
|
||||
if (res.code == 20000) {
|
||||
this.siteList = res.data.list
|
||||
}
|
||||
})
|
||||
}
|
||||
oilSiteApi[uni.getStorageSync('user')?'getSiteLists':'getSiteLists'](params).then(res=>{
|
||||
if (res.code == 20000) {
|
||||
this.siteList = res.data.list
|
||||
}
|
||||
})
|
||||
/* caolc 禁用
|
||||
别人写的有毛病
|
||||
if (!uni.getStorageSync('user')) {
|
||||
oilSiteApi.readOnlySites(params).then(res => {
|
||||
this.getCount++
|
||||
@@ -532,8 +577,8 @@
|
||||
setTimeout(() => {
|
||||
this.getSiteList()
|
||||
}, 1000)
|
||||
|
||||
|
||||
|
||||
|
||||
} else {
|
||||
uni.getSetting({
|
||||
success: (resSet) => {
|
||||
@@ -545,7 +590,7 @@
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
uni.openSetting({
|
||||
|
||||
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -563,11 +608,19 @@
|
||||
}
|
||||
})
|
||||
}
|
||||
*/
|
||||
|
||||
},
|
||||
toDetail(item) {
|
||||
let itemS = encodeURIComponent(JSON.stringify(item))
|
||||
let itemS = encodeURIComponent(JSON.stringify(item));
|
||||
uni.navigateTo({
|
||||
url: `/BagStation/pages/stationDetail/stationDetail?item=${itemS}`,
|
||||
fail: (err) => {},
|
||||
success: () => {}
|
||||
})
|
||||
// console.log(uni.getStorageSync('user'))
|
||||
// return
|
||||
/*
|
||||
if (uni.getStorageSync('user')) {
|
||||
uni.navigateTo({
|
||||
url: `/BagStation/pages/stationDetail/stationDetail?item=${itemS}`,
|
||||
@@ -592,6 +645,8 @@
|
||||
}
|
||||
})
|
||||
}
|
||||
*/
|
||||
|
||||
},
|
||||
getFilterData() {
|
||||
oilSiteApi.getCheckInfo().then(res => {
|
||||
|
||||
@@ -256,8 +256,13 @@
|
||||
}
|
||||
},
|
||||
},
|
||||
onLoad() {
|
||||
this.refreshLocation()
|
||||
onShow() {
|
||||
this.tools.userLocationChenk().then(res => {
|
||||
this.refreshLocation();
|
||||
}).catch(err => {});
|
||||
},
|
||||
onLoad() {
|
||||
// this.refreshLocation()
|
||||
if (!uni.getStorageSync('filterData')) {
|
||||
this.getFilterData()
|
||||
} else {
|
||||
@@ -373,13 +378,14 @@
|
||||
});
|
||||
},
|
||||
|
||||
getSiteList() {
|
||||
this.refreshLocation()
|
||||
getSiteList() {
|
||||
let data1 = {
|
||||
currentPage: this.currentPage,
|
||||
pageSize: 10,
|
||||
params: { //类型:Object 必有字段 备注:// 筛选对象
|
||||
clientBelong:'ZHONGPIN',
|
||||
longitude: 117.157817, // 必有字段 备注:// 当前位置经度
|
||||
latitude: 31.802472, // 必有字段 备注:// 当前位置维度
|
||||
sort: "juli", //类型:String 必有字段 备注:// 智能排序 ( price:价格最低 juli:距离最近 ) 默认距离排序
|
||||
siteName: this.siteName,
|
||||
...uni.getStorageSync('location'),
|
||||
@@ -410,7 +416,7 @@
|
||||
})
|
||||
} else {
|
||||
oilSiteApi.getSiteLists(data1).then(res => {
|
||||
if (res.code == 20000) {
|
||||
if (res.code == 20000) {
|
||||
this.siteList = this.siteList.concat(res.data.list)
|
||||
if (res.data.list.length < 10) { //判断接口返回数据量小于请求数据量,则表示此为最后一页
|
||||
this.loadStatus = 'nomore'
|
||||
|
||||
@@ -7,8 +7,8 @@ const env = 'production'/* */
|
||||
const testUrl = 'http://192.168.0.254:38080'
|
||||
// const productUrl = 'http://121.196.213.68/adminapi' //预生产
|
||||
|
||||
const productUrl = 'https://www.xingoil.com/adminapi' // 生产,加密 new
|
||||
// const productUrl = 'http://uat.xingoil.com/adminapi' // 生产,加密 new
|
||||
// const productUrl = 'https://www.xingoil.com/adminapi' // 生产,加密 new
|
||||
const productUrl = 'http://uat.xingoil.com/adminapi' // 生产,加密 new
|
||||
const service = axios.create({
|
||||
baseURL: env == 'production' ? productUrl : testUrl,
|
||||
// baseURL: testUrl,
|
||||
|
||||
698
utils/tool.js
Normal file
698
utils/tool.js
Normal file
@@ -0,0 +1,698 @@
|
||||
import utils from '@/utils/encode';
|
||||
// import login from '../api/login.js';
|
||||
// import station from '@/api/station.js';
|
||||
import QQMapWX from '@/static/qqmap-wx-jssdk.min.js';
|
||||
import oilIdentityApi from '@/api/oil-identity.js'
|
||||
class Anticorrosive {
|
||||
//需要的基本数据定义
|
||||
reqData = null
|
||||
data = null;
|
||||
configure = null;
|
||||
pageKeys = ['outputField', 'field', 'type', 'defaultValue'];
|
||||
constructor(data, configure) {
|
||||
// 初始化数据 => 校验数据
|
||||
this.data = data;
|
||||
this.configure = configure;
|
||||
return this.chenk();
|
||||
}
|
||||
|
||||
// 递归 生成数据结构
|
||||
generate(data, configure) {
|
||||
// 通过传入的源数据生成相应的数据结构
|
||||
let reqData = data instanceof Array ? [] : {};
|
||||
//递归配置参数直到数据类型为基本类型 创建相应的数据(深拷贝)
|
||||
for (const fields of configure) {
|
||||
this.pageKeys.forEach(item => {
|
||||
let fieldsKeys = Object.keys(fields);
|
||||
if (!fieldsKeys.includes(item)) throw new Error(`必填字段 :${item} 不能为空`);
|
||||
})
|
||||
let field = data[fields.field] === undefined ? fields.defaultValue ? fields.defaultValue : null : data[
|
||||
fields.field]; //如果为undefined直接为null;
|
||||
let isChildField = fields?.childField ? true : false; //判断是否有子配置项
|
||||
let isType = fields.type === typeof field; //判断数据类型是否匹配
|
||||
// console.log(field,fields.type,typeof field,'isType')
|
||||
//检测是field类型 基本类型/引用类型
|
||||
if (field instanceof Function) { //引用类型且为Function
|
||||
console.warn("Function类型无法配置");
|
||||
reqData[fields.outputField] = field
|
||||
} else if (field instanceof Set) { //引用类型且为Set
|
||||
console.warn("Set类型无法配置");
|
||||
reqData[fields.outputField] = field
|
||||
} else if (field instanceof Map) { //引用类型且为Map
|
||||
console.warn("Map类型无法配置");
|
||||
reqData[fields.outputField] = field
|
||||
} else if (field instanceof Array) { //引用类型且为数组 递归
|
||||
if (!isType) console.warn(`数据源与数据类型不匹配:${fields.field}`);
|
||||
reqData[fields.outputField] = [];
|
||||
reqData[fields.outputField] = isChildField ? field.map(element => this.generate(element, fields
|
||||
.childField)) : field;
|
||||
} else if (field instanceof Object) { //引用类型 递归
|
||||
if (!isType) console.warn(`数据源与数据类型不匹配:${fields.field}`);
|
||||
reqData[fields.outputField] = isChildField ? this.generate(field, fields.childField) : field;
|
||||
} else {
|
||||
// null 和基本类型
|
||||
reqData[fields.outputField] = this.voluation(field, fields);
|
||||
}
|
||||
}
|
||||
return reqData
|
||||
}
|
||||
// 数据校验
|
||||
chenk() {
|
||||
let testingType = true;
|
||||
if (this.data == undefined || this.data.constructor == Function || this.data.constructor == Set || this.data
|
||||
.constructor == Map || !(this.data instanceof Object)) {
|
||||
testingType = false
|
||||
}
|
||||
if (this.configure == undefined || this.configure.constructor == Function || this.configure.constructor ==
|
||||
Set || this.configure.constructor == Map || !(this.configure instanceof Object)) {
|
||||
testingType = false
|
||||
}
|
||||
if (testingType) {
|
||||
// 校验通过 => 生成数据
|
||||
return this.generate(this.data, this.configure)
|
||||
} else {
|
||||
return this.data
|
||||
}
|
||||
}
|
||||
voluation(data, configure) {
|
||||
if (!(typeof configure.defaultValue === configure.type)) throw new Error(
|
||||
`定义的数据类型与默认值数据类型不匹配:${configure.field}`);
|
||||
let value = null;
|
||||
let isData = data === null;
|
||||
if (isData) return configure.defaultValue; //如果data为null直接返回默认值
|
||||
switch (configure.type) {
|
||||
case 'number':
|
||||
value = isNaN(Number(data)) ? configure.defaultValue : Number(data);
|
||||
break;
|
||||
case 'string':
|
||||
value = String(data)
|
||||
break;
|
||||
case 'boolean':
|
||||
value = Boolean(data)
|
||||
break;
|
||||
}
|
||||
if (configure?.customHandler) { //是否有自定义处理程序
|
||||
let customHandlerValue = configure.customHandler(value);
|
||||
value = customHandlerValue !== undefined ? customHandlerValue : value
|
||||
}
|
||||
return value
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
Anticorrosive,
|
||||
getPhone(e){
|
||||
return new Promise((re,rj)=>{
|
||||
const data1 = {
|
||||
...e.detail,
|
||||
sessionKey: uni.getStorageSync('sessionKey'),
|
||||
unionId: uni.getStorageSync('unionid'),
|
||||
openId: uni.getStorageSync('openid'),
|
||||
appId: 'wxed3e2914d6aa4d52'
|
||||
};
|
||||
oilIdentityApi.ackPhone(data1).then(resj => {
|
||||
re(resj.data)
|
||||
});
|
||||
})
|
||||
},
|
||||
async WXlogin(e) {
|
||||
return new Promise((re, rj) => {
|
||||
uni.login({
|
||||
provider: 'weixin',
|
||||
success: async (loginRes) => {
|
||||
const code = loginRes.code
|
||||
oilIdentityApi.sendCode(loginRes.code).then(res => {
|
||||
if (res.code === 20000) {
|
||||
uni.setStorageSync('sessionKey', res.data.sessionKey);
|
||||
uni.setStorageSync('openid', res.data.openId);
|
||||
uni.setStorageSync('unionid', res.data.unionId);
|
||||
const data1 = {
|
||||
...e.detail,
|
||||
sessionKey: uni.getStorageSync('sessionKey'),
|
||||
unionId: uni.getStorageSync('unionid'),
|
||||
openId: uni.getStorageSync('openid'),
|
||||
appId: 'wxed3e2914d6aa4d52'
|
||||
}
|
||||
oilIdentityApi.getPhone(data1).then(resj => {
|
||||
re(resj.data.phoneNumber)
|
||||
});
|
||||
} else if (res.code == 1002) {
|
||||
uni.showModal({
|
||||
title: '微信登录失败提醒',
|
||||
content: `${res.msg}如有疑问,请联系客服处理`
|
||||
})
|
||||
|
||||
}
|
||||
}).catch(err => {
|
||||
uni.showToast({
|
||||
title: '登陆失败',
|
||||
icon: 'none'
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
},
|
||||
fail: err => {},
|
||||
})
|
||||
})
|
||||
},
|
||||
difTags(res) {
|
||||
res.data.forEach((item, index) => {
|
||||
item['tags'] = ['maxCurrent', 'createSource'].map((tag, tagIndex) => {
|
||||
let result = {}
|
||||
switch (tag) {
|
||||
case 'maxCurrent':
|
||||
result = {
|
||||
label: `最大${item[tag]}A`,
|
||||
color: '#6EA29BCC'
|
||||
}
|
||||
break;
|
||||
case 'createSource':
|
||||
let source = this.difSource(item[tag]);
|
||||
result = {
|
||||
...source
|
||||
}
|
||||
break;
|
||||
}
|
||||
return result
|
||||
});
|
||||
if (index == 0) item['tags'].unshift({
|
||||
label: '距离最近',
|
||||
color: '#36658DFF'
|
||||
})
|
||||
})
|
||||
},
|
||||
difSource(e) {
|
||||
switch (e) {
|
||||
case 'XXCD':
|
||||
return {
|
||||
label: '星星充电',
|
||||
color: '#E48011CC'
|
||||
}
|
||||
case 'QT':
|
||||
return {
|
||||
label: '其他',
|
||||
color: '#121836CC'
|
||||
}
|
||||
case 'KD':
|
||||
return {
|
||||
label: '快电',
|
||||
color: '#FF5F0FCC'
|
||||
}
|
||||
case 'TLD':
|
||||
return {
|
||||
label: '特来电',
|
||||
color: '#7AA0F4CC'
|
||||
}
|
||||
case 'YKC':
|
||||
return {
|
||||
label: '云快充',
|
||||
color: '#00A7EBCC'
|
||||
}
|
||||
case 'ZGGD':
|
||||
return {
|
||||
label: '中国国电',
|
||||
color: '#27AB3BCC'
|
||||
}
|
||||
}
|
||||
},
|
||||
userLocationChenk(){
|
||||
return new Promise((re,rj)=>{
|
||||
wx.getSetting({
|
||||
success(res) {
|
||||
console.log(res.authSetting,'res.authSetting')
|
||||
if (!res.authSetting[ 'scope.userLocation']) {
|
||||
console.log('用户没有授权用户没有授权用户没有授权用户没有授权')
|
||||
// 用户没有授权
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '您暂无授权定位权限,将无法显示油站距离',
|
||||
success(res) {
|
||||
if (res.confirm) {
|
||||
wx.openSetting({
|
||||
success(res) {
|
||||
if (res.authSetting['scope.userLocation']) {
|
||||
re()
|
||||
// 授权成功,重新定位
|
||||
} else {
|
||||
// 没有允许定位权限
|
||||
wx.showToast({
|
||||
title: '您拒绝了定位权限,将无法使用附近电站站功能',
|
||||
icon: 'none'
|
||||
});
|
||||
rj('拒绝了定位权限')
|
||||
}
|
||||
},
|
||||
fail() {
|
||||
rj('openSetting调用失败')
|
||||
}
|
||||
})
|
||||
}else{
|
||||
rj('取消授权')
|
||||
}
|
||||
}
|
||||
})
|
||||
}else{
|
||||
re()
|
||||
}
|
||||
},
|
||||
fail(err){
|
||||
rj(err)
|
||||
}
|
||||
})
|
||||
})
|
||||
},
|
||||
getLocation() {
|
||||
return new Promise((re, rj) => {
|
||||
uni.getLocation({
|
||||
type: 'wgs84',
|
||||
geocode: true,
|
||||
success: function(res) {
|
||||
const qqmapsdk = new QQMapWX({
|
||||
key: 'NYEBZ-YURY3-XTU3N-YBR54-PKW6E-ROB2F'
|
||||
});
|
||||
qqmapsdk.reverseGeocoder({
|
||||
location: {
|
||||
latitude: res.latitude,
|
||||
longitude: res.longitude
|
||||
},
|
||||
success(addressRes){
|
||||
var address = addressRes.result.formatted_addresses.recommend;
|
||||
let location = {
|
||||
...res,
|
||||
address
|
||||
}
|
||||
uni.setStorageSync('location',location );
|
||||
re(location)
|
||||
},
|
||||
fail(err){
|
||||
rj(err)
|
||||
}
|
||||
})
|
||||
|
||||
},
|
||||
fail(err) {
|
||||
rj(err)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
},
|
||||
routingParameterGeneration(parameter){
|
||||
if(parameter==null||parameter==undefined) return;
|
||||
const parameterType = typeof parameter;
|
||||
if( parameterType== 'string'){
|
||||
let obj = {};
|
||||
let splitParameter = parameter.split('?');
|
||||
if(splitParameter.length<=1){
|
||||
console.warn("暂无路径参数");
|
||||
return
|
||||
}
|
||||
splitParameter[1].split('&').forEach(item=>{
|
||||
if(item.indexOf('=')!==-1){
|
||||
let splitItem = item.split('=')
|
||||
obj[splitItem[0]] = splitItem[1]
|
||||
}else{
|
||||
console.warn("error");
|
||||
console.log(item)
|
||||
}
|
||||
})
|
||||
return obj
|
||||
}else if(parameterType == 'object'){
|
||||
let stringParameter = '?'
|
||||
let parameterEntries = Object.entries(parameter);
|
||||
parameterEntries.forEach((key,index)=>{
|
||||
let itemString = `${key[0]}=${key[1]}${ parameterEntries.length-1==index?'':'&' }`;
|
||||
stringParameter += itemString
|
||||
})
|
||||
return stringParameter
|
||||
}
|
||||
},
|
||||
scanCode() {
|
||||
return new Promise((re, rj) => {
|
||||
uni.scanCode({
|
||||
onlyFromCamera: true,
|
||||
success: (res) => {
|
||||
re(res)
|
||||
},
|
||||
fail(err) {
|
||||
rj(err)
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
},
|
||||
loginOut() {
|
||||
// return new Promise((re, rj) => {
|
||||
// login.logoutAuthSystem('ELEC_COM_DRIVER_MINI').then(res => {
|
||||
// if (res.code == 20000) {
|
||||
// re(res)
|
||||
// } else {
|
||||
// rj(res)
|
||||
// }
|
||||
// }).catch(err => {
|
||||
// rj(err)
|
||||
// })
|
||||
// })
|
||||
},
|
||||
getCode(data) {
|
||||
return new Promise((re, rj) => {
|
||||
login.sendSmsForEleccomDriverMini(data).then(res => {
|
||||
if (res.code == 20000) {
|
||||
re(res)
|
||||
} else {
|
||||
rj(res)
|
||||
}
|
||||
}).catch(err => {
|
||||
rj(err)
|
||||
})
|
||||
})
|
||||
},
|
||||
bindLoginByPhoneOilOmsWebMini(data) {
|
||||
// return new Promise((re, rj) => {
|
||||
// login.bindLoginByPhoneOilOmsWebMini({
|
||||
// ...data,
|
||||
// sessionKey: uni.getStorageSync('sessionKey'),
|
||||
// unionId: uni.getStorageSync('unionid'),
|
||||
// openId: uni.getStorageSync('openid'),
|
||||
// }).then(res => {
|
||||
// if (res.code == 20000) {
|
||||
// re(res)
|
||||
// } else {
|
||||
// rj(res.code)
|
||||
// }
|
||||
// }).catch(err => {
|
||||
// rj(err)
|
||||
// })
|
||||
// })
|
||||
},
|
||||
sendCode(code) {
|
||||
// return new Promise((re, rj) => {
|
||||
// login.sendCode(code).then(res => {
|
||||
// uni.setStorageSync('openid', res.data.openId);
|
||||
// uni.setStorageSync('unionid', res.data.unionId);
|
||||
// uni.setStorageSync('sessionKey', res.data.sessionKey)
|
||||
// re(res)
|
||||
// }).catch(err => {
|
||||
// rj(err)
|
||||
// })
|
||||
// })
|
||||
},
|
||||
autoLogin(codeData) {
|
||||
// return new Promise((re, rj) => {
|
||||
// login.loginOilOmsWebMini(codeData).then(res => {
|
||||
// if (res.code == 20000) {
|
||||
// re(res)
|
||||
// } else {
|
||||
// rj(res.code)
|
||||
// }
|
||||
// }).catch(err => {
|
||||
// rj(err)
|
||||
// })
|
||||
// })
|
||||
},
|
||||
weixinLogin() {
|
||||
return new Promise((re, rj) => {
|
||||
uni.login({
|
||||
provider: 'weixin',
|
||||
success: (loginRes) => {
|
||||
re(loginRes)
|
||||
},
|
||||
fail: err => {
|
||||
rj(err)
|
||||
},
|
||||
})
|
||||
})
|
||||
},
|
||||
async getCards() {
|
||||
// await station.getAccountList().then(res => {
|
||||
// if (res.code == 20000) {
|
||||
// res.data.forEach(item => {
|
||||
// item['isEye'] = false
|
||||
// })
|
||||
// uni.setStorageSync('cards', res.data);
|
||||
// }
|
||||
// })
|
||||
},
|
||||
async loginSuccess(res) {
|
||||
let resData = res.data
|
||||
if (resData.authTokenDTO.loginFlag) {
|
||||
uni.setStorageSync('Authorization', resData.authTokenDTO.accessToken)
|
||||
uni.setStorageSync('accountStatus', resData.isCompanyAccount)
|
||||
let user = resData.authTokenDTO.loginUser
|
||||
uni.setStorageSync('user', user);
|
||||
await this.getCards();
|
||||
setTimeout(() => {
|
||||
uni.showToast({
|
||||
title: res.msg,
|
||||
icon: 'none',
|
||||
complete: (err) => {}
|
||||
})
|
||||
}, 500);
|
||||
uni.reLaunch({
|
||||
url: '/pages/index/index',
|
||||
fail() {
|
||||
console.log('跳转失败')
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
//调起上传图片
|
||||
chooseImage(clickfn) {
|
||||
const JSESSIONID = utils.uuid()
|
||||
let chooseImageUrl = ''
|
||||
uni.chooseImage({
|
||||
success: (chooseImageRes) => {
|
||||
uni.showLoading({
|
||||
title: '加载中'
|
||||
})
|
||||
const tempFilePaths = chooseImageRes.tempFilePaths;
|
||||
uni.uploadFile({
|
||||
url: 'https://www.xingoil.com/adminapi/oil-oss/obejct/uploadFile',
|
||||
filePath: tempFilePaths[0],
|
||||
name: 'file',
|
||||
formData: {
|
||||
ossKey: 'xingyou',
|
||||
pathKey: 'publicxingyou',
|
||||
encrypt: 'PUBLIC',
|
||||
},
|
||||
header: {
|
||||
"Content-Type": "multipart/form-data",
|
||||
"Authorization": uni.getStorageSync('Authorization'),
|
||||
'dataSources': 'MP',
|
||||
"imei": uni.getStorageSync('unionid'),
|
||||
"openId": uni.getStorageSync('openid'),
|
||||
'JSESSIONID': JSESSIONID,
|
||||
'token': utils.md5Salt(JSESSIONID)
|
||||
},
|
||||
success: (uploadFileRes) => {
|
||||
uni.hideLoading()
|
||||
chooseImageUrl = JSON.parse(uploadFileRes.data).data.publicUrl
|
||||
clickfn(chooseImageUrl)
|
||||
},
|
||||
fail: () => {
|
||||
uni.hideLoading()
|
||||
}
|
||||
});
|
||||
},
|
||||
fail: () => {
|
||||
uni.hideLoading()
|
||||
}
|
||||
});
|
||||
},
|
||||
getnum(num, size = 2) {
|
||||
if (String(num).indexOf('.') == -1 || String(num).split('.')[1].length < 2) return Number(num).toFixed(size);
|
||||
var s = num.toString();
|
||||
var result = s.substring(0, s.indexOf(".") + 1 + size);
|
||||
return result
|
||||
},
|
||||
//数据转为两位小数
|
||||
numberSetting(obj, key, nm = 2) {
|
||||
if (arguments.length < 2) throw new Error('请检查函数配置参数,最少传递两个必填参数');
|
||||
if (!Array.isArray(key)) throw new Error('参数2必须为Array');
|
||||
// if (obj.constructor.toString().indexOf('Object') == -1) throw new Error('参数1必须为Object');
|
||||
if (Array.isArray(obj)) {
|
||||
obj.forEach((item, index) => {
|
||||
if (Array.isArray(item)) {
|
||||
this.numberSetting(item, key, nm)
|
||||
}
|
||||
let keyArray = Object.keys(item)
|
||||
keyArray.forEach(i => {
|
||||
if (key.includes(i)) {
|
||||
item[i] = isNaN(Number(item[i])) ? 0.00 : Number(item[i]).toFixed(nm)
|
||||
}
|
||||
})
|
||||
})
|
||||
} else {
|
||||
Object.keys(obj).forEach(keys => {
|
||||
if (key.includes(keys)) {
|
||||
// if (isNaN(Number(obj[keys]))) throw new Error(keys + '值不是数字')
|
||||
// obj[keys] = Number(obj[keys]).toFixed(nm);
|
||||
obj[keys] = isNaN(Number(obj[keys])) ? 0.00 : Number(obj[keys]).toFixed(nm)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
},
|
||||
/*
|
||||
校验数据规范
|
||||
data:校验源数据,
|
||||
options:校验配置,
|
||||
correct:是否修正
|
||||
*/
|
||||
checkData(data, options, correct = false) {
|
||||
// 校验对象
|
||||
let checkData = {
|
||||
typeFn(data, type) {
|
||||
return typeof data == type
|
||||
},
|
||||
correctFn(item) {
|
||||
console.log('校验失败', item)
|
||||
//查看是否修正
|
||||
if (correct) {
|
||||
//修正
|
||||
switch (item.type) {
|
||||
case 'number':
|
||||
data[item.field] = data[item.field] == null ? item.defaultValue : data[item.field] ===
|
||||
'' || isNaN(Number(data[item.field])) ? item.defaultValue : Number(data[item.field])
|
||||
break;
|
||||
case 'string':
|
||||
data[item.field] = data[item.field] == null ? item.defaultValue : String(data[item
|
||||
.field])
|
||||
break;
|
||||
case 'null':
|
||||
data[item.field] = null
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
//无需直接退出
|
||||
wx.exitMiniProgram({
|
||||
success: function() {
|
||||
console.log('拜拜')
|
||||
}
|
||||
})
|
||||
// throw new Error('错误!!!');
|
||||
}
|
||||
},
|
||||
}
|
||||
//参数校验
|
||||
if (arguments.length < 2) throw new Error('请检查函数配置参数,最少传递两个必填参数');
|
||||
if (!Array.isArray(options)) throw new Error('参数2必须为Array');
|
||||
//获取对象的key
|
||||
let dataKeys = Object.keys(data);
|
||||
//开始通过 options 校验
|
||||
options.forEach(item => {
|
||||
//判断是否有该字段
|
||||
if (typeof data[item.field] !== 'undefined') {
|
||||
//校验数据类型
|
||||
if (!checkData.typeFn(data[item.field], item.type)) {
|
||||
//类型校验失败
|
||||
checkData.correctFn(item);
|
||||
}
|
||||
} else {
|
||||
console.log(`%c ${item.field} ← 错误值,请检查源数据中该字段`, 'font-size:50px;color:red');
|
||||
checkData.correctFn(item);
|
||||
}
|
||||
})
|
||||
},
|
||||
//表单校验
|
||||
checkFn(obj, whiteList, configure = {}) {
|
||||
//校验状态 con
|
||||
let con = {
|
||||
result: true,
|
||||
field: '',
|
||||
WrongText: '',
|
||||
errCheckField: ''
|
||||
}
|
||||
//校验参数
|
||||
if (arguments.length < 1) throw new Error('请检查函数配置参数,最少传递1个必填参数');
|
||||
if (obj.constructor.toString().indexOf('Object') == -1) throw new Error('参数1必须为Object');
|
||||
if (whiteList && !Array.isArray(whiteList)) throw new Error('参数2必须为Array');
|
||||
let configurationTable = Object.keys(configure)
|
||||
// console.log(configurationTable, obj, '需要校验的字段数组')
|
||||
// 循环需要校验的对象
|
||||
Object.keys(obj).forEach(keys => {
|
||||
// console.log(keys, '当前循环的校验对象')
|
||||
//如果循环的当前字段在白名单内跳过
|
||||
// console.log(whiteList, '白名单')
|
||||
if (whiteList.includes(keys)) return
|
||||
//校验状态改变跳过
|
||||
// console.log(con.result, '校验状态')
|
||||
if (!con.result) return
|
||||
if (configurationTable.includes(keys)) {
|
||||
//当前需要匹配的字段 obj[keys] configure[keys]
|
||||
//循环配置参数 拿到校验配置
|
||||
// console.log('key:', keys, '源对象:', obj[keys], '校验配置', configure[keys], '匹配到的需要校验的数据')
|
||||
Object.keys(configure[keys]).forEach(pages => {
|
||||
if (!con.result) return
|
||||
// console.log('字段:', keys, '开始校验', pages, )
|
||||
// configure[keys][pages]
|
||||
switch (pages) {
|
||||
case 'type':
|
||||
con.result = typeof obj[keys] == configure[keys][pages]
|
||||
if (!con.result) {
|
||||
con.field = keys
|
||||
con.WrongText = configure[keys].WrongText ? configure[keys].WrongText :
|
||||
'字段:' + con.field + '校验出错'
|
||||
con.errCheckField = pages
|
||||
}
|
||||
break;
|
||||
case 'length':
|
||||
con.result = obj[keys].toString().length == configure[keys][pages]
|
||||
if (!con.result) {
|
||||
con.field = keys
|
||||
con.WrongText = configure[keys].WrongText ? configure[keys].WrongText :
|
||||
'字段:' + con.field + '校验出错'
|
||||
con.errCheckField = pages
|
||||
}
|
||||
break;
|
||||
case 'minLength':
|
||||
con.result = obj[keys].toString().length >= configure[keys][pages]
|
||||
if (!con.result) {
|
||||
con.field = keys
|
||||
con.WrongText = configure[keys].WrongText ? configure[keys].WrongText :
|
||||
'字段:' + con.field + '校验出错'
|
||||
con.errCheckField = pages
|
||||
}
|
||||
break;
|
||||
case 'maxLength':
|
||||
con.result = obj[keys].toString().length <= configure[keys][pages]
|
||||
if (!con.result) {
|
||||
con.field = keys
|
||||
con.WrongText = configure[keys].WrongText ? configure[keys].WrongText :
|
||||
'字段:' + con.field + '校验出错'
|
||||
con.errCheckField = pages
|
||||
}
|
||||
break;
|
||||
case 'custom':
|
||||
con.result = configure[keys][pages].test(obj[keys])
|
||||
if (!con.result) {
|
||||
con.field = keys
|
||||
con.WrongText = configure[keys].WrongText ? configure[keys].WrongText :
|
||||
'字段:' + con.field + '校验出错'
|
||||
con.errCheckField = pages
|
||||
}
|
||||
// console.log('自定义类型校验', configure[keys][pages], '值', obj[keys])
|
||||
break;
|
||||
case 'tacitly':
|
||||
con.result = Boolean(obj[keys])
|
||||
if (!con.result) {
|
||||
con.field = keys
|
||||
con.WrongText = configure[keys].WrongText ? configure[keys].WrongText :
|
||||
'字段:' + con.field + ',' + pages + '校验出错'
|
||||
con.errCheckField = pages
|
||||
}
|
||||
// console.log('自定义类型校验', configure[keys][pages], '值', obj[keys])
|
||||
break;
|
||||
default:
|
||||
// console.log(pages, '其他')
|
||||
break;
|
||||
}
|
||||
})
|
||||
}
|
||||
});
|
||||
// console.log(con, '校验结果')
|
||||
return con
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user