This commit is contained in:
2023-08-12 22:15:27 +08:00
commit c46b07d1da
421 changed files with 46336 additions and 0 deletions

10
src/jtools/api/index.js Normal file
View File

@@ -0,0 +1,10 @@
import request from '../request/index.js';
export function getAliCompanyInfo(data) {
return request({
url: 'alipay/findAliCompanyInfo',
method: 'POST',
data,
noToken: true
});
}

10
src/jtools/api/login.js Normal file
View File

@@ -0,0 +1,10 @@
import request from '../request/index.js';
export function login(data) {
return request({
url: 'api-admin/pcLogin',
method: 'POST',
data,
noToken: true
});
}

View File

@@ -0,0 +1,11 @@
// 请求状态码
const RESPONSE_TYPE = {
SUCCESS: '0000',
RELOGIN: 'E403',
ERROR: '4000'
};
export default {
RESPONSE_TYPE,
};

View File

@@ -0,0 +1,5 @@
import common from './common.js'
export default {
...common
}

View File

@@ -0,0 +1,75 @@
/**
* Platform v1.0.0
* @Class Platform
* @description jtools-platform 1.0.0 全平台兼容
* @Author lidongtony
* @Date 2021-04-07
* @Email lidongtony@qq.com
*/
// #ifdef H5
// 微信H5
import wxsdk from '@/jtools/wechat/sdk';
// #endif
export default {
// 获取当前运行平台
get() {
let platform = '';
// #ifdef H5
wxsdk.isWechat() ? (platform = 'wxOfficialAccount') : (platform = 'H5');
// #endif
// #ifdef APP-PLUS
platform = 'App';
// #endif
// #ifdef MP-WEIXIN
platform = 'wxMiniProgram';
// #endif
// #ifdef MP-ALIPAY
platform = 'alipayMiniProgram';
// #endif
if (platform !== '') {
uni.setStorageSync('platform', platform);
} else {
uni.showToast({
title: '暂不支持该平台',
icon: 'none'
});
}
return platform;
},
set(platform) {
uni.setStorageSync('platform', platform);
return platform;
},
// 检测当前运行机型
device() {
return uni.getSystemInfoSync().platform;
},
// 获取前端真实主机
host() {
let host = location.origin;
let basePath = router.$route.options.base;
let mode = router.$route.options.mode;
host += basePath;
if (mode === 'hash') {
host += '#/';
}
return host;
},
// 处理wechat jssdk 签名网址(针对IOS微信浏览器做优化)
entry() {
let that = this;
var entryUrl = location.href;
if (this.device() === 'ios') {
if (typeof location.entryUrl !== 'undefined') {
entryUrl = location.entryUrl;
} else {
location.entryUrl = entryUrl;
}
}
return entryUrl;
}
};

View File

@@ -0,0 +1,47 @@
import storage from '../storage/index.js';
//把配置项单独处理
let server_url = ' '; // 请求地址
let token = ' '; // 凭证
server_url = import.meta.env.VITE_APP_BASE_API; //环境配置
function service(options = {}) {
storage.get('token') && (token = storage.get('token'));
options.url = `${server_url}${options.url}`;
if (!options.noToken) {
if (!token.trim()) {
uni.redirectTo({
url: '/pages/login/login'
});
} else {
options.header = {
Authorization: `Bearer ${token}`
};
}
}
return new Promise((resolved, rejected) => {
//成功
options.success = res => {
if (res.data.code == 'E403') {
// 未登录
uni.showToast({
title: res.data.message,
icon: 'none'
});
uni.redirectTo({
url: '/pages/login/login'
});
//请求成功
resolved(res.data);
} else {
//请求成功
resolved(res.data);
}
};
//错误
options.fail = err => {
rejected(err); //错误
};
uni.request(options);
});
}
export default service;

View File

