This commit is contained in:
2023-08-11 10:45:20 +08:00
commit 161ca982f3
31850 changed files with 2706500 additions and 0 deletions

59
src/utils/appointTime.js Normal file
View File

@ -0,0 +1,59 @@
import { formatDate, formatNumber } from '@/utils/common'
// 拼接 预约时间 picker
export function getAppointFun (time) {
let arr = []
// 当天剩余时间段
let obj = getCurrentDatePicker(time)
arr.push(obj)
// 后六天的可选时间段
let tempArr = getAfterTimeList()
arr.push(...tempArr)
return arr
}
// 拼接 当天剩余的可预约时间段(默认第一个是两小时之后可选)
const getCurrentDatePicker = time => {
let obj = {}
obj.text = formatDate(time);
let timeArr = getCurrentTimeList()
obj.children = timeArr
return obj
}
// 当天日期的时间段
const getCurrentTimeList = () => {
let todayDate = new Date()
let tempArr = []
tempArr.push({ text: '尽快到' }); // 首先添加尽快到
if( todayDate.getMinutes() <= 30 && todayDate.getMinutes() > 0 ) {
let tempVal = todayDate.getHours() + 2;
let tempHalfHours = formatNumber(tempVal) + ':30';
tempArr.push({ text: tempHalfHours });
}
let startFlag = (todayDate.getMinutes() == 0) ? (todayDate.getHours() + 2) : (todayDate.getHours() + 3)
tempArr = getDateTimeList(startFlag, tempArr)
return tempArr
}
// 获取后六天的 预约时间 picker
const getAfterTimeList = () => {
let afterArr = []
for(let i = 1; i < 7; i++ ) {
let obj = {};
let tempTime = formatDate(new Date().getTime() + (i * 24* 60 * 60 * 1000))
obj.text = tempTime
let timeArr = []
obj.children = getDateTimeList(0, timeArr)
afterArr.push(obj)
}
return afterArr
}
// 获取某个时间段后的所有可选时段
const getDateTimeList = (startHours = 0, list) => {
for(let i = startHours; i < 24; i++ ) {
list.push({ text: formatNumber(i) + ':' + '00' })
list.push({ text: formatNumber(i) + ':' + '30' })
}
return list
}

30
src/utils/common.js Normal file
View File

@ -0,0 +1,30 @@
const formatDate = date => {
let tempDate = new Date(date)
const year = tempDate.getFullYear()
const month = tempDate.getMonth() + 1
const day = tempDate.getDate()
return `${[year, month, day].map(formatNumber).join('-')}`
}
const formatNumber = n => {
n = n.toString()
return n[1] ? n : `0${n}`
}
const leftCopy = (obj, source) => {
let sourceKey = Object.keys(source)
if (obj && source) {
Object.keys(obj).forEach(key => {
if (sourceKey.includes(key)) {
obj[key] = source[key] == null ? '' : source[key]
}
})
}
}
module.exports = {
formatNumber,
formatDate,
leftCopy,
}

54
src/utils/http.js Normal file
View File

@ -0,0 +1,54 @@
import axios from "axios";
import qs from 'qs'
import { Toast } from 'vant'
console.log('process.env.VUE_APP_BASE_API', process.env.VUE_APP_BASE_API)
const service = axios.create({
// baseURL: process.env.VUE_APP_BASE_API,
baseURL: 'https://api1.sino-assist.com/',
headers: {
Accept: 'application/json'
},
timeout: 10000
})
service.interceptors.request.use(
config => {
config.data = config.contentType ? config.data : qs.stringify(config.data)
config.headers['Content-Type'] = config.contentType || 'application/x-www-form-urlencoded'
// 在发送请求之前做一些操作如添加token到请求头
const token='eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJzemwiLCJhdWQiOlsic3VwcGxpZXItYXBwIl0sIm5iZiI6MTY5MTU1NzIzNSwidXNlcl9pbmZvIjp7InVzZXJJZCI6NTQ1ODUsInBob25lIjoiMTc2MzAwMzU2NTgiLCJuYW1lIjoi5bCP5a6LIiwic3VwcGxpZXJOYW1lIjoi5LiK5rW35a6J55WFQSIsInN1cHBsaWVySWQiOjExMjgsInVzZXJuYW1lIjoic3psIiwidXNlclR5cGUiOiJBUFAiLCJhdXRob3JpdGllcyI6W119LCJzY29wZSI6WyJhbGwiXSwiaXNzIjoiaHR0cHM6Ly9zaW5vYXNzaXN0LmNvbSIsImV4cCI6MTY5MTY0MzYzNSwiaWF0IjoxNjkxNTU3MjM1fQ.S1AignpcnCxSrm3M8rzhCLYlgyqD2Hv-SPMqPLgqlt4'
config.headers['Authorization'] = `${token}`;
/* if (getToken()) {
config.headers['token'] = getToken()
}*/
return config
},
error => {
console.log(error)
return Promise.reject(error)
}
)
service.interceptors.response.use(
response => {
const res = response.data
console.log('rere', res)
if (res.code && (res.code != '00' && res.code != '105' )) {
Toast(res.msg || 'Error')
return Promise.reject(new Error(res.msg || 'Error'))
} else {
if( res.code === 0 ) {
return res.result
} else {
return res.data
}
}
},
error => {
console.log('err' + error)
Toast(error.message)
return Promise.reject(error)
}
)
export default service

