源文件

This commit is contained in:
gyq
2024-05-23 14:39:33 +08:00
commit a1128dd791
2997 changed files with 500069 additions and 0 deletions

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,23 @@
export function doubleToThousands(amount) {
if(!amount) {
return
}
let numList = amount.toString().split('.')
let num = (numList[0] || 0).toString(), result = '';
while (num.length > 3) {
result = ',' + num.slice(-3) + result;
num = num.slice(0, num.length - 3);
}
if (num) { result = num + result; }
if(numList[1]) {
return result + '.' + numList[1]
}
if(amount.endsWith('.')) {
return result + '.'
}
return result
}

View File

@@ -0,0 +1,17 @@
console.log(window.location,'windowlocationwindowlocation')
console.log(window.location.pathname.split('/pages/hub/'),'46541651651651615')
let pathname = window.location.pathname.split('/pages/hub/').slice(-1)[0]
let pathnameList = pathname.split("/")
let pathnameString = window.location.pathname
console.log(pathnameList[1],'pathnameString')
if (pathnameList.length >= 2) {
let parameterToRemove = pathnameList[1]
pathnameString = pathnameString.replace(parameterToRemove, "");
}
console.log(pathnameString,'pathnameStringpathnameString')
// 支持多服务商码牌地址
if(/^\/cashier\/(.+)\/pages\/hub\/(default|h5|lite)\/$/.test(pathname)){
console.log(pathnameList,'windowlocationwindowlocation')
window.location.href= '/cashier/pages/hub/' + pathnameList[0] + window.location.search
}

View File

@@ -0,0 +1,131 @@
import appConfig from '@/config/appConfig.js'
import {toErrPageFunc} from '@/util/toErrorPageUtil.js'
export function setToken(toPageParams){
console.log(toPageParams,'toPageParamstoPageParamstoPageParams')
let env = ''
if(toPageParams){
env = toPageParams.env ? toPageParams.env : '';
}
console.log(env,'toPageParamstoPageParamstoPageParams')
if(env == ''){
uni.setStorageSync('payH5','') // 改变存储
}
// 参数token
let token = toPageParams ? toPageParams[appConfig.tokenKey] : '';
// 参数中包含token 赋值到配置中
if(token){
appConfig.tokenValue = token;
// #ifdef H5
window.sessionStorage.setItem(appConfig.tokenKey, token) // 放置到sessionStorage 刷新浏览器不会消失,关闭浏览器会消失
// #endif
}
// token不存在
if(!appConfig.tokenValue){
return toErrPageFunc('获取二维码参数失败,请通过扫描收款二维码进入小程序支付!');
}
//放置 pageType
setPageType()
}
export function setPageType(){
let currentPageType = ''
// #ifdef H5
const userAgent = navigator.userAgent;
if(userAgent.indexOf("MicroMessenger") >= 0){
currentPageType = appConfig.PAGE_TYPE_ENUM.WECHAT_H5
}
else if(userAgent.indexOf("AlipayClient") >= 0){
currentPageType = appConfig.PAGE_TYPE_ENUM.ALIPAY_H5
}
else if(userAgent.indexOf("UnionPay") >= 0 || userAgent.indexOf("unionpay") >= 0){
currentPageType = appConfig.PAGE_TYPE_ENUM.YSFPAY_H5
}
else{
appConfig.currentPageType = appConfig.PAGE_TYPE_ENUM.OTHER_H5
uni.reLaunch({
url: '/pages/index/index'
})
return
}
// #endif
// #ifdef MP-WEIXIN
currentPageType = appConfig.PAGE_TYPE_ENUM.WECHAT_LITE
// #endif
// #ifdef MP-ALIPAY
currentPageType = appConfig.PAGE_TYPE_ENUM.ALIPAY_LITE
// #endif
if(!currentPageType){
return toErrPageFunc('当前应用不支持!');
}
appConfig.currentPageType = currentPageType;
}
// 根据小程序规则获取并设置token
export function setLiteToken(url = '') {
// token对象
const tokenObject = {}
if (url) {
// 截取协议名 + 域名 + 端口号
if(url.startsWith('http://')) {
let sUrl = url.substring(7)
appConfig.env.JEEPAY_PAY_BASE_URL = "http://" + sUrl.substring(0, sUrl.indexOf('/'))
}else if(url.startsWith('https://')) {
let sUrl = url.substring(8)
appConfig.env.JEEPAY_PAY_BASE_URL = "https://" + sUrl.substring(0, sUrl.indexOf('/'))
}else{
toErrPageFunc('二维码协议头错误')
}
// 截取token
const query = url.substring(url.indexOf('?') +1)
const vars = query.split("&")
for (var i=0; i<vars.length; i++) {
const pair = vars[i].split("=")
if(pair[0] == appConfig.tokenKey){
tokenObject[appConfig.tokenKey] = pair[1]
setToken(tokenObject)
return
}
}
}
// else {
// appConfig.env.JEEPAY_PAY_BASE_URL = 'https://pay.s.jeepay.vip'
// tokenObject[appConfig.tokenKey] = 'f86f221f580ef6945206a7a48d0cb05cf450b43f10edfe5603998cd48791a074'
// setToken(tokenObject)
// return
// }
return toErrPageFunc('获取二维码参数失败,请通过扫描收款二维码进入小程序支付!');
}
//同步取出ext.json对象
export function getExtStoreId(){
try{
const extConfig = uni.getExtConfigSync()
if(extConfig.domain){
appConfig.env.JEEPAY_BASE_URL = extConfig.domain
}
// uni.showToast({title: JSON.stringify(extConfig),icon:"none",duration:3000});
console.log(extConfig,'extJson对象');
return extConfig;
}catch(err){
console.log(err,'getExtStoreId__error')
}
}

