20260929
This commit is contained in:
+292
@@ -0,0 +1,292 @@
|
||||
import {getLocation, getUserInfo, setLocation} from "@/util/user";
|
||||
import {API, MAIN_API} from "@/config";
|
||||
import {get} from "@/api/request";
|
||||
import {areaInfoByNameReq, areaInfoReq} from "@/api/common";
|
||||
import dayjs from "dayjs";
|
||||
import md5 from "md5";
|
||||
|
||||
export const ORDER_STATUS_LIST = ['已取消', '进行中', '已完成', '申请退款中', '退款完成', '退款失败']
|
||||
|
||||
export const CHECK_STATUS_LIST = [
|
||||
{
|
||||
label: '审核中',
|
||||
color: 'info'
|
||||
},
|
||||
{
|
||||
label: '审核通过',
|
||||
color: 'success'
|
||||
},
|
||||
{
|
||||
label: '审核拒绝',
|
||||
color: 'error'
|
||||
},
|
||||
{
|
||||
label: '已到账',
|
||||
color: 'success'
|
||||
},
|
||||
|
||||
]
|
||||
|
||||
export const chooseImg = (limit = 1, sourceType = ['album', 'camera']) => {
|
||||
return new Promise(resolveMain => {
|
||||
uni.chooseImage({
|
||||
count: limit,
|
||||
sourceType,
|
||||
extension: ['png', 'jpg', 'jpeg'],
|
||||
sizeType: ['original'],
|
||||
success: async ({tempFiles}) => {
|
||||
const result = await Promise.all(tempFiles.map(async file => {
|
||||
const uploadRes = await uploadFileToAliOss(file.path)
|
||||
return {
|
||||
path: uploadRes,
|
||||
}
|
||||
}))
|
||||
resolveMain(result)
|
||||
},
|
||||
complete: () => {
|
||||
uni.hideLoading()
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
let ossUploadSeed = 0
|
||||
|
||||
const createOssKey = (filePath) => {
|
||||
ossUploadSeed += 1
|
||||
const suffix = filePath.substring(filePath.lastIndexOf("."));
|
||||
const hash = md5(`${filePath}_${Date.now()}_${ossUploadSeed}_${Math.random()}`)
|
||||
return `${dayjs().format('YYYYMMDD')}/${hash}${suffix}`
|
||||
}
|
||||
|
||||
export const uploadImg = filePath => {
|
||||
const {token} = getUserInfo()
|
||||
uni.showLoading({title: '上传中'})
|
||||
return new Promise(async resolve => {
|
||||
// uni.uploadFile({
|
||||
// url: `${MAIN_API}/api/file/upload`,
|
||||
// name: 'file',
|
||||
// filePath,
|
||||
// header: {
|
||||
// Authorization: token,
|
||||
// TenantId: 10325
|
||||
// },
|
||||
// formData: {
|
||||
// type: 'header'
|
||||
// },
|
||||
// success: uploadRes => {
|
||||
// uni.hideLoading()
|
||||
// const {data: {url}} = JSON.parse(uploadRes.data)
|
||||
// resolve({
|
||||
// path: url,
|
||||
// })
|
||||
// }
|
||||
// })
|
||||
const uploadRes = await uploadFileToAliOss(filePath)
|
||||
uni.hideLoading()
|
||||
resolve({
|
||||
path: uploadRes,
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
const getSts = () => get('/oss/getSTSToken')
|
||||
|
||||
export const uploadFileToAliOss = async (filePath) => {
|
||||
const stsRes = await getSts()
|
||||
const sts = stsRes.data
|
||||
const key = createOssKey(filePath)
|
||||
const url = 'https://yaodongxiao.oss-cn-guangzhou.aliyuncs.com';
|
||||
return new Promise(resolve => {
|
||||
uni.uploadFile({
|
||||
url,
|
||||
name: 'file',
|
||||
filePath,
|
||||
formData: {
|
||||
key,
|
||||
OSSAccessKeyId: sts.accessKeyId,
|
||||
signature: sts.signature,
|
||||
security_token: sts.token,
|
||||
policy: sts.policy,
|
||||
},
|
||||
success: () => {
|
||||
resolve(`${url}/${key}`)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
export const getLocationAction = (save = true) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const res = getLocation()
|
||||
if (res.area_id) resolve(res)
|
||||
else {
|
||||
uni.authorize({
|
||||
scope: 'scope.userLocation',
|
||||
success: () => {
|
||||
uni.getLocation({
|
||||
isHighAccuracy: true,
|
||||
success: async ({longitude, latitude}) => {
|
||||
const {result} = await get(`https://api.tianditu.gov.cn/geocoder?postStr={'lon':${longitude},'lat':${latitude},'ver':1}&type=geocode&tk=1099ec280e86f4e9b632173326cde90b`)
|
||||
const areaRes = await areaInfoByNameReq({name: result.addressComponent.county}).catch(() => {
|
||||
if (!this.areaId) reject(false)
|
||||
})
|
||||
if (save) setLocation({
|
||||
longitude,
|
||||
latitude,
|
||||
province_str: result.addressComponent.province,
|
||||
city_str: result.addressComponent.city,
|
||||
area_str: result.addressComponent.county,
|
||||
area_id: areaRes.data.id,
|
||||
city_id: areaRes.data.fid,
|
||||
province_id: areaRes.data.city.fid
|
||||
})
|
||||
resolve({
|
||||
longitude,
|
||||
latitude,
|
||||
area_id: areaRes.data.id,
|
||||
city_id: areaRes.data.fid,
|
||||
province_id: areaRes.data.city.fid,
|
||||
province_str: result.addressComponent.province,
|
||||
city_str: result.addressComponent.city,
|
||||
area_str: result.addressComponent.county,
|
||||
})
|
||||
},
|
||||
fail: () => {
|
||||
reject(false)
|
||||
}
|
||||
})
|
||||
},
|
||||
fail: () => {
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '为了更好的提供服务,请开启定位服务',
|
||||
success: ({confirm}) => {
|
||||
if (confirm) uni.openSetting()
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export const chooseVideo = (sourceType = ['album', 'camera']) => {
|
||||
return new Promise((resolveMain, reject) => {
|
||||
uni.chooseVideo({
|
||||
sourceType,
|
||||
compressed: true,
|
||||
maxDuration: 60,
|
||||
success: async ({tempFilePath, duration, size}) => {
|
||||
if (duration > 180) {
|
||||
uni.showToast({
|
||||
title: '暂时不支持3分钟以上的视频',
|
||||
icon: 'none'
|
||||
})
|
||||
return reject(false)
|
||||
}
|
||||
// 50M限制
|
||||
if (size > 50 * 1024 * 1024) {
|
||||
uni.showToast({
|
||||
title: '暂时不支持50M以上的视频',
|
||||
icon: 'none'
|
||||
})
|
||||
return reject(false)
|
||||
}
|
||||
const {token} = getUserInfo()
|
||||
uni.showLoading({title: '上传中...'})
|
||||
// uni.uploadFile({
|
||||
// url: `${MAIN_API}/api/file/upload`,
|
||||
// name: 'file',
|
||||
// filePath: tempFilePath,
|
||||
// header: {
|
||||
// Authorization: token,
|
||||
// TenantId: 10325
|
||||
// },
|
||||
// success: uploadRes => {
|
||||
// const {data} = JSON.parse(uploadRes.data)
|
||||
// uni.hideLoading()
|
||||
// resolveMain({
|
||||
// path: data.url,
|
||||
// })
|
||||
// }
|
||||
// })
|
||||
const uploadRes = await uploadFileToAliOss(tempFilePath)
|
||||
resolveMain({
|
||||
path: uploadRes,
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
export const getLocationOnly = () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.authorize({
|
||||
scope: 'scope.userLocation',
|
||||
success: () => {
|
||||
uni.getLocation({
|
||||
isHighAccuracy: true,
|
||||
success: async ({longitude, latitude}) => {
|
||||
const {result} = await get(`https://api.tianditu.gov.cn/geocoder?postStr={'lon':${longitude},'lat':${latitude},'ver':1}&type=geocode&tk=1099ec280e86f4e9b632173326cde90b`)
|
||||
const {data} = await areaInfoByNameReq({name: result.addressComponent.county}).catch(() => {
|
||||
if (!this.areaId) reject(false)
|
||||
})
|
||||
resolve({
|
||||
longitude,
|
||||
latitude,
|
||||
area_id: data.id,
|
||||
city_id: data.fid,
|
||||
province_id: data.city.fid,
|
||||
province_str: result.addressComponent.province,
|
||||
city_str: result.addressComponent.city,
|
||||
area_str: result.addressComponent.county,
|
||||
full: result.formatted_address
|
||||
})
|
||||
},
|
||||
fail: () => {
|
||||
uni.setStorageSync("no_more_realtime_location", 1)
|
||||
reject(false)
|
||||
}
|
||||
})
|
||||
},
|
||||
fail: err => {
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '为了更好的提供服务,请开启定位服务',
|
||||
success: ({confirm}) => {
|
||||
if (confirm) uni.openSetting()
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
export const getExpressMode = () => parseInt(uni.getStorageSync("express_mode"))
|
||||
|
||||
export const calcDistanceMeters = (lat1, lng1, lat2, lng2) => {
|
||||
const nLat1 = Number(lat1)
|
||||
const nLng1 = Number(lng1)
|
||||
const nLat2 = Number(lat2)
|
||||
const nLng2 = Number(lng2)
|
||||
if (![nLat1, nLng1, nLat2, nLng2].every(Number.isFinite)) return NaN
|
||||
const rad = value => value * Math.PI / 180
|
||||
const r = 6371000
|
||||
const dLat = rad(nLat2 - nLat1)
|
||||
const dLng = rad(nLng2 - nLng1)
|
||||
const a = Math.sin(dLat / 2) * Math.sin(dLat / 2)
|
||||
+ Math.cos(rad(nLat1)) * Math.cos(rad(nLat2))
|
||||
* Math.sin(dLng / 2) * Math.sin(dLng / 2)
|
||||
const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a))
|
||||
return r * c
|
||||
}
|
||||
|
||||
export const formatDistance = meters => {
|
||||
if (!Number.isFinite(meters)) return ''
|
||||
if (meters < 1000) return `${Math.round(meters)}m`
|
||||
const km = (meters / 1000).toFixed(1).replace(/\.0$/, '')
|
||||
return `${km}km`
|
||||
}
|
||||
+100
@@ -0,0 +1,100 @@
|
||||
import {BLUE, BLUE_LIGHT, GREEN, ORANGE, RED} from "@/config/color";
|
||||
|
||||
// -1已取消、0待付款、1待发货/配送中、2待收货、3已完成、4退款中、5退款成功、6退款失败
|
||||
|
||||
export const ORDER_STATUS_LIST = [
|
||||
{
|
||||
label: '已取消',
|
||||
value: -1,
|
||||
color: '#BBB',
|
||||
},
|
||||
{
|
||||
label: '待付款',
|
||||
value: 0,
|
||||
color: RED,
|
||||
},
|
||||
{
|
||||
label: '配送中',
|
||||
value: 1,
|
||||
color: BLUE_LIGHT,
|
||||
},
|
||||
{
|
||||
label: '待收货',
|
||||
value: 2,
|
||||
color: BLUE,
|
||||
},
|
||||
{
|
||||
label: '已完成',
|
||||
value: 3,
|
||||
color: GREEN,
|
||||
},
|
||||
{
|
||||
label: '退款中',
|
||||
value: 4,
|
||||
color: '#F9A8D4',
|
||||
},
|
||||
{
|
||||
label: '退款成功',
|
||||
value: 5,
|
||||
color: '#DB2777',
|
||||
},
|
||||
{
|
||||
label: '退款失败',
|
||||
value: 6,
|
||||
color: '#831843',
|
||||
},
|
||||
]
|
||||
|
||||
export const EXPRESS_ORDER_STATUS_LIST = [
|
||||
{
|
||||
label: '已取消',
|
||||
value: -1,
|
||||
color: '#BBB',
|
||||
},
|
||||
{
|
||||
label: '待支付',
|
||||
value: 0,
|
||||
color: RED,
|
||||
},
|
||||
{
|
||||
label: '待接单',
|
||||
value: 1,
|
||||
color: BLUE_LIGHT,
|
||||
},
|
||||
{
|
||||
label: '配送中',
|
||||
value: 2,
|
||||
color: BLUE,
|
||||
},
|
||||
{
|
||||
label: '待确认',
|
||||
value: 20,
|
||||
color: BLUE,
|
||||
},
|
||||
{
|
||||
label: '已完成',
|
||||
value: 3,
|
||||
color: GREEN,
|
||||
},
|
||||
{
|
||||
label: '退款中',
|
||||
value: 4,
|
||||
color: '#F9A8D4',
|
||||
},
|
||||
{
|
||||
label: '退款成功',
|
||||
value: 5,
|
||||
color: '#DB2777',
|
||||
},
|
||||
{
|
||||
label: '退款失败',
|
||||
value: 6,
|
||||
color: '#831843',
|
||||
},
|
||||
]
|
||||
|
||||
export const getOrderStatusItem = (type, orderStatus) => {
|
||||
if ([1, 2, 3, 4, 5].includes(type))
|
||||
return EXPRESS_ORDER_STATUS_LIST.filter(item => item.value === orderStatus)[0]
|
||||
else return ORDER_STATUS_LIST.filter(item => item.value === orderStatus)[0]
|
||||
}
|
||||
+129
@@ -0,0 +1,129 @@
|
||||
import {MAIN_API} from "@/config";
|
||||
|
||||
const SHARE_USER_ID_KEY = "share_user_id"
|
||||
|
||||
const normalizeStorageValue = (value) => {
|
||||
if (value === undefined || value === null) return ""
|
||||
const text = String(value).trim()
|
||||
if (!text || text === "undefined" || text === "null") return ""
|
||||
return text
|
||||
}
|
||||
|
||||
const parsePathQuery = (path = "") => {
|
||||
const [pathname = "", queryString = ""] = String(path).split("?")
|
||||
const query = {}
|
||||
if (!queryString) return {pathname, query}
|
||||
queryString.split("&").forEach(segment => {
|
||||
if (!segment) return
|
||||
const [rawKey = "", rawValue = ""] = segment.split("=")
|
||||
const key = decodeURIComponent(rawKey)
|
||||
if (!key) return
|
||||
query[key] = decodeURIComponent(rawValue)
|
||||
})
|
||||
return {pathname, query}
|
||||
}
|
||||
|
||||
const buildPathQuery = (pathname = "", query = {}) => {
|
||||
const queryString = Object.keys(query)
|
||||
.filter(key => normalizeStorageValue(key) && normalizeStorageValue(query[key]) !== "")
|
||||
.map(key => `${encodeURIComponent(key)}=${encodeURIComponent(query[key])}`)
|
||||
.join("&")
|
||||
return queryString ? `${pathname}?${queryString}` : pathname
|
||||
}
|
||||
|
||||
export const setLocation = ({latitude, longitude, province_str, city_str, area_str, area_id, city_id, province_id}) => {
|
||||
if (latitude) uni.setStorageSync("latitude", latitude)
|
||||
if (longitude) uni.setStorageSync("longitude", longitude)
|
||||
uni.setStorageSync("province_str", province_str)
|
||||
uni.setStorageSync("city_str", city_str)
|
||||
uni.setStorageSync("area_str", area_str)
|
||||
uni.setStorageSync("area_id", area_id)
|
||||
uni.setStorageSync("city_id", city_id)
|
||||
uni.setStorageSync("province_id", province_id)
|
||||
}
|
||||
|
||||
export const getLocation = () => {
|
||||
return {
|
||||
latitude: uni.getStorageSync("latitude"),
|
||||
longitude: uni.getStorageSync("longitude"),
|
||||
province_str: uni.getStorageSync("province_str"),
|
||||
city_str: uni.getStorageSync("city_str"),
|
||||
area_str: uni.getStorageSync("area_str"),
|
||||
area_id: uni.getStorageSync("area_id"),
|
||||
city_id: uni.getStorageSync("city_id"),
|
||||
province_id: uni.getStorageSync("province_id")
|
||||
}
|
||||
}
|
||||
|
||||
export const setUserInfo = (user) => {
|
||||
if (user.uid) uni.setStorageSync("uid", user.uid)
|
||||
if (user.username) uni.setStorageSync("username", user.username)
|
||||
if (user.token) uni.setStorageSync("token", user.token)
|
||||
if (user.header) uni.setStorageSync("header", `${MAIN_API}${user.header}`)
|
||||
if (user.phone) uni.setStorageSync("phone", user.phone)
|
||||
}
|
||||
|
||||
export const getUserInfo = () => {
|
||||
return {
|
||||
uid: uni.getStorageSync("uid"),
|
||||
username: uni.getStorageSync("username"),
|
||||
token: uni.getStorageSync("token"),
|
||||
header: uni.getStorageSync("header"),
|
||||
phone: uni.getStorageSync("phone"),
|
||||
}
|
||||
}
|
||||
|
||||
export const clearUserInfo = () => {
|
||||
uni.removeStorageSync("uid");
|
||||
uni.removeStorageSync("username");
|
||||
uni.removeStorageSync("token");
|
||||
uni.removeStorageSync("header");
|
||||
uni.removeStorageSync("phone");
|
||||
}
|
||||
|
||||
export const getShareUserId = () => normalizeStorageValue(uni.getStorageSync(SHARE_USER_ID_KEY))
|
||||
|
||||
export const setShareUserId = (userId) => {
|
||||
const value = normalizeStorageValue(userId)
|
||||
if (!value) return ""
|
||||
uni.setStorageSync(SHARE_USER_ID_KEY, value)
|
||||
return value
|
||||
}
|
||||
|
||||
export const clearShareUserId = () => {
|
||||
uni.removeStorageSync(SHARE_USER_ID_KEY)
|
||||
}
|
||||
|
||||
export const saveShareUserIdFromQuery = (query = {}) => {
|
||||
const shareUserId = normalizeStorageValue(
|
||||
query.shareUserId ?? query.inviterUserId ?? query.userId ?? query.uid
|
||||
)
|
||||
if (!shareUserId) return ""
|
||||
const currentUserId = normalizeStorageValue(uni.getStorageSync("uid"))
|
||||
if (currentUserId && currentUserId === shareUserId) return ""
|
||||
return setShareUserId(shareUserId)
|
||||
}
|
||||
|
||||
export const appendPathParams = (path = "", params = {}) => {
|
||||
const {pathname, query} = parsePathQuery(path)
|
||||
Object.keys(params).forEach(key => {
|
||||
const value = normalizeStorageValue(params[key])
|
||||
if (value === "") return
|
||||
query[key] = value
|
||||
})
|
||||
return buildPathQuery(pathname, query)
|
||||
}
|
||||
|
||||
export const getCurrentPagePath = () => {
|
||||
const pages = typeof getCurrentPages === "function" ? getCurrentPages() : []
|
||||
const currentPage = pages[pages.length - 1]
|
||||
if (!currentPage || !currentPage.route) return ""
|
||||
return appendPathParams(`/${currentPage.route}`, currentPage.options || {})
|
||||
}
|
||||
|
||||
export const buildSharePath = (path = "") => {
|
||||
const shareUserId = normalizeStorageValue(uni.getStorageSync("uid"))
|
||||
const targetPath = normalizeStorageValue(path) || getCurrentPagePath()
|
||||
if (!targetPath || !shareUserId) return targetPath
|
||||
return appendPathParams(targetPath, {shareUserId})
|
||||
}
|
||||
Reference in New Issue
Block a user