108
src/utils/map.js Normal file
View File

@ -0,0 +1,108 @@
// 获取定位, 返回 经纬度
export function getLocal(mapContext) {
return new Promise((resolve, reject) => {
mapContext.plugin('AMap.Geolocation', function () {
let geolocation = new AMap.Geolocation({
enableHighAccuracy: true, // 是否使用高精度定位默认true
timeout: 10000, // 设置定位超时时间,默认:无穷大
offset: [10, 20], // 定位按钮的停靠位置的偏移量
zoomToAccuracy: true, // 定位成功后调整地图视野范围使定位位置及精度范围视野内可见默认false
position: 'RB' // 定位按钮的排放位置, RB表示右下
})
geolocation.getCurrentPosition(function(status, result){
if(status == 'complete'){
resolve(result.position)
}else{
reject(result)
}
});
})
})
}
// 逆地址解析,根据经纬度获取详细地址
export function getAddress(mapContext, lnglat) {
return new Promise((resolve, reject) => {
mapContext.plugin('AMap.Geocoder', function () {
let geocoder = new AMap.Geocoder({
// city: "010", //城市设为北京,默认:“全国”
});
geocoder.getAddress(lnglat, function(status, result) {
if (status === 'complete' && result.info === 'OK') {
// result为对应的地理位置详细信息
resolve(result)
} else {
console.log(result)
alert(JSON.stringify(result))
}
})
})
})
}
// 输入提示
export function searchFun(mapContext, cityCode, keyword) {
return new Promise((resolve, reject) => {
mapContext.plugin('AMap.AutoComplete', function(){
var autoOptions = {
city: cityCode || '全国',
};
// 实例化AutoComplete
var autoComplete= new AMap.AutoComplete(autoOptions);
// 根据关键字进行搜索
autoComplete.search(keyword, function(status, result) {
// 搜索成功时result即是对应的匹配数据
if(result.info == 'OK') {
resolve(result.tips)
} else {
reject(result)
}
})
})
})
}
// 路径规划
export function getRoad( mapContext, startLng, startLat, endLng, endLat ) {
return new Promise((resolve, reject) => {
mapContext.plugin('AMap.Driving', function() {
let driving = new AMap.Driving({
// 驾车路线规划策略AMap.DrivingPolicy.LEAST_TIME是最快捷模式
// policy: AMap.DrivingPolicy.LEAST_TIME,
// map: mapContext
})
let startLngLat = [startLng, startLat]
let endLngLat = [endLng, endLat]
driving.search(startLngLat, endLngLat, function (status, result) {
// 未出错时result即是对应的路线规划方案
if (status === 'complete') {
resolve(result)
} else {
reject(result)
}
})
})
})
}
function drawRoute(route, map) {
let path = parseRouteToPath(route)
let routeLine = new AMap.Polyline({
path: path,
isOutline: true,
outlineColor: '#ffeeee',
borderWeight: 2,
strokeWeight: 5,
strokeOpacity: 0.9,
strokeColor: '#0091ff',
lineJoin: 'round'
})
map.add(routeLine);
}

27
src/utils/myMixins.js Normal file
View File

@ -0,0 +1,27 @@
export const myMixins = {
data() {
return {
touchStart: [],
touchEnd: [],
slideShow: true
}
},
methods: {
goPage(page, query) {
this.$router.push({
name: page,
query: query
})
},
copyText(){//复制订单编号
const copyText = document.getElementById('copyText');
const range = document.createRange();
range.selectNode(copyText);
window.getSelection().removeAllRanges(); // 清除当前页面的选择内容
window.getSelection().addRange(range);
document.execCommand('copy');
window.getSelection().removeAllRanges(); // 清除选择内容的高亮状态
this.$toast('复制成功')
}
}
}

14
src/utils/rem.js Normal file
View File

@ -0,0 +1,14 @@
const baseSize = 37.5 //跟postcss.config.js中rootValue的值是一致的
// 设置 rem 函数
function setRem () {
// 当前页面宽度相对于 375 宽的缩放比例,可根据自己需要修改。 vantUI使用的是375px页面宽这里使用375px
const scale = document.documentElement.clientWidth / 375
// 设置页面根节点字体大小 最高为两倍图 即设计稿为750
document.documentElement.style.fontSize = (baseSize * Math.min(scale, 2)) + 'px'
}
// 初始化
setRem()
// 改变窗口大小时重新设置 rem
window.onresize = function () {
setRem()
}