View File

@@ -0,0 +1,70 @@
import { $getIsMemberPower } from '@/http/apiManager.js'
import appConfig from '@/config/appConfig.js'
// 计算 应该跳转的页面
export function navigateTo (channelUserId) {
appConfig.channelUserId = channelUserId
$getIsMemberPower().then((res) => {
console.log('查询是否开启会员==>', res.bizData);
// appConfig.redPacketIsOpen = res.bizData.redPacketIsOpen
// appConfig.redbalance = res.bizData.balance
// appConfig.redbalance = (1000 / 100).toFixed(2)
if (!res.bizData.memberIsOpen) {
// 跳转到输入金额 页面;
const payH5 = uni.getStorageSync('payH5') // 改变存储
if(payH5 && (appConfig.currentPageType == 'wechatH5' || appConfig.currentPageType == 'alipayH5')){
const info = JSON.parse(payH5)
if(info.env == "scan"){
uni.redirectTo({ url: '/pages/payment/index?tk='+info.tk+'&price='+info.price+'&order_no='+info.order_no+'&env='+info.env });
}else if(info.env == 'route'){
// uni.showToast({title: payH5,icon:'none',duration:3000})
uni.redirectTo({ url: '/pages/route/index?tk='+info.tk+'&env='+info.env });
}else{
uni.redirectTo({ url: '/pages/payway/index' });
}
}else{
uni.redirectTo({ url: '/pages/payway/index' });
}
} else {
appConfig.memberBaseUrl = res.bizData.memberSiteUrl
uni.redirectTo({
url: '/pageMember/payMember/payMember'
})
}
})
}
// 计算主题色
export function calcThemeColor (key = 'color') {
const colorObj = {
wechatLite: {
color: '#35d757',
bgColor: '#52cc701a',
imgUrl: '/static/payIcon/wechat.svg'
},
alipayLite: {
color: '#108ee9',
BgColor: '#3476fe1a',
imgUrl: '/static/payIcon/zfb.svg'
},
wechatH5: {
color: '#35d757',
bgColor: '#52cc701a',
imgUrl: '/static/payIcon/wechat.svg'
},
alipayH5: {
color: '#108ee9',
bgColor: '#3476fe1a',
imgUrl: '/static/payIcon/zfb.svg'
},
ysfpayH5: {
color: '#FF4433',
bgColor: '#ff44331a',
imgUrl: '/static/payIcon/ysf.svg'
},
otherH5: {
color: '#3D5D99',
bgColor: '#334e801a',
imgUrl: '/static/payIcon/UnionPay.svg'
}
}
return colorObj[appConfig.currentPageType][key]
}

View File

@@ -0,0 +1,43 @@
/**
* uniapp 页面跳转通用函数(将参数自动转换)
* @author terrfly
* @site https://www.jeequan.com
* @date 2021/12/17 18:49
*/
let result = {
convertCondition: (params) =>{
if(!params){
return '';
}
let result = '';
Object.keys(params).forEach(function(key){
result += key + '=' + encodeURIComponent(params[key]) + '&'
});
return result.substring(0, result.length - 1)
},
// 跳转页面
to: (page, params) => {
uni.navigateTo({
url: params ? page + '?' + result.convertCondition(params) : page
})
},
// 关闭当前页面并跳转页面
redirectTo: (page, params) => {
uni.redirectTo({
url: params ? page + '?' + result.convertCondition(params) : page
})
},
}
export default result

