2025-02-28 09:56:01 +08:00
|
|
|
import router from "../router/index.js";
|
2025-06-17 21:34:59 +08:00
|
|
|
import {useSystemStore} from "../pinia/SystemStore/index.js";
|
2025-02-28 09:56:01 +08:00
|
|
|
|
2025-06-25 20:25:40 +08:00
|
|
|
export const toPath = (path, query = {}, flag = false) => {
|
2025-04-30 16:43:52 +08:00
|
|
|
router.push({
|
2025-06-12 20:53:39 +08:00
|
|
|
path: path, query: query
|
2025-06-17 21:34:59 +08:00
|
|
|
}).then(() => {
|
|
|
|
|
const SystemStore = useSystemStore();
|
2025-06-25 20:25:40 +08:00
|
|
|
if (!flag) {
|
|
|
|
|
SystemStore.NOW_ROUTER = path;
|
|
|
|
|
Object.assign(SystemStore.NOW_ROUTER_QUERY, query);
|
|
|
|
|
}
|
2025-06-17 21:34:59 +08:00
|
|
|
});
|
2025-02-28 09:56:01 +08:00
|
|
|
}
|
2025-03-19 16:43:17 +08:00
|
|
|
|
2025-06-25 20:25:40 +08:00
|
|
|
export const openPage = (path, query = {}) => {
|
|
|
|
|
window.open('http://localhost:9050/#/manage-materials', '_blank');
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-19 16:43:17 +08:00
|
|
|
export const VITE_TINYMCE_KEY = () => {
|
|
|
|
|
return import.meta.env.VITE_TINYMCE_KEY;
|
|
|
|
|
}
|
2025-04-29 19:43:06 +08:00
|
|
|
|
|
|
|
|
export const deleteObjectFields = (obj) => {
|
|
|
|
|
Object.keys(obj).forEach(key => {
|
|
|
|
|
delete obj[key];
|
|
|
|
|
});
|
|
|
|
|
}
|
2025-04-30 16:43:52 +08:00
|
|
|
|
|
|
|
|
export const baseImage = (url) => {
|
|
|
|
|
if (!url) url = '';
|
|
|
|
|
return url.startsWith('http') ? url : import.meta.env.VITE_API_URL + url;
|
|
|
|
|
}
|
2025-05-10 15:59:02 +08:00
|
|
|
|
2025-05-24 18:23:11 +08:00
|
|
|
export const openUrl = (url) => {
|
|
|
|
|
window.open(url);
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-10 15:59:02 +08:00
|
|
|
export const determineMediaType = (url) => {
|
|
|
|
|
const imageExtensions = ['.jpg', '.jpeg', '.png', '.gif', '.bmp', '.svg'];
|
|
|
|
|
const videoExtensions = ['.mp4', '.mov', '.avi', '.mkv', '.webm'];
|
|
|
|
|
|
|
|
|
|
const extension = url.substring(url.lastIndexOf('.')).toLowerCase();
|
|
|
|
|
|
|
|
|
|
if (imageExtensions.includes(extension)) {
|
|
|
|
|
return 'Image';
|
|
|
|
|
} else if (videoExtensions.includes(extension)) {
|
|
|
|
|
return 'Video';
|
|
|
|
|
} else {
|
|
|
|
|
return 'Unknown';
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-06-12 20:53:39 +08:00
|
|
|
|
|
|
|
|
export const findSwappedIds = (original, swapped) => {
|
|
|
|
|
let id1, id2;
|
|
|
|
|
|
|
|
|
|
original.forEach((item, index) => {
|
|
|
|
|
if (item.id !== swapped[index].id) {
|
|
|
|
|
if (!id1) {
|
|
|
|
|
id1 = item.id; // 记录第一个不同的 id
|
|
|
|
|
} else {
|
|
|
|
|
id2 = item.id; // 记录第二个不同的 id
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return [id1, id2];
|
|
|
|
|
};
|