|
@@ -183,11 +183,11 @@ export const getEnvBaseUploadUrl = () => {
|
|
|
* @returns {*}
|
|
* @returns {*}
|
|
|
*/
|
|
*/
|
|
|
export function formatDate(value, fmt) {
|
|
export function formatDate(value, fmt) {
|
|
|
- var regPos = /^\d+(\.\d+)?$/;
|
|
|
|
|
- if(regPos.test(value)){
|
|
|
|
|
- //如果是数字
|
|
|
|
|
- let getDate = new Date(value);
|
|
|
|
|
- let o = {
|
|
|
|
|
|
|
+ const regPos = /^\d+(\.\d+)?$/
|
|
|
|
|
+ if (regPos.test(value)) {
|
|
|
|
|
+ // 如果是数字
|
|
|
|
|
+ const getDate = new Date(value)
|
|
|
|
|
+ const o = {
|
|
|
'M+': getDate.getMonth() + 1,
|
|
'M+': getDate.getMonth() + 1,
|
|
|
'd+': getDate.getDate(),
|
|
'd+': getDate.getDate(),
|
|
|
'h+': getDate.getHours(),
|
|
'h+': getDate.getHours(),
|
|
@@ -195,22 +195,25 @@ export function formatDate(value, fmt) {
|
|
|
'm+': getDate.getMinutes(),
|
|
'm+': getDate.getMinutes(),
|
|
|
's+': getDate.getSeconds(),
|
|
's+': getDate.getSeconds(),
|
|
|
'q+': Math.floor((getDate.getMonth() + 3) / 3),
|
|
'q+': Math.floor((getDate.getMonth() + 3) / 3),
|
|
|
- 'S': getDate.getMilliseconds()
|
|
|
|
|
- };
|
|
|
|
|
|
|
+ S: getDate.getMilliseconds(),
|
|
|
|
|
+ }
|
|
|
if (/(y+)/.test(fmt)) {
|
|
if (/(y+)/.test(fmt)) {
|
|
|
fmt = fmt.replace(RegExp.$1, (getDate.getFullYear() + '').substr(4 - RegExp.$1.length))
|
|
fmt = fmt.replace(RegExp.$1, (getDate.getFullYear() + '').substr(4 - RegExp.$1.length))
|
|
|
}
|
|
}
|
|
|
- for (let k in o) {
|
|
|
|
|
|
|
+ for (const k in o) {
|
|
|
if (new RegExp('(' + k + ')').test(fmt)) {
|
|
if (new RegExp('(' + k + ')').test(fmt)) {
|
|
|
- fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k]) : (('00' + o[k]).substr(('' + o[k]).length)))
|
|
|
|
|
|
|
+ fmt = fmt.replace(
|
|
|
|
|
+ RegExp.$1,
|
|
|
|
|
+ RegExp.$1.length === 1 ? o[k] : ('00' + o[k]).substr(('' + o[k]).length),
|
|
|
|
|
+ )
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- return fmt;
|
|
|
|
|
- }else{
|
|
|
|
|
- //TODO
|
|
|
|
|
- if(value && value.length>0){
|
|
|
|
|
- value = value.trim();
|
|
|
|
|
- return value.substr(0,fmt.length);
|
|
|
|
|
|
|
+ return fmt
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // TODO
|
|
|
|
|
+ if (value && value.length > 0) {
|
|
|
|
|
+ value = value.trim()
|
|
|
|
|
+ return value.substr(0, fmt.length)
|
|
|
}
|
|
}
|
|
|
return value
|
|
return value
|
|
|
}
|
|
}
|
|
@@ -221,39 +224,39 @@ export function formatDate(value, fmt) {
|
|
|
*/
|
|
*/
|
|
|
export function getRefPromise(componentRef) {
|
|
export function getRefPromise(componentRef) {
|
|
|
return new Promise((resolve) => {
|
|
return new Promise((resolve) => {
|
|
|
- (function next() {
|
|
|
|
|
- let ref = componentRef.value;
|
|
|
|
|
|
|
+ ;(function next() {
|
|
|
|
|
+ const ref = componentRef.value
|
|
|
if (ref) {
|
|
if (ref) {
|
|
|
- resolve(ref);
|
|
|
|
|
|
|
+ resolve(ref)
|
|
|
} else {
|
|
} else {
|
|
|
setTimeout(() => {
|
|
setTimeout(() => {
|
|
|
- next();
|
|
|
|
|
- }, 100);
|
|
|
|
|
|
|
+ next()
|
|
|
|
|
+ }, 100)
|
|
|
}
|
|
}
|
|
|
- })();
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ })()
|
|
|
|
|
+ })
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 构建文件URL
|
|
* 构建文件URL
|
|
|
- *
|
|
|
|
|
|
|
+ *
|
|
|
* 将域名和文件名拼接成完整的文件URL,支持自定义域名或使用环境变量
|
|
* 将域名和文件名拼接成完整的文件URL,支持自定义域名或使用环境变量
|
|
|
- *
|
|
|
|
|
|
|
+ *
|
|
|
* @param filename 文件名(必需),不能为空
|
|
* @param filename 文件名(必需),不能为空
|
|
|
* @param domain 自定义域名(可选),如未提供则使用环境变量 VITE_FILE_URL
|
|
* @param domain 自定义域名(可选),如未提供则使用环境变量 VITE_FILE_URL
|
|
|
* @param basePath 基础路径(可选),默认为空
|
|
* @param basePath 基础路径(可选),默认为空
|
|
|
* @returns 完整的文件URL
|
|
* @returns 完整的文件URL
|
|
|
- *
|
|
|
|
|
|
|
+ *
|
|
|
* @example
|
|
* @example
|
|
|
* // 使用自定义域名
|
|
* // 使用自定义域名
|
|
|
* buildFileUrl('avatar.jpg', 'https://cdn.example.com')
|
|
* buildFileUrl('avatar.jpg', 'https://cdn.example.com')
|
|
|
* // 返回: 'https://cdn.example.com/avatar.jpg'
|
|
* // 返回: 'https://cdn.example.com/avatar.jpg'
|
|
|
- *
|
|
|
|
|
- * @example
|
|
|
|
|
|
|
+ *
|
|
|
|
|
+ * @example
|
|
|
* // 使用自定义域名和基础路径
|
|
* // 使用自定义域名和基础路径
|
|
|
* buildFileUrl('avatar.jpg', 'https://cdn.example.com', '/uploads')
|
|
* buildFileUrl('avatar.jpg', 'https://cdn.example.com', '/uploads')
|
|
|
* // 返回: 'https://cdn.example.com/uploads/avatar.jpg'
|
|
* // 返回: 'https://cdn.example.com/uploads/avatar.jpg'
|
|
|
- *
|
|
|
|
|
|
|
+ *
|
|
|
* @example
|
|
* @example
|
|
|
* // 使用环境变量域名
|
|
* // 使用环境变量域名
|
|
|
* buildFileUrl('avatar.jpg')
|
|
* buildFileUrl('avatar.jpg')
|
|
@@ -277,7 +280,7 @@ export const buildFileUrl = (filename: string, domain?: string, basePath?: strin
|
|
|
|
|
|
|
|
// 确定使用的域名
|
|
// 确定使用的域名
|
|
|
let baseUrl = domain || import.meta.env.VITE_FILE_URL || ''
|
|
let baseUrl = domain || import.meta.env.VITE_FILE_URL || ''
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// 智能协议处理:如果域名不包含协议,自动添加 https://
|
|
// 智能协议处理:如果域名不包含协议,自动添加 https://
|
|
|
if (baseUrl && !baseUrl.match(/^https?:\/\//)) {
|
|
if (baseUrl && !baseUrl.match(/^https?:\/\//)) {
|
|
|
baseUrl = `https://${baseUrl}`
|
|
baseUrl = `https://${baseUrl}`
|
|
@@ -302,3 +305,7 @@ export const buildFileUrl = (filename: string, domain?: string, basePath?: strin
|
|
|
|
|
|
|
|
return fullUrl
|
|
return fullUrl
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+export const getTime = () => {
|
|
|
|
|
+ return new Date().getTime()
|
|
|
|
|
+}
|