View File

@@ -0,0 +1,33 @@
/**
* 存储管理对象
* 目标:将现有系统的所有需要存储的数据,统一管理
*
* @author terrfly
* @site https://www.jeequan.com
* @date 2022/04/13 07:18
*/
const model = {
// 渠道用户ID
channelUserId: (key, channelUserId) => {
if (channelUserId) {
uni.setStorageSync(key, channelUserId) // 改变存储
}
return uni.getStorageSync(key)
},
iToken: (iToken) => {
if (iToken) {
uni.setStorageSync('iToken', iToken) // 改变存储
}
return uni.getStorageSync('iToken')
},
channelUniId:(key,channelUniId)=>{
if (channelUniId) {
uni.setStorageSync(key, channelUniId) // 改变存储
}
return uni.getStorageSync(key)
}
}
export default model

View File

@@ -0,0 +1,7 @@
export function toErrPageFunc(errInfo){
uni.navigateTo({url: '/pages/error/index?errInfo=' + errInfo});
}

View File

@@ -0,0 +1,266 @@
// 格式化日期格式为 xxxx-xx-xx
function getFullDate(targetDate) {
var nowDate = new Date()
var fullYear = nowDate.getFullYear();
var month = nowDate.getMonth() + 1 // getMonth 方法返回 0-11代表1-12月
var D, y, m, d
if (targetDate) {
D = new Date(targetDate)
y = D.getFullYear()
m = D.getMonth() + 1
d = D.getDate()
} else { // 不传参数 则获取今天的日期
y = fullYear
m = month
d = new Date()
d = d.getDate()
}
m = m > 9 ? m : '0' + m
d = d > 9 ? d : '0' + d
return y + '-' + m + '-' + d
}
/* 将时间戳格式化为yyyy-MM-dd hh:mm:ss格式其它格式可自行更改 */
function formatTimeMills(timeMills, sign) {
var date = new Date(timeMills);
var timeStr = date.getFullYear() + sign;
if (date.getMonth() < 9) { // 月份从0开始的
timeStr += '0';
}
timeStr += date.getMonth() + 1 + sign;
timeStr += date.getDate() < 10 ? ('0' + date.getDate()) : date.getDate();
timeStr += ' ';
timeStr += date.getHours() < 10 ? ('0' + date.getHours()) : date.getHours();
timeStr += ':';
timeStr += date.getMinutes() < 10 ? ('0' + date.getMinutes()) : date.getMinutes();
timeStr += ':';
timeStr += date.getSeconds() < 10 ? ('0' + date.getSeconds()) : date.getSeconds();
return timeStr;
}
// 获取当月的第一天
function getCurrentMonthFirst() {
let date = new Date();
let year = date.getFullYear();
let month = date.getMonth() + 1;
let day = "01";
month = month < 10 ? "0" + month : month;
return year + "-" + month + "-" + day;
}
// 获取本月的最后一天
function getCurrentMonthLast() {
var date = new Date();
var currentMonth = date.getMonth();
var nextMonth = ++currentMonth;
var nextMonthFirstDay = new Date(date.getFullYear(), nextMonth, 1);
var oneDay = 1000 * 60 * 60 * 24;
var lastTime = new Date(nextMonthFirstDay - oneDay);
var month = parseInt(lastTime.getMonth() + 1);
var day = lastTime.getDate();
if (month < 10) {
month = '0' + month;
}
if (day < 10) {
day = '0' + day;
}
return date.getFullYear() + '-' + month + '-' + day;
}
// 获取一年后的今天
function getOneYearLater() {
var date = new Date();
var year = date.getFullYear() + 1; // 减一是算去年时间,+ 1 是明年时间
var month = date.getMonth() + 1;
var day = date.getDate();
if (month < 10) {
month = '0' + month;
}
if (day < 10) {
day = '0' + day;
}
var dateStr = year + "-" + month + "-" + day;
return dateStr;
}
let num = (a) => {
if (a != null && a.toString() != "") {
let r = /^-?(0|[1-9]+\d*|[1-9]+\d*\.\d+|0\.\d+)$/;
if (r.test(a.toString())) {
return true;
}
}
return false;
}
//除法
function division(a, b) {
if (!num(a) || !num(b)) {
return null;
}
let c, d, f, g;
try {
c = a.toString().split(".")[1].length;
} catch (e) {
c = 0;
}
try {
d = b.toString().split(".")[1].length;
} catch (e) {
d = 0;
}
f = Number(a.toString().replace(".", ""));
g = Number(b.toString().replace(".", ""));
return parseFloat(((f / g) * Math.pow(10, d - c)).toFixed(2))
}
// 获取n天后的日期
function getNdaysLater(n) {
var nowDate = new Date();
let nDaysLaterDate = this.getFullDate(nowDate.getTime() + 24 * 60 * 60 * 1000 * n); //获取明天日期
return nDaysLaterDate;
}
// 去除日期中的点或-
function removeDateStr(dateStr, sign, num) {
let date = '';
if (num == 0) {
if (sign == '.') {
date = dateStr.replace(/\./g, '');
} else if (sign == '-') {
date = dateStr.replace(/\-/g, '');
}
} else if (num == 1) {
if (sign == '.') {
date = dateStr.replace(/\./g, '-');
} else if (sign == '-') {
date = dateStr.replace(/\-/g, '.');
}
}
return date;
}
// 金额格式化
function amountFormatting(amount, sign) {
let changeAmount = 0;
let resultAmount = 0;
if (sign == 0) {
changeAmount = division(amount, 100);
resultAmount = changeAmount.toFixed(2).replace(/\d{1,3}(?=(\d{3})+(\.\d*)?$)/g, '$&,');
} else if (sign == 1) {
resultAmount = amount.toFixed(0).replace(/\d{1,3}(?=(\d{3})+(\.\d*)?$)/g, '$&,');
}
return resultAmount;
}
// 字符串转日期格式
function stringToDate(Date, sign) {
let newStr = '';
let resultStr = '';
if (sign == '-') {
newStr = Date.substring(0, 4) + "-" + Date.substring(4);
resultStr = newStr.substring(0, 7) + "-" + newStr.substring(7);
} else if (sign == '.') {
newStr = Date.substring(0, 4) + "." + Date.substring(4);
resultStr = newStr.substring(0, 7) + "." + newStr.substring(7);
}
return resultStr;
}
// 获取今天的零点/最后一刻
function getTodayStartOrEnd(sign) {
let resultTime = '';
if (sign == 'start') {
resultTime = new Date(new Date(new Date().toLocaleDateString()).getTime());
} else if (sign == 'end') {
resultTime = new Date(new Date(new Date().toLocaleDateString()).getTime() + 24 * 60 * 60 * 1000 - 1);
}
return formatTimeMills(resultTime, '-');
}
// 判断门店对象是否为空
let storeObject = null;
function getStore() {
if (!storeObject) {
storeObject = uni.getStorageSync('storeObject')
}
return storeObject;
}
function setStore(store) {
storeObject = store;
uni.setStorageSync('storeObject', storeObject);
}
// 获取今天
function getToday(symbol = '') {
var taday = new Date()
var tdyear = taday.getFullYear().toString()
var tdmonth = taday.getMonth() + 1
var tdstrDate = taday.getDate()
if (tdmonth >= 1 && tdmonth <= 9) tdmonth = "0" + tdmonth
if (tdstrDate >= 0 && tdstrDate <= 9) tdstrDate = "0" + tdstrDate
return tdyear + symbol + tdmonth.toString() + symbol + tdstrDate
}
// 获取以今天为准的前后多少天的时间
function getOtherToday(num, symbol = '') {
var taday = new Date()
var date = new Date(taday.setDate(taday.getDate() + num))
let year = date.getFullYear().toString()
let month = (date.getMonth() + 1).toString()
let day = date.getDate().toString()
if (month.length < 2) month = '0' + month
if (day.length < 2) day = '0' + day
return year + symbol + month + symbol + day
}
// 获取设备号
let deviceNo = null;
function getDeviceNo() {
// #ifndef H5
if (!deviceNo) {
deviceNo = uni.getStorageSync('deviceNo')
}
return deviceNo;
// #endif
// #ifdef H5
return '82365aa3f9700ad4'
// #endif
}
function setDeviceNo(device) {
deviceNo = device;
uni.setStorageSync('deviceNo', deviceNo);
}
// 获取baseUrl
let baseUrl = '';
function getBaseUrl() {
if (!baseUrl) {
baseUrl = uni.getStorageSync('baseUrl', baseUrl);
}
return baseUrl;
}
function setBaseUrl(passBaseUrl) {
baseUrl = passBaseUrl;
uni.setStorageSync('baseUrl', baseUrl);
}
exports default {
getFullDate,
getCurrentMonthLast,
getOneYearLater,
getNdaysLater,
removeDateStr,
amountFormatting,
stringToDate,
getTodayStartOrEnd,
getStore,
setStore,
getCurrentMonthFirst,
formatTimeMills,
getToday,
getOtherToday,
getDeviceNo,
setDeviceNo,
getBaseUrl,
setBaseUrl
}