You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
126 lines
3.0 KiB
JavaScript
126 lines
3.0 KiB
JavaScript
/**
|
|
* 上传地址
|
|
* @returns {*}
|
|
*/
|
|
import config from "@/config";
|
|
import { Session } from "../utils";
|
|
|
|
/**
|
|
* 上传成功返回详情信息
|
|
* @returns {string}
|
|
*/
|
|
export const uploadURLReturnDetail = () => {
|
|
return config.get("file/uploadReturnDetail");
|
|
};
|
|
|
|
/**
|
|
* 上传成功仅返回fileId
|
|
* @returns {string}
|
|
*/
|
|
export const uploadURLReturnId = () => {
|
|
return config.get("file/uploadReturnId");
|
|
};
|
|
|
|
/**
|
|
* 文件下载地址
|
|
* @param fileId
|
|
* @returns {string}
|
|
*/
|
|
export const downloadURL = (fileId) => {
|
|
const token = Session.getAccessToken() || Session.getRefreshToken();
|
|
return config.get("file/download") + "/" + fileId + `?access_token=${token}`;
|
|
};
|
|
|
|
/**
|
|
* 头像/图片查看地址
|
|
* @param fileId
|
|
* @returns {string}
|
|
*/
|
|
export const viewImg = (fileId) => {
|
|
const token = Session.getAccessToken() || Session.getRefreshToken();
|
|
return config.get("file/viewImg") + "/" + fileId + `?access_token=${token}`;
|
|
};
|
|
|
|
/**
|
|
* 获取图片后缀
|
|
* @returns {string}
|
|
*/
|
|
export const getPicSuffix = () => {
|
|
return config.get("picSuffix");
|
|
};
|
|
|
|
/**
|
|
* 数组中某项移至数组末尾
|
|
* @returns {array}
|
|
*/
|
|
export const convertColumns = (array, fromIndex, toIndex) => {
|
|
array.splice(toIndex, 1, array.splice(fromIndex, 1)[0]);
|
|
return array;
|
|
};
|
|
|
|
/**
|
|
* 判断是否为JSON字符串
|
|
* @returns {string}
|
|
*/
|
|
export const exceptStr = (str) => {
|
|
try {
|
|
return JSON.parse(str);
|
|
} catch (err) {
|
|
return {};
|
|
}
|
|
};
|
|
|
|
export const paginationFun = (tableListPageObj, sizeChange, onChange, i18n = {}) => {
|
|
return {
|
|
current: tableListPageObj.pageNum || tableListPageObj.current,
|
|
pageSize: tableListPageObj.size || tableListPageObj.pageSize,
|
|
total: tableListPageObj.total,
|
|
showTotal: total => `${i18n["共"] ? i18n["共"] : "共"} ${total} ${i18n["条"] ? i18n["条"] : "条"}`,
|
|
showQuickJumper: true,
|
|
showSizeChanger: true,
|
|
pageSizeOptions: ["10", "20", "50", "100"],
|
|
onShowSizeChange: (page, size) => {
|
|
const { total } = tableListPageObj;
|
|
sizeChange({
|
|
pageNum: page,
|
|
size,
|
|
total
|
|
});
|
|
},
|
|
onChange: (page, size) => {
|
|
const { total } = tableListPageObj;
|
|
onChange({
|
|
pageNum: page,
|
|
size,
|
|
total
|
|
});
|
|
}
|
|
};
|
|
};
|
|
|
|
export const paginationAction = (pageInfo = {}, i18n = {}, onChange, onShowSizeChange) => {
|
|
return {
|
|
pageSize: pageInfo.pageSize || 10,
|
|
current: pageInfo.current || 1,
|
|
total: pageInfo.total || 0,
|
|
pageSizeOptions: ["10", "20", "50", "100"],
|
|
showTotal: total => `${i18n["共"] ? i18n["共"] : "共"} ${total} ${i18n["条"] ? i18n["条"] : "条"}`,
|
|
onChange, onShowSizeChange,
|
|
showQuickJumper: true,
|
|
showSizeChanger: true
|
|
};
|
|
};
|
|
/*
|
|
* Author: 黎永顺
|
|
* Description:
|
|
* Params: 格式化钱
|
|
* Date: 2023/12/6
|
|
*/
|
|
export const toDecimal_n = (num, decimalPlaces) => {
|
|
if (num === null || !isFinite(num)) return null
|
|
if (decimalPlaces < 0) return null;
|
|
const multiplier = Math.pow(10, decimalPlaces);
|
|
const roundedNum = Math.round(num * multiplier) / multiplier;
|
|
return roundedNum.toFixed(decimalPlaces);
|
|
};
|