提交代码

This commit is contained in:
2025-06-26 11:41:12 +08:00
commit d75fb55eec
396 changed files with 42172 additions and 0 deletions

67
src/utils/common.ts Normal file
View File

@@ -0,0 +1,67 @@
import Taro from '@tarojs/taro'
export default function navTo(url: string, isLogin = false) {
if (isLogin) {
if (!Taro.getStorageSync('access_token')) {
Taro.showToast({
title: '请先登录',
icon: 'none',
duration: 500
});
return false;
}
}
Taro.navigateTo({
url: url
})
}
// 转base64
export function fileToBase64(filePath) {
return new Promise((resolve) => {
let fileManager = Taro.getFileSystemManager();
fileManager.readFile({
filePath,
encoding: 'base64',
success: (e: any) => {
resolve(`data:image/jpg;base64,${e.data}`);
}
});
});
};
/**
* 转义微信富文本图片样式
* @param htmlText
*/
export function wxParse(htmlText) {
// Replace <img> tags with max-width and height styles
htmlText = htmlText.replace(/\<img/gi, '<img style="max-width:100%;height:auto;"');
// Replace style attributes that do not contain text-align
htmlText = htmlText.replace(/style\s*?=\s*?(['"])(?!.*?text-align)[\s\S]*?\1/ig, 'style="max-width:100%;height:auto;"');
return htmlText;
}
export function copyText(text: string) {
Taro.setClipboardData({
data: text,
success: function () {
Taro.showToast({
title: '复制成功',
icon: 'success',
duration: 2000
});
},
fail: function () {
Taro.showToast({
title: '复制失败',
icon: 'none',
duration: 2000
});
}
});
}

8
src/utils/config.ts Normal file
View File

@@ -0,0 +1,8 @@
// 租户ID
export const TenantId = 10550;
// 接口地址
export const BaseUrl = 'https://cms-api.websoft.top/api';
// 当前版本
export const Version = 'v3.0.8';
// 版权信息
export const Copyright = 'WebSoft Inc.';

110
src/utils/domain.ts Normal file
View File

@@ -0,0 +1,110 @@
// 解析域名结构
export function getHost(): any {
const host = window.location.host;
return host.split('.');
}
// 是否https
export function isHttps() {
const protocol = window.location.protocol;
if (protocol == 'https:') {
return true;
}
return false;
}
/**
* 获取原始域名
* @return http://www.domain.com
*/
export function getOriginDomain(): string {
return window.origin;
}
/**
* 域名的第一部分
* 获取tenantId
* @return 10140
*/
export function getDomainPart1(): any {
const split = getHost();
if (split[0] == '127') {
return undefined;
}
if (typeof (split[0])) {
return split[0];
}
return undefined;
}
/**
* 通过解析泛域名获取租户ID
* https://10140.wsdns.cn
* @return 10140
*/
export function getTenantId() {
let tenantId = localStorage.getItem('TenantId');
if(getDomainPart1()){
tenantId = getDomainPart1();
return tenantId;
}
return tenantId;
}
/**
* 获取根域名
* hostname
*/
export function getHostname(): string {
return window.location.hostname;
}
/**
* 获取域名
* @return https://www.domain.com
*/
export function getDomain(): string {
return window.location.protocol + '//www.' + getRootDomain();
}
/**
* 获取根域名
* abc.com
*/
export function getRootDomain(): string {
const split = getHost();
return split[split.length - 2] + '.' + split[split.length - 1];
}
/**
* 获取二级域名
* @return abc.com
*/
export function getSubDomainPath(): string {
const split = getHost();
if (split.length == 2) {
return '';
}
return split[split.length - 3];
}
/**
* 获取产品标识
* @return 10048
*/
export function getProductCode(): string | null {
const subDomain = getSubDomainPath();
if (subDomain == undefined) {
return null;
}
const split = subDomain.split('-');
return split[0];
}
/**
* 控制台域名
*/
export function navSubDomain(path: string): string {
return `${window.location.protocol}//${path}.${getRootDomain()}`;
}

89
src/utils/request.ts Normal file
View File

@@ -0,0 +1,89 @@
import Taro from '@tarojs/taro'
import {BaseUrl, TenantId} from "@/utils/config";
let baseUrl = BaseUrl
if(process.env.NODE_ENV === 'development'){
// baseUrl = 'http://localhost:9000/api'
}
export function request<T>(options:any) {
const token = Taro.getStorageSync('access_token');
const header = {
'Content-Type': 'application/json',
'TenantId': Taro.getStorageSync('TenantId') || TenantId
}
if(token){
header['Authorization'] = token;
}
// 发起网络请求
return <T>new Promise((resolve, reject) => {
Taro.request({
url: options.url,
method: options.method || 'GET',
data: options.data || {},
header: options.header || header,
success: (res) => {
resolve(res.data)
},
fail: (err) => {
reject(err)
}
// 可以添加其他Taro.request支持的参数
})
});
}
export function get<T>(url: string,data?: any) {
if(url.indexOf('http') === -1){
url = baseUrl + url
}
if(data){
url = url + '?' + Object.keys(data).map(key => {
return key + '=' + data[key]
}).join('&')
}
return <T>request({
url,
method: 'GET'
})
}
export function post<T>(url:string, data?:any) {
if(url.indexOf('http') === -1){
url = baseUrl + url
}
return <T>request({
url,
method: 'POST',
data
})
}
export function put<T>(url:string, data?:any) {
if(url.indexOf('http') === -1){
url = baseUrl + url
}
return <T>request({
url,
method: 'PUT',
data
})
}
export function del<T>(url:string,data?: any) {
if(url.indexOf('http') === -1){
url = baseUrl + url
}
return <T>request({
url,
method: 'DELETE',
data
})
}
export default {
request,
get,
post,
put,
del
}

20
src/utils/server.ts Normal file
View File

@@ -0,0 +1,20 @@
import Taro from '@tarojs/taro';
import {User} from "@/api/system/user/model";
// 模版套餐ID
export const TEMPLATE_ID = 10258;
// 服务接口
export const SERVER_API_URL = 'https://server.gxwebsoft.com/api';
// export const SERVER_API_URL = 'http://127.0.0.1:8000/api';
/**
* 保存用户信息到本地存储
* @param token
* @param user
*/
export function saveStorageByLoginUser(token: string, user: User) {
Taro.setStorageSync('TenantId',user.tenantId)
Taro.setStorageSync('access_token', token)
Taro.setStorageSync('UserId', user.userId)
Taro.setStorageSync('Phone', user.phone)
Taro.setStorageSync('User', user)
}

39
src/utils/time.ts Normal file
View File

@@ -0,0 +1,39 @@
/**
* 获取当前时间
*/
export function formatCurrentDate() {
// 创建一个Date对象表示当前日期和时间
const now = new Date();
// 获取年、月、日,并进行必要的格式化
const day = String(now.getDate()).padStart(2, '0'); // 获取日,并确保是两位数
const month = String(now.getMonth() + 1).padStart(2, '0'); // 获取月并确保是两位数月份是从0开始的所以要加1
const year = String(now.getFullYear()).slice(-2); // 获取年份的最后两位数字
return `${day}${month}${year}`;
}
/**
* 获取当前时分秒
*/
export function formatHhmmss(){
// 创建一个Date对象表示当前日期和时间
const now = new Date();
// 获取当前的小时
const hour = String(now.getHours()).padStart(2, '0');
// 获取当前的分钟
const minute = String(now.getMinutes()).padStart(2, '0');
// 获取当前的秒数
const second = String(now.getSeconds()).padStart(2, '0');
return `${String(Number(hour) - 8).padStart(2, '0')}${minute}${second}`;
}
/**
* 获取当前小时
*/
export function getCurrentHour() {
const now = new Date();
// 获取当前的小时
const hour = String(now.getHours()).padStart(2, '0');
return `${String(Number(hour) - 8).padStart(2, '0')}`;
}