@@ -0,0 +1,40 @@
const APP_NAME = import.meta.env.VITE_APP_TITLE
export default {
set(key, value) {
// 命名规则 小程序名称-环境
const storageName = `${APP_NAME}-${process.env.NODE_ENV}`
const temp = uni.getStorageSync(storageName) || {}
temp[key] = value
uni.setStorageSync(storageName, temp)
},
get(key) {
// 命名规则 小程序名称-环境
const storageName = `${APP_NAME}-${process.env.NODE_ENV}`
const temp = uni.getStorageSync(storageName) || {}
if(temp.hasOwnProperty(key)) {
return temp[key]
} else {
return undefined
}
},
remove(key) {
// 命名规则 小程序名称-环境
const storageName = `${APP_NAME}-${process.env.NODE_ENV}`
const temp = uni.getStorageSync(storageName) || {}
if(temp.hasOwnProperty(key)) {
delete temp[key];
uni.setStorageSync(storageName, temp);
}
},
has(key) {
// 命名规则 小程序名称-环境
const storageName = `${APP_NAME}-${process.env.NODE_ENV}`
const temp = uni.getStorageSync(storageName) || {}
return temp.hasOwnProperty(key)
},
clear() {
// 命名规则 小程序名称-环境
const storageName = `${APP_NAME}-${process.env.NODE_ENV}`
uni.removeStorageSync(storageName)
}
}

18
src/jtools/store/index.js Normal file
View File

@@ -0,0 +1,18 @@
import { createPinia } from 'pinia';
// 自动注入所有pinia模块
const files = import.meta.globEager('./*.js');
const modules = {};
Object.keys(files).forEach((key) => {
modules[key.replace(/(.*\/)*([^.]+).*/gi, '$2')] = files[key].default;
});
export const setupPinia = (app) => {
const pinia = createPinia();
app.use(pinia);
};
export default (name) => {
return modules[name]();
};

68
src/jtools/store/user.js Normal file
View File

@@ -0,0 +1,68 @@
import { defineStore } from 'pinia';
import http from '@/jtools/request/index';
import constants from '@/jtools/constants';
import storage from '@/jtools/storage';
const user = defineStore({
id: 'user',
state: () => ({
token: storage.get('token'),
isLogin: storage.get('isLogin'), // 是否登陆
userInfo: storage.get('userInfo'), // 用户信息
}),
actions: {
// 登录
showAuth() {
// router.replaceAll('/pages/login/login');
},
// 获取个人信息
async getInfo() {
const { error, data } = await userApi.profile();
if (error !== 0) return;
this.userInfo = data;
return Promise.resolve(data);
},
// 设置token
setToken(token = '') {
if (token === '') {
this.isLogin = false;
this.token = ''
this.userInfo = {}
storage.set('token', '');
storage.set('isLogin', false);
storage.set('userInfo', {});
} else {
this.isLogin = true;
this.token = token
storage.set('token', token);
storage.set('isLogin', true);
}
return this.isLogin;
},
// 重置用户默认数据
resetUserData() {
this.setToken();
},
// 登出
async logout(force = false) {
if (!force) {
const { error } = await userApi.logout();
if (error === 0) {
this.resetUserData();
}
}
if (force) {
this.resetUserData();
}
return !this.isLogin;
},
},
});
export default user;

View File

@@ -0,0 +1,31 @@
let timer;
let flag;
/**
* 节流原理:在一定时间内,只能触发一次
*
* @param {Function} func 要执行的回调函数
* @param {Number} wait 延时的时间
* @param {Boolean} immediate 是否立即执行
* @return null
*/
function throttle(func, wait = 500, immediate = true) {
if (immediate) {
if (!flag) {
flag = true;
// 如果是立即执行则在wait毫秒内开始时执行
typeof func === 'function' && func();
timer = setTimeout(() => {
flag = false;
}, wait);
} else {
}
} else if (!flag) {
flag = true;
// 如果是非立即执行则在wait毫秒内的结束处执行
timer = setTimeout(() => {
flag = false;
typeof func === 'function' && func();
}, wait);
}
}
export default throttle;

170
src/jtools/wechat/sdk.js Normal file
View File

