fix import path

This commit is contained in:
Timi
2026-04-02 16:52:48 +08:00
parent cdaf858a53
commit c266c9e95b
44 changed files with 180 additions and 194 deletions

View File

@@ -1,4 +1,5 @@
import { ArticleView, axios } from "timi-web";
import { ArticleView } from "../types";
import { axios } from "./BaseAPI";
/**
* 获取文章

16
src/api/BaseAPI.ts Normal file
View File

@@ -0,0 +1,16 @@
import Network from "../utils/Network";
let serviceAxios: any | null = null;
function getServiceAxios(): any {
if (serviceAxios === null) {
serviceAxios = Network.axios;
}
return serviceAxios;
}
export const axios = new Proxy({} as any, {
get(_target: any, prop: string | symbol, receiver: any): any {
return Reflect.get(getServiceAxios(), prop, receiver);
}
});

View File

@@ -1,4 +1,5 @@
import { axios, CaptchaData, Comment, CommentReply, Page, PageResult } from "~/index";
import { CaptchaData, Comment, CommentReply, Page, PageResult } from "../types";
import { axios } from "./BaseAPI";
const BASE_URI = "/comment";

View File

@@ -1,4 +1,6 @@
import { axios, SettingKey, TemplateBizType, Toolkit } from "~/index";
import { TemplateBizType } from "../types";
import Toolkit from "../utils/Toolkit";
import { axios } from "./BaseAPI";
const getCaptchaAPI = () => axios.defaults.baseURL + "/captcha";

View File

@@ -1,4 +1,5 @@
import { axios, Developer } from "~/index";
import { Developer } from "../types";
import { axios } from "./BaseAPI";
const BASE_URI = "/git/developer";

View File

@@ -1,15 +1,15 @@
import {
Attachment,
axios,
CaptchaData,
CommonAPI,
LoginRequest,
LoginResponse,
RegisterRequest,
UserAttachType,
UserProfileView,
UserView
} from "~/index";
} from "../types";
import { axios } from "./BaseAPI";
import CommonAPI from "./CommonAPI";
const BASE_URI = "/user";

5
src/api/index.ts Normal file
View File

@@ -0,0 +1,5 @@
export * from "./ArticleAPI";
export * from "./CommentAPI";
export * from "./CommonAPI";
export * from "./DeveloperAPI"
export * from "./UserAPI";

View File

@@ -1,18 +1,18 @@
@import url(~/assets/style/variable);
@import url(./variable);
*::-webkit-scrollbar {
.custom-scroll-bar *::-webkit-scrollbar {
width: 10px !important;
height: 10px !important;
cursor: var(--tui-cur-default);
background: #CFD2E0;
}
*::-webkit-scrollbar-corner {
.custom-scroll-bar *::-webkit-scrollbar-corner {
background: #CFD2E0;
cursor: var(--tui-cur-default);
}
*::-webkit-scrollbar-thumb {
.custom-scroll-bar *::-webkit-scrollbar-thumb {
cursor: var(--tui-cur-default);
background: #525870;
}

View File

@@ -1,5 +1,5 @@
import view from "./index.vue";
import Toolkit from "~/utils/Toolkit";
import Toolkit from "../../../utils/Toolkit";
export const BEFlowerFall = Toolkit.withInstall(view);
export default BEFlowerFall;

View File

@@ -5,8 +5,8 @@
</template>
<script lang="ts" setup>
import Toolkit from "~/utils/Toolkit";
import Resizer from "~/utils/Resizer";
import Resizer from "../../../utils/Resizer";
import Toolkit from "../../../utils/Toolkit";
defineOptions({
name: "BEFlowerFall"

View File

@@ -1,5 +1,5 @@
import view from "./index.vue";
import Toolkit from "~/utils/Toolkit";
import Toolkit from "../../utils/Toolkit";
export const Captcha = Toolkit.withInstall(view);
export default Captcha;

View File

@@ -11,7 +11,7 @@
</template>
<script lang="ts" setup>
import Toolkit from "~/utils/Toolkit";
import Toolkit from "../../utils/Toolkit";
defineOptions({
name: "Captcha"

View File

@@ -1,5 +1,5 @@
import view from "./index.vue";
import Toolkit from "~/utils/Toolkit";
import Toolkit from "../../utils/Toolkit";
export const Copyright = Toolkit.withInstall(view);
export default Copyright;

View File

@@ -1,5 +1,5 @@
import view from "./index.vue";
import Toolkit from "~/utils/Toolkit";
import Toolkit from "../../utils/Toolkit";
export const EmptyTips = Toolkit.withInstall(view);
export default EmptyTips;

View File

@@ -1,5 +1,5 @@
import view from "./index.vue";
import Toolkit from "~/utils/Toolkit";
import Toolkit from "../../utils/Toolkit";
export const Icon = Toolkit.withInstall(view);
export default Icon;

View File

@@ -13,7 +13,7 @@
</template>
<script lang="ts" setup>
import IconMapper from "~/utils/IconMapper";
import IconMapper from "../../utils/IconMapper";
defineOptions({
name: "Icon"

View File

@@ -1,5 +1,5 @@
import view from "./index.vue";
import Toolkit from "~/utils/Toolkit";
import Toolkit from "../../utils/Toolkit";
export const Loading = Toolkit.withInstall(view);
export default Loading;

View File

@@ -13,7 +13,7 @@
</template>
<script lang="ts" setup>
import { Toolkit } from "~/index";
import Toolkit from "../../utils/Toolkit";
defineOptions({
name: "Loading"
});

View File

@@ -1,5 +1,5 @@
import view from "./index.vue";
import Toolkit from "~/utils/Toolkit";
import Toolkit from "../../utils/Toolkit";
export const MarkdownEditor = Toolkit.withInstall(view);
export default MarkdownEditor;

View File

@@ -38,7 +38,8 @@
</template>
<script lang="ts" setup>
import { Icon, MarkdownView } from "~/index";
import { Icon } from "../icon";
import { MarkdownView } from "../markdown-view";
import calcHeight from "./CalcTextareaHeight";
defineOptions({

View File

@@ -1,5 +1,5 @@
import view from "./index.vue";
import Toolkit from "~/utils/Toolkit";
import Toolkit from "../../utils/Toolkit";
import "./style.less";
export const MarkdownView = Toolkit.withInstall(view);

View File

@@ -7,7 +7,7 @@
</template>
<script lang="ts" setup>
import Prism from "prismjs";
import Markdown from "~/utils/Markdown";
import Markdown from "../../utils/Markdown";
defineOptions({
name: "MarkdownView"

View File

@@ -1,4 +1,4 @@
@import url(~/assets/style/variable);
@import url("../../assets/style/variable");
.tui-markdown-view {
font-size: 14px;

View File

@@ -1,5 +1,5 @@
import view from "./index.vue";
import Toolkit from "~/utils/Toolkit";
import Toolkit from "../../utils/Toolkit";
export const Popup = Toolkit.withInstall(view);
export default Popup;

View File

@@ -1,5 +1,5 @@
import view from "./index.vue";
import Toolkit from "~/utils/Toolkit";
import Toolkit from "../../utils/Toolkit";
export const UserLevel = Toolkit.withInstall(view);
export default UserLevel;

View File

@@ -2,54 +2,17 @@ import type { App } from "vue";
import components from "./components";
import Network from "./utils/Network";
import UserAPI from "./api/UserAPI";
import CommonAPI from "./api/CommonAPI";
import ArticleAPI from "./api/ArticleAPI";
import CommentAPI from "./api/CommentAPI";
import DeveloperAPI from "./api/DeveloperAPI";
import Time from "./utils/Time";
import IOSize from "./utils/IOSize";
import Events from "./utils/Events";
import Cooker from "./utils/Cooker";
import Toolkit from "./utils/Toolkit";
import Resizer from "./utils/Resizer";
import Storage from "./utils/Storage";
import Prismjs from "./utils/Prismjs";
import Markdown from "./utils/Markdown";
import Scroller from "./utils/Scroller";
import IconMapper from "./utils/IconMapper";
import SettingMapper from "./utils/SettingMapper";
import VPopup from "./utils/directives/Popup";
import VDraggable from "./utils/directives/Draggable";
import { userStore } from "./store/user";
import { deviceStore } from "./store/device";
import "./assets/style/variable.less";
import "./assets/style/timi-web.less";
import { Network } from "./utils";
export * from "./api";
export * from "./components";
export * from "./store";
export * from "./types";
export * from "./utils";
export * from "./types/Model";
export * from "./types/Article";
export * from "./types/User";
export * from "./types/Comment";
export * from "./types/Setting";
export * from "./types/Template";
export * from "./types/Developer";
export * from "./types/Attachment";
export * from "./utils/Prismjs";
export * from "./utils/directives/Popup";
export type { ScrollListener } from "./utils/Scroller";
export type { DraggableConfig } from "./utils/directives/Draggable";
export type { PopupConfig } from "./utils/directives/Popup";
export const axios = Network.axios;
const install = function (app: App) {
components.forEach(component => {
@@ -57,40 +20,6 @@ const install = function (app: App) {
});
};
const axios = Network.axios;
const setGlobalErrorCallback = Network.setGlobalErrorCallback;
export default {
install
};
export {
axios,
Network,
setGlobalErrorCallback,
UserAPI,
CommonAPI,
ArticleAPI,
CommentAPI,
DeveloperAPI,
userStore,
deviceStore,
Time,
Events,
IOSize,
Cooker,
Toolkit,
Resizer,
Storage,
Prismjs,
Markdown,
Scroller,
IconMapper,
SettingMapper,
VPopup,
VDraggable
};

View File

@@ -1,4 +1,4 @@
import { Resizer } from "~/index";
import Resizer from "../utils/Resizer";
// true 为手机
const isPhone = ref(false);

2
src/store/index.ts Normal file
View File

@@ -0,0 +1,2 @@
export * from "./device";
export * from "./user";

View File

@@ -1,4 +1,6 @@
import { LoginResponse, LoginToken, LoginUser, Storage, UserAPI, UserToken } from "timi-web";
import { LoginResponse, LoginToken, LoginUser, UserToken } from "../types";
import Storage from "../utils/Storage";
import UserAPI from "../api/UserAPI";
const loginUser = reactive<LoginUser>({
token: undefined,

View File

@@ -1,4 +1,5 @@
import { AttachmentView, Model } from "timi-web";
import type { AttachmentView } from "./Attachment";
import type { Model } from "./Model";
// 文章
export type Article<E extends ArticleMusicExtendData | ArticleSoftwareExtendData> = {

View File

@@ -1,5 +1,15 @@
import type { Plugin } from "vue";
export * from "./Model";
export * from "./Article";
export * from "./Setting";
export * from "./Attachment";
export * from "./Model";
export * from "./User";
export * from "./Template";
export * from "./Comment";
export * from "./Developer";
/**
*
*/
@@ -8,7 +18,7 @@ export type InstallRecord<T> = T & Plugin;
/**
*
*/
export type DefaultSlotProp = (props: {}) => unknown
export type DefaultSlotProp = (props: object) => unknown
/**
*

View File

@@ -4,7 +4,7 @@ import { markedHighlight } from "marked-highlight";
import { mangle } from "marked-mangle";
import Prism from "prismjs";
import "prismjs/themes/prism.css";
import { Toolkit } from "~/index";
import SettingMapper from "./SettingMapper";
export default class Markdown {
@@ -99,7 +99,7 @@ export default class Markdown {
}
// 内部资源链接
if (href.indexOf("@") !== -1) {
href = Toolkit.toResURL(href);
href = SettingMapper.toResURL(href);
}
{
// 处理嵌套 markdown这可能不是最优解
@@ -159,7 +159,7 @@ export default class Markdown {
if (extendTag) {
href = href.substring(1);
}
href = Toolkit.toResURL(href);
href = SettingMapper.toResURL(href);
}
const clazzStr = clazz.join(" ");

View File

@@ -1,6 +1,8 @@
import axios, { InternalAxiosRequestConfig } from "axios";
import { Response } from "~/types/Model";
import { Cooker, Time, userStore } from "~/index";
import Cooker from "./Cooker";
import type { Response } from "../types/Model";
import Time from "./Time";
import { userStore } from "../store/user";
type ErrorCallback = (response: Response<any>) => void;

View File

@@ -1,7 +1,7 @@
import { SettingKey } from "~/types/Setting";
import { readonly, Ref, ref } from "vue";
import CommonAPI from "~/api/CommonAPI";
import { RunEnv, Toolkit } from "timi-web";
import { RunEnv, SettingKey } from "../types";
import Toolkit from "./Toolkit";
import CommonAPI from "../api/CommonAPI";
export default class SettingMapper {
@@ -100,4 +100,22 @@ export default class SettingMapper {
}
return SettingMapper.instance = new SettingMapper();
}
/**
* 解析资源 URL 协议前缀
*
* @param val 原始值,如 `res@/path/to/file`
* @returns 完整 URL
*/
public static toResURL(val: string): string {
const at = val.indexOf("@");
const start = val.substring(0, at);
const path = val.substring(at + 1);
switch (start) {
case "res": return SettingMapper.getDomainLink(SettingKey.DOMAIN_RESOURCE) + path;
case "dl": return SettingMapper.getDomainLink(SettingKey.DOMAIN_DOWNLOAD) + path;
case "attach": return CommonAPI.getAttachmentReadAPI(path);
}
return val;
}
}

