123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581 |
- import * as config from '../config'
- var sdkwx = uni.requireNativePlugin('Hdgq-LocSdkWX');
- const rolesList = []
- const gjList=[]
- const ossUploadUrl = 'https://taohaoliang.oss-cn-beijing.aliyuncs.com/';
- const chooseImage = {
- count: '1',
- sizeType: ['original', 'compressed'],
- sourceType: ['album'],
- }
- const imgType = '请选择图片来源'
- const imgTypeList = [{
- name: '相册',
- },
- {
- name: '拍照',
- }
- ]
- //定位sdk授权
- const sdkAuth = function(){
- var enterpriseSenderCode = config.def().enterpriseSenderCode
- var environment = config.def().environment
- var appId = ''
- var appSecurity = ''
- let phoneType = uni.getSystemInfoSync().platform //判断手机类型
- if (phoneType == "android") {
- appId = config.def().androidAppId
- appSecurity = config.def().androidAppSecurity
- } else if (phoneType == "ios") {
- appId = config.def().iosAppId
- appSecurity = config.def().iosAppSecurity
- }
- console.log("appid:" + appId + "安全码:" + appSecurity + "发送代码:" + enterpriseSenderCode)
- sdkwx.auth(appId, appSecurity, enterpriseSenderCode, environment, function(res) {
- if (res.type == "onSuccess") {
- //成功
-
- console.log("授权成功")
- console.log(res)
- } else if (res.type == "onFailure") {
- //失败
- var errorCode = res.data.errorCode; //错误码
- var errorMsg = res.data.errorMsg; //错误描述
- console.log("授权失败")
- console.log(res)
- }
- });
- }
- //定位sdk开启
- const sdkStart = function(carNo,driverName,remark,shippingNoteInfos){
- sdkwx.start(carNo, driverName, remark, shippingNoteInfos,
- function(res) {
- if (res.type == "onSuccess") {
- //成功
- console.log("开启定位成功!!!")
- console.log(res)
- var shippingNoteInfos = res.data[0]; //运单信息列表
- console.log(shippingNoteInfos, "sdassss")
- if (shippingNoteInfos) {
- let dateTtime = Number(shippingNoteInfos.interval + 1000)
- console.log("开始定时", dateTtime)
- // that.send()
- }
- } else if (res.type == "onFailure") {
- //失败
- console.log("开启定位失败!!!")
- console.log(res)
- var errorCode = res.data.errorCode; //错误码
- var errorMsg = res.data.errorMsg; //错误描述
- setTimeout(() => {
- console.log("定时")
- // that.send()
- }, 915204);
- }
- });
- }
- // 当前日期是否超过今天(校验有效期)
- const periodOfValidity=function(year1,month1,day1){
- let nowDate = new Date();
- let year = nowDate.getFullYear()
- let month = nowDate.getMonth() + 1
- let day = nowDate.getDate()
- if(year1<year){
- return false
- }
- if(year1==year&&month1<month){
- return false
- }
- if(year1==year&&month1==month&&day1<=day){
- return false
- }
- return true
- }
- const makeValidityPeriod = function(type,yearnum) {
- console.log(yearnum)
- //获取当前年
- let nowDate = new Date();
- let year = nowDate.getFullYear()
- let _list = []
- let _list1 = []
- // let _list2 = ["一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"]
- let _list2 = ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"]
- let _list3 = ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14",
- "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30",
- "31"
- ]
- let _ValidityPeriod = []
- if(yearnum){
- var len=year-Number(yearnum)
- var len2=30+len
- for (let i = 0; i < len2; i++) {
- _list1.push(yearnum + i)
- }
- }else{
- for (let i = 0; i < 30; i++) {
- _list1.push(year + i)
- }
- }
-
- if (type == 0) {
- _list1.unshift('长期')
- _list2.unshift('')
- _list3.unshift('')
- }
- _list.push(_list1, _list2, _list3)
- return _list
- }
- const fUN_AmapLocation = uni.requireNativePlugin('FUN-AmapLocation');
- const getListByUserId = function() {
- let baseUrlNew = config.def().baseUrlNew
- var userInfo = uni.getStorageSync("userInfo")
- console.log("------", userInfo)
- if (userInfo) {
- uni.request({
- url: baseUrlNew + '/roleMenu/query/getListByUserId',
- data: {
- userId: userInfo.id ? userInfo.id : userInfo.data.id
- },
- method: 'GET',
- success: (res) => {
- if (res.statusCode === 200) {
- uni.setStorageSync("jurisdiction", res.data.data)
- let list = getUserAllRoles(res.data.data);
- uni.setStorageSync("rolesList", list)
- }
- }
- })
- }
- }
- const getUserAllRoles = (item) => {
- console.log(item)
- for (let i = 0; i < item.length; i++) {
- rolesList.push(item[i].name)
- // console.log('用户权限',rolesList)
- if (item[i].children && item[i].children.length > 0) {
- getUserAllRoles(item[i].children)
- }
- }
- return rolesList;
- }
- const setAudit = (item) => {
- let _list = uni.getStorageSync("copyTaskInfo")
- let _isShowbtn = true
- if (_list.length == 0) {
- _isShowbtn = false
- }
- for (let i = 0; i < _list.length; i++) {
- if (_list[i].businessId == item.id) {
- _list.splice(i, 1)
- uni.setStorageSync("copyTaskInfo", _list)
- }
- }
- if (_list.length > 0) {
- uni.navigateTo({
- url: _list[0].itemUrl + '&isShowbtn=' + _isShowbtn,
- })
- }
- console.log(item)
- }
- const contactCustomerService = (phone) => {
- console.log(phone)
- //客服
- if (!phone) {
- phone = '4006688647'
- }
- const res = uni.getSystemInfoSync();
- // ios系统默认有个模态框
- if(res.platform=='ios'){
- uni.makePhoneCall({
- phoneNumber:phone,
- success(){
- console.log('拨打成功了');
- },
- fail() {
- console.log('拨打失败了');
- }
- })
- }else{
- //安卓手机手动设置一个showActionSheet
- uni.showActionSheet({
- itemList: [phone,'呼叫'],
- success:function(res){
- console.log(res);
- if(res.tapIndex==1){
- uni.makePhoneCall({
- phoneNumber: phone,
- success: (res) => {
- console.log('调用成功!')
-
- },
-
- // 失败回调
- fail: (res) => {
- console.log('调用失败!')
- // contactCustomerService(item)
- }
- })
- }
- }
- })
- }
- // console.log("联系客服")
- // uni.makePhoneCall({
- // phoneNumber: item,
- // success: (res) => {
- // console.log('调用成功!')
- // },
- // // 失败回调
- // fail: (res) => {
- // console.log('调用失败!')
- // contactCustomerService(item)
- // }
- // });
- }
- // 获取市、区简称
- const filterUrban = (s) => {
- if (s.lastIndexOf('市') != -1) {
- return s.substring(0, s.length - 1)
- }
- return s
- }
- const filterArea = (q) => {
- if (q.lastIndexOf('区') != -1) {
- return q.substring(0, q.length - 1)
- }
- return q
- }
- // 根据当前时间获取本周一到本周日日期
- function getDates() {
- // var new_Date = new Date(t2)
- var new_Date = new Date()
- var timesStamp = new_Date.getTime()
- var currenDay = new_Date.getDay()
- var dates = []
- for (var i = 0; i < 7; i++) {
- dates.push(new Date(timesStamp + 24 * 60 * 60 * 1000 * (i - (currenDay + 6) % 7)).toLocaleDateString().replace(
- /[年月]/g, '-').replace(/[日上下午]/g, ''));
- }
- var weekStar = new Date(dates[0] + ' 00:00:00').getTime()
- var weekEnd = new Date(dates[dates.length - 1] + ' 23:59:59').getTime()
- var week = [weekStar, weekEnd]
- return week
- }
- //判断是否是今天,昨天,明天
- function isToday(str,type) {
- //type == 0 判断是否是今天,type == 1 判断是否是昨天,type == 2 判断是否是明天
- if (type == 0){
- if (new Date(str).toDateString() === new Date().toDateString()) {
- // console.log('今天');
- return true
- } else{
- // console.log('不是今天');
- return false
- }
- }if (type == 1) {
- if (new Date(str).toDateString() === new Date(new Date().getTime() -1000 * 60 * 60 * 24).toDateString()) {
- // console.log('昨天');
- return true
- } else{
- // console.log('不是昨天');
- return false
- }
- }
- if (type == 2) {
- if (new Date(str).toDateString() === new Date(new Date().getTime() +1000 * 60 * 60 * 24).toDateString()) {
- // console.log('明天');
- return true
- } else{
- // console.log('不是明天');
- return false
- }
- }
- }
- const changeTime = (t1) => {
- // console.log(t1)
- // t1截止时间 t2当前时间
- // 调用getDtes函数把当前时间传过去,获取本周一和本周日时间戳
- // var weeks = getDates(t2)
- var weeks = getDates()
- // console.log(weeks)
- var dateBegin = new Date(t1.replace(/-/g,'/'))//解决ios时new Date(2021-04-17 09:50:20)报错
- // var dateEnd = new Date(t2)
- var dateEnd = new Date()
- // 时间戳
- var end = dateBegin.getTime()
- // console.log(end)
- var nows = dateEnd.getTime()
- // console.log(nows)
- // 获取当天0点时间戳todayStar
- const start = new Date(new Date(dateEnd).toLocaleDateString())
- start.setTime(start.getTime())
- var todayStar = new Date(start).getTime()
- // console.log(todayStar)
- // 获取当天23点59分59秒时间戳todayEnd
- var ends = new Date(new Date(new Date(dateEnd).toLocaleDateString()).getTime() + 24 * 60 * 60 * 1000 - 1)
- var todayEnd = new Date(ends).getTime()
- // console.log(todayEnd)
- // 时间差的毫秒数
- var dateDiff = Math.abs(dateBegin.getTime() - dateEnd.getTime())
- // 计算出相差天数
- var dayDiff = Math.floor(dateDiff / (24 * 3600 * 1000))
- // console.log(dayDiff);
- // 计算天数后剩余的毫秒数
- var leave1 = dateDiff % (24 * 3600 * 1000)
- // 计算出小时数
- var hours = Math.floor(leave1 / (3600 * 1000))
- // console.log(hours);
- // 计算相差分钟数
- var leave2 = leave1 % (3600 * 1000) // 计算小时数后剩余的毫秒数
- // 计算相差分钟数
- var minutes = Math.floor(leave2 / (60 * 1000))
- // console.log(minutes);
- // t1截止时间 t2当前时间
-
- if (dateEnd < dateBegin) {
- if ((dayDiff === 0)) {
- if (hours === 0) {
- if (minutes < 30 || minutes == 30) {
- return minutes + '分钟后'
- }else{
- return '今天' + t1.substring(10, 16)
- }
- } else {
- if (isToday(end,0)) {
- return '今天' + t1.substring(10, 16)
- }else{
- return '明天' + t1.substring(10, 16)
- }
- }
- } else if (dayDiff === 1) {
- if (isToday(end,2)){
- return '明天' + t1.substring(10, 16)
- }else{
- if ((weeks[0] < end || weeks[0] == end) && (weeks[1] > end || weeks[1] == end)) {
- var weekArray = new Array('日', '一', '二', '三', '四', '五', '六')
- var week = weekArray[new Date(t1.replace(/-/g,'/')).getDay()] // 注意此处必须是先new一个Date
- return '周' + week + t1.substring(10, 16)
- } else {
- return t1.substring(0, 16).replace(/-/g, '/')
- }
- }
- } else {
- if ((weeks[0] < end || weeks[0] == end) && (weeks[1] > end || weeks[1] == end)) {
- var weekArray = new Array('日', '一', '二', '三', '四', '五', '六')
- var week = weekArray[new Date(t1.replace(/-/g,'/')).getDay()] // 注意此处必须是先new一个Date
- return '周' + week + t1.substring(10, 16)
- } else {
- return t1.substring(0, 16).replace(/-/g, '/')
- }
- }
- }
- if (dateEnd === dateBegin) {
- return '刚刚'
- }
- if (dateEnd > dateBegin) {
- if (dayDiff === 0) {
- if (hours === 0) {
- if (minutes < 60 || minutes == 60) {
- if (minutes < 5 || minutes == 5) {
- return '刚刚'
- } else {
- return minutes + '分钟前'
- }
- } else {
- return '今天' + t1.substring(10, 16)
- }
- } else {
- if (isToday(end,0)) {
- return hours+'小时前'
- }else{
-
- return '昨天' + t1.substring(10, 16)
- }
- }
- } else if (dayDiff === 1) {
- if (isToday(end,1)){
- // return '昨天' + t1.substring(10, 16)
- return dayDiff + '天前'
- }else{
- if ((weeks[0] < end || weeks[0] == end) && (weeks[1] > end || weeks[1] == end)) {
- var weekArray = new Array('日', '一', '二', '三', '四', '五', '六')
- var week = weekArray[new Date(t1.replace(/-/g,'/')).getDay()] // 注意此处必须是先new一个Date
- return '周' + week + t1.substring(10, 16)
- } else {
- return t1.substring(0, 16).replace(/-/g, '/')
- }
- }
- }else if (dayDiff < 30){
- // return dayDiff +'天前'+ t1.substring(10, 16)
- return dayDiff +'天前'
-
- }else if (dayDiff > 30 && dayDiff < 365){
- return t1.substring(5, 10)
-
- }else if (dayDiff > 365){
-
- return t1.substring(0, 4)
-
- }else {
- if ((weeks[0] < end || weeks[0] == end) && (weeks[1] > end || weeks[1] == end)) {
- var weekArray = new Array('日', '一', '二', '三', '四', '五', '六')
- var week = weekArray[new Date(t1.replace(/-/g,'/')).getDay()] // 注意此处必须是先new一个Date
- return '周' + week + t1.substring(10, 16)
- } else {
- return t1.substring(0, 16).replace(/-/g, '/')
- }
- }
- }
- }
- const formatLocation = (str) => {
- let area = {}
- let index11 = 0
- let index1 = str.indexOf("省")
- if (index1 == -1) {
- index11 = str.indexOf("自治区")
- if (index11 != -1) {
- area.Province = str.substring(0, index11 + 3)
- } else {
- area.Province = str.substring(0, 0)
- }
- } else {
- area.Province = str.substring(0, index1 + 1)
- }
- let index2 = str.indexOf("市")
- if (index11 == -1) {
- area.City = str.substring(index11 + 1, index2 + 1)
- } else {
- if (index11 == 0) {
- area.City = str.substring(index1 + 1, index2 + 1)
- } else {
- area.City = str.substring(index11 + 3, index2 + 1)
- }
- }
- let index3 = str.indexOf("区")
- if (index3 == -1) {
- index3 = str.indexOf("县")
- if (index3 == -1) {
- index3 = str.lastIndexOf("市")
- if (index3 == -1) {
- index3 = str.indexOf("镇")
- if (index3 == -1) {
- } else {
- area.Country = str.substring(index2 + 1, index3 + 1)
- }
- } else {
- area.Country = str.substring(index2 + 1, index3 + 1)
- }
- } else {
- area.Country = str.substring(index2 + 1, index3 + 1)
- }
- } else {
- area.Country = str.substring(index2 + 1, index3 + 1)
- }
- area.Village = str.substring(index3 + 1, str.length)
- return area;
- }
- //获取省份简称
- const getProvinceAbbreviation = (province) => {
- if (province == "北京市" || province == "北京")
- return "京";
- else if (province == "天津市" || province == "天津")
- return "津";
- else if (province == "重庆市" || province == "重庆")
- return "渝";
- else if (province == "上海市" || province == "上海")
- return "沪";
- else if (province == "河北省" || province == "河北")
- return "冀";
- else if (province == "山西省" || province == "山西")
- return "晋";
- else if (province == "辽宁省" || province == "辽宁")
- return "辽";
- else if (province == "吉林省" || province == "吉林")
- return "吉";
- else if (province == "黑龙江省" || province == "黑龙江")
- return "黑";
- else if (province == "江苏省" || province == "江苏")
- return "苏";
- else if (province == "浙江省" || province == "浙江")
- return "浙";
- else if (province == "安徽省" || province == "安徽")
- return "皖";
- else if (province == "福建省" || province == "福建")
- return "闽";
- else if (province == "江西省" || province == "江西")
- return "赣";
- else if (province == "山东省" || province == "山东")
- return "鲁";
- else if (province == "河南省" || province == "河南")
- return "豫";
- else if (province == "湖北省" || province == "湖北")
- return "鄂";
- else if (province == "湖南省" || province == "湖南")
- return "湘";
- else if (province == "广东省" || province == "广东")
- return "粤";
- else if (province == "海南省" || province == "海南")
- return "琼";
- else if (province == "四川省" || province == "四川")
- return "川";
- else if (province == "贵州省" || province == "贵州")
- return "贵";
- else if (province == "云南省" || province == "云南")
- return "云";
- else if (province == "陕西省" || province == "陕西")
- return "陕";
- else if (province == "甘肃省" || province == "甘肃")
- return "甘";
- else if (province == "青海省" || province == "青海")
- return "青";
- else if (province == "台湾省" || province == "台湾")
- return "台";
- else if (province == "内蒙古自治区" || province == "内蒙古")
- return "蒙";
- else if (province == "广西壮族自治区" || province == "广西")
- return "桂";
- else if (province == "宁夏回族自治区" || province == "宁夏")
- return "宁";
- else if (province == "新疆维吾尔自治区" || province == "新疆")
- return "新";
- else if (province == "西藏自治区" || province == "西藏")
- return "藏";
- else if (province == "香港特别行政区" || province == "香港")
- return "港";
- else if (province == "澳门特别行政区" || province == "澳门")
- return "澳";
- }
- export default {
- getListByUserId,
- setAudit,
- ossUploadUrl,
- contactCustomerService,
- chooseImage,
- imgType,
- imgTypeList,
- makeValidityPeriod,
- periodOfValidity,
- sdkAuth,
- getProvinceAbbreviation,
- formatLocation,
- filterUrban,
- filterArea,
- sdkStart,
- fUN_AmapLocation,
- changeTime,
- gjList
- }
|