@@ -0,0 +1,170 @@
var jweixin = require("jweixin-module");
import http from "@/jtools/request/index";
import $platform from "@/jtools/platform";
export default {
//判断是否在微信中
isWechat() {
var ua = window.navigator.userAgent.toLowerCase();
if (ua.match(/micromessenger/i) == "micromessenger") {
return true;
} else {
return false;
}
},
// 鉴权页面
initJssdk(callback) {
http("common.wxJssdk", {
uri: encodeURIComponent($platform.entry())
}).then(res => {
jweixin.config({
debug: res.data.debug,
appId: res.data.appId,
timestamp: res.data.timestamp,
nonceStr: res.data.nonceStr,
signature: res.data.signature,
jsApiList: res.data.jsApiList,
openTagList: res.data.openTagList
});
if (callback) {
callback(res.data);
}
});
},
//在需要定位页面调用
getLocation(callback) {
this.isWechat() && this.initJssdk(function(res) {
jweixin.ready(function() {
jweixin.getLocation({
type: "gcj02", // 默认为wgs84的gps坐标如果要返回直接给openLocation用的火星坐标可传入'gcj02'
success: function(res) {
callback(res);
},
fail: function(res) {
console.log("%c微信H5sdk,getLocation失败",
"color:green;background:yellow");
},
});
});
});
},
//获取微信收货地址
openAddress(callback) {
this.isWechat() && this.initJssdk(function(res) {
jweixin.ready(function() {
jweixin.openAddress({
success: function(res) {
callback(res);
},
fail: function(err) {
console.log("%c微信H5sdk,openAddress失败",
"color:green;background:yellow");
},
complete: function(msg) {}
});
});
});
},
// 微信扫码
scanQRCode(callback) {
this.isWechat() && this.initJssdk(function(res) {
jweixin.ready(function() {
jweixin.scanQRCode({
needResult: 1, // 默认为0扫描结果由微信处理1则直接返回扫描结果
scanType: ["qrCode", "barCode"], // 可以指定扫二维码还是一维码,默认二者都有
success: function(res) {
callback(res);
},
fail: function(res) {
console.log("%c微信H5sdk,scanQRCode失败",
"color:green;background:yellow");
},
});
});
});
},
// 微信分享
share(data, callback) {
this.isWechat() && this.initJssdk(function(res) {
jweixin.ready(function() {
var shareData = {
title: data.title,
desc: data.desc,
link: data.path,
imgUrl: data.image,
success: function(res) {
callback(res);
// 分享后的一些操作,比如分享统计等等
},
cancel: function(res) {}
};
jweixin.updateAppMessageShareData(shareData); //新版接口
//分享到朋友圈接口
// jweixin.updateTimelineShareData(shareData);
});
});
},
// 打开坐标位置
openLocation(data, callback) { //打开位置
this.isWechat() && this.initJssdk(function(res) {
jweixin.ready(function() {
jweixin.openLocation({ //根据传入的坐标打开地图
latitude: data.latitude,
longitude: data.longitude
});
});
});
},
// 选择图片
chooseImage(callback) { //选择图片
this.isWechat() && this.initJssdk(function(res) {
jweixin.ready(function() {
jweixin.chooseImage({
count: 1,
sizeType: ["compressed"],
sourceType: ["album"],
success: function(rs) {
callback(rs);
}
});
});
});
},
//微信支付
wxpay(data, callback) {
let that = this;
this.isWechat() && this.initJssdk(function(res) {
jweixin.ready(function() {
jweixin.chooseWXPay({
timestamp: data
.timeStamp, // 支付签名时间戳注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
nonceStr: data.nonceStr, // 支付签名随机串,不长于 32 位
package: data.package, // 统一支付接口返回的prepay_id参数值提交格式如prepay_id=\*\*\*
signType: data.signType, // 签名方式,默认为'SHA1',使用新版支付需传入'MD5'
paySign: data.paySign, // 支付签名
success: function(res) {
callback(res);
},
fail: function(res) {
console.log("%c微信H5sdk,chooseWXPay失败",
"color:green;background:yellow");
callback(res);
},
cancel: function(res) {
},
});
});
});
}
};