View File

@@ -1,7 +1,5 @@
import type { App } from "vue";
import type { InstallRecord } from "~/types";
import { UserLevelType } from "~/types/User";
import { CommonAPI, SettingKey, SettingMapper } from "~/index";
import { InstallRecord, UserLevelType } from "../types";
export default class Toolkit {
@@ -340,18 +338,6 @@ export default class Toolkit {
return form;
}
public static toResURL(val: string): string {
const at = val.indexOf("@");
const start = val.substring(0, at);
const path = val.substring(at + 1);
switch (start) {
case "res": return SettingMapper.getDomainLink(SettingKey.DOMAIN_RESOURCE) + path;
case "dl": return SettingMapper.getDomainLink(SettingKey.DOMAIN_DOWNLOAD) + path;
case "attach": return CommonAPI.getAttachmentReadAPI(path);
}
return val;
}
public static format(template: string, variables: { [key: string]: any }): string {
return template.replace(/\$\{(\w+)}/g, (_, key) => variables[key]);
}

22
src/utils/index.ts Normal file
View File

@@ -0,0 +1,22 @@
export { default as Cooker } from "./Cooker";
export { default as Events } from "./Events";
export { default as IOSize } from "./IOSize";
export { default as Markdown } from "./Markdown";
export { default as Network } from "./Network";
export { default as Prismjs } from "./Prismjs";
export { default as Resizer } from "./Resizer";
export { default as Scroller } from "./Scroller";
export { default as Storage } from "./Storage";
export { default as Time } from "./Time";
export { default as Toolkit } from "./Toolkit";
export { default as IconMapper } from "./IconMapper";
export { default as SettingMapper } from "./SettingMapper";
export { default as VDraggable } from "./directives/Draggable";
export { default as VPopup } from "./directives/Popup";
export * from "./MethodLocker";
export * from "./Network";
export * from "./Prismjs";
export * from "./directives/Draggable";
export * from "./directives/Popup";