perf: 代码优化 所有的 interface 类型命名

This commit is contained in:
pany 2023-05-21 09:51:41 +08:00
parent 6cca254335
commit 05712f4adc
19 changed files with 61 additions and 61 deletions

View File

@ -10,7 +10,7 @@ export function getLoginCodeApi() {
} }
/** 登录并返回 Token */ /** 登录并返回 Token */
export function loginApi(data: Login.ILoginRequestData) { export function loginApi(data: Login.LoginRequestData) {
return request<Login.LoginResponseData>({ return request<Login.LoginResponseData>({
url: "users/login", url: "users/login",
method: "post", method: "post",

View File

@ -1,4 +1,4 @@
export interface ILoginRequestData { export interface LoginRequestData {
/** admin 或 editor */ /** admin 或 editor */
username: "admin" | "editor" username: "admin" | "editor"
/** 密码 */ /** 密码 */
@ -7,8 +7,8 @@ export interface ILoginRequestData {
code: string code: string
} }
export type LoginCodeResponseData = IApiResponseData<string> export type LoginCodeResponseData = ApiResponseData<string>
export type LoginResponseData = IApiResponseData<{ token: string }> export type LoginResponseData = ApiResponseData<{ token: string }>
export type UserInfoResponseData = IApiResponseData<{ username: string; roles: string[] }> export type UserInfoResponseData = ApiResponseData<{ username: string; roles: string[] }>

View File

@ -2,7 +2,7 @@ import { request } from "@/utils/service"
import type * as Table from "./types/table" import type * as Table from "./types/table"
/** 增 */ /** 增 */
export function createTableDataApi(data: Table.ICreateTableRequestData) { export function createTableDataApi(data: Table.CreateTableRequestData) {
return request({ return request({
url: "table", url: "table",
method: "post", method: "post",
@ -19,7 +19,7 @@ export function deleteTableDataApi(id: string) {
} }
/** 改 */ /** 改 */
export function updateTableDataApi(data: Table.IUpdateTableRequestData) { export function updateTableDataApi(data: Table.UpdateTableRequestData) {
return request({ return request({
url: "table", url: "table",
method: "put", method: "put",
@ -28,7 +28,7 @@ export function updateTableDataApi(data: Table.IUpdateTableRequestData) {
} }
/** 查 */ /** 查 */
export function getTableDataApi(params: Table.IGetTableRequestData) { export function getTableDataApi(params: Table.GetTableRequestData) {
return request<Table.GetTableResponseData>({ return request<Table.GetTableResponseData>({
url: "table", url: "table",
method: "get", method: "get",

View File

@ -1,15 +1,15 @@
export interface ICreateTableRequestData { export interface CreateTableRequestData {
username: string username: string
password: string password: string
} }
export interface IUpdateTableRequestData { export interface UpdateTableRequestData {
id: string id: string
username: string username: string
password?: string password?: string
} }
export interface IGetTableRequestData { export interface GetTableRequestData {
/** 当前页码 */ /** 当前页码 */
currentPage: number currentPage: number
/** 查询条数 */ /** 查询条数 */
@ -20,7 +20,7 @@ export interface IGetTableRequestData {
phone?: string phone?: string
} }
export interface IGetTableData { export interface GetTableData {
createTime: string createTime: string
email: string email: string
id: string id: string
@ -30,7 +30,7 @@ export interface IGetTableData {
username: string username: string
} }
export type GetTableResponseData = IApiResponseData<{ export type GetTableResponseData = ApiResponseData<{
list: IGetTableData[] list: GetTableData[]
total: number total: number
}> }>

View File

@ -1,10 +1,10 @@
<script lang="ts" setup> <script lang="ts" setup>
import { type PropType } from "vue" import { type PropType } from "vue"
import { type IListItem } from "./data" import { type ListItem } from "./data"
const props = defineProps({ const props = defineProps({
list: { list: {
type: Object as PropType<IListItem[]>, type: Object as PropType<ListItem[]>,
required: true required: true
} }
}) })

View File

@ -1,4 +1,4 @@
export interface IListItem { export interface ListItem {
avatar?: string avatar?: string
title: string title: string
datetime?: string datetime?: string
@ -7,7 +7,7 @@ export interface IListItem {
extra?: string extra?: string
} }
export const notifyData: IListItem[] = [ export const notifyData: ListItem[] = [
{ {
avatar: "https://gw.alipayobjects.com/zos/rmsportal/OKJXDXrmkNshAMvwtvhu.png", avatar: "https://gw.alipayobjects.com/zos/rmsportal/OKJXDXrmkNshAMvwtvhu.png",
title: "V3 Admin Vite 上线啦", title: "V3 Admin Vite 上线啦",
@ -23,7 +23,7 @@ export const notifyData: IListItem[] = [
} }
] ]
export const messageData: IListItem[] = [ export const messageData: ListItem[] = [
{ {
avatar: "https://gw.alipayobjects.com/zos/rmsportal/ThXAXghbEsBCCSDihZxY.png", avatar: "https://gw.alipayobjects.com/zos/rmsportal/ThXAXghbEsBCCSDihZxY.png",
title: "来自楚门的世界", title: "来自楚门的世界",
@ -44,7 +44,7 @@ export const messageData: IListItem[] = [
} }
] ]
export const todoData: IListItem[] = [ export const todoData: ListItem[] = [
{ {
title: "任务名称", title: "任务名称",
description: "这家伙很懒,什么都没留下", description: "这家伙很懒,什么都没留下",

View File

@ -3,14 +3,14 @@ import { ref, computed } from "vue"
import { ElMessage } from "element-plus" import { ElMessage } from "element-plus"
import { Bell } from "@element-plus/icons-vue" import { Bell } from "@element-plus/icons-vue"
import NotifyList from "./NotifyList.vue" import NotifyList from "./NotifyList.vue"
import { type IListItem, notifyData, messageData, todoData } from "./data" import { type ListItem, notifyData, messageData, todoData } from "./data"
type TabNameType = "通知" | "消息" | "待办" type TabNameType = "通知" | "消息" | "待办"
interface IDataItem { interface DataItem {
name: TabNameType name: TabNameType
type: "primary" | "success" | "warning" | "danger" | "info" type: "primary" | "success" | "warning" | "danger" | "info"
list: IListItem[] list: ListItem[]
} }
/** 角标当前值 */ /** 角标当前值 */
@ -28,7 +28,7 @@ const popoverWidth = 350
/** 当前 Tab */ /** 当前 Tab */
const activeName = ref<TabNameType>("通知") const activeName = ref<TabNameType>("通知")
/** 所有数据 */ /** 所有数据 */
const data = ref<IDataItem[]>([ const data = ref<DataItem[]>([
// //
{ {
name: "通知", name: "通知",

View File

@ -1,5 +1,5 @@
/** 动态路由配置 */ /** 动态路由配置 */
interface IAsyncRouteSettings { interface AsyncRouteSettings {
/** /**
* *
* 1. roles * 1. roles
@ -13,7 +13,7 @@ interface IAsyncRouteSettings {
defaultRoles: Array<string> defaultRoles: Array<string>
} }
const asyncRouteSettings: IAsyncRouteSettings = { const asyncRouteSettings: AsyncRouteSettings = {
open: true, open: true,
defaultRoles: ["DEFAULT_ROLE"] defaultRoles: ["DEFAULT_ROLE"]
} }

View File

@ -1,5 +1,5 @@
/** 布局配置 */ /** 布局配置 */
interface ILayoutSettings { interface LayoutSettings {
/** 是否显示 Settings Panel */ /** 是否显示 Settings Panel */
showSettings: boolean showSettings: boolean
/** 是否显示标签栏 */ /** 是否显示标签栏 */
@ -20,7 +20,7 @@ interface ILayoutSettings {
showColorWeakness: boolean showColorWeakness: boolean
} }
const layoutSettings: ILayoutSettings = { const layoutSettings: LayoutSettings = {
showSettings: true, showSettings: true,
showTagsView: true, showTagsView: true,
fixedHeader: true, fixedHeader: true,

View File

@ -3,29 +3,29 @@ import { ref, onMounted } from "vue"
type OptionValueType = string | number type OptionValueType = string | number
/** Select 需要的数据格式 */ /** Select 需要的数据格式 */
interface ISelectOption { interface SelectOption {
value: OptionValueType value: OptionValueType
label: string label: string
disabled?: boolean disabled?: boolean
} }
/** 接口响应格式 */ /** 接口响应格式 */
interface IApiData { interface ApiData {
code: number code: number
data: ISelectOption[] data: SelectOption[]
message: string message: string
} }
/** 入参格式,暂时只需要传递 api 函数即可 */ /** 入参格式,暂时只需要传递 api 函数即可 */
interface IFetchSelectProps { interface FetchSelectProps {
api: () => Promise<IApiData> api: () => Promise<ApiData>
} }
export function useFetchSelect(props: IFetchSelectProps) { export function useFetchSelect(props: FetchSelectProps) {
const { api } = props const { api } = props
const loading = ref<boolean>(false) const loading = ref<boolean>(false)
const options = ref<ISelectOption[]>([]) const options = ref<SelectOption[]>([])
const value = ref<OptionValueType>("") const value = ref<OptionValueType>("")
/** 调用接口获取数据 */ /** 调用接口获取数据 */

View File

@ -5,11 +5,11 @@ const defaultOptions = {
text: "加载中..." text: "加载中..."
} }
interface ILoadingInstance { interface LoadingInstance {
close: () => void close: () => void
} }
interface IUseFullscreenLoading { interface UseFullscreenLoading {
<T extends (...args: any[]) => ReturnType<T>>(fn: T, options?: LoadingOptions): ( <T extends (...args: any[]) => ReturnType<T>>(fn: T, options?: LoadingOptions): (
...args: Parameters<T> ...args: Parameters<T>
) => Promise<ReturnType<T>> | ReturnType<T> ) => Promise<ReturnType<T>> | ReturnType<T>
@ -25,8 +25,8 @@ interface IUseFullscreenLoading {
* @param options LoadingOptions * @param options LoadingOptions
* @returns Function * @returns Function
*/ */
export const useFullscreenLoading: IUseFullscreenLoading = (fn, options = {}) => { export const useFullscreenLoading: UseFullscreenLoading = (fn, options = {}) => {
let loadingInstance: ILoadingInstance let loadingInstance: LoadingInstance
const showLoading = (options: LoadingOptions) => { const showLoading = (options: LoadingOptions) => {
loadingInstance = ElLoading.service(options) loadingInstance = ElLoading.service(options)
} }

View File

@ -1,6 +1,6 @@
import { reactive } from "vue" import { reactive } from "vue"
interface IDefaultPaginationData { interface DefaultPaginationData {
total: number total: number
currentPage: number currentPage: number
pageSizes: number[] pageSizes: number[]
@ -8,7 +8,7 @@ interface IDefaultPaginationData {
layout: string layout: string
} }
interface IPaginationData { interface PaginationData {
total?: number total?: number
currentPage?: number currentPage?: number
pageSizes?: number[] pageSizes?: number[]
@ -17,7 +17,7 @@ interface IPaginationData {
} }
/** 默认的分页参数 */ /** 默认的分页参数 */
const defaultPaginationData: IDefaultPaginationData = { const defaultPaginationData: DefaultPaginationData = {
total: 0, total: 0,
currentPage: 1, currentPage: 1,
pageSizes: [10, 20, 50], pageSizes: [10, 20, 50],
@ -25,7 +25,7 @@ const defaultPaginationData: IDefaultPaginationData = {
layout: "total, sizes, prev, pager, next, jumper" layout: "total, sizes, prev, pager, next, jumper"
} }
export function usePagination(initialPaginationData: IPaginationData = {}) { export function usePagination(initialPaginationData: PaginationData = {}) {
/** 合并分页参数 */ /** 合并分页参数 */
const paginationData = reactive({ ...defaultPaginationData, ...initialPaginationData }) const paginationData = reactive({ ...defaultPaginationData, ...initialPaginationData })
/** 改变当前页码 */ /** 改变当前页码 */

View File

@ -7,13 +7,13 @@ type DefaultThemeNameType = typeof DEFAULT_THEME_NAME
/** 注册的主题名称, 其中 DefaultThemeNameType 是必填的 */ /** 注册的主题名称, 其中 DefaultThemeNameType 是必填的 */
export type ThemeName = DefaultThemeNameType | "dark" | "dark-blue" export type ThemeName = DefaultThemeNameType | "dark" | "dark-blue"
interface IThemeList { interface ThemeList {
title: string title: string
name: ThemeName name: ThemeName
} }
/** 主题列表 */ /** 主题列表 */
const themeList: IThemeList[] = [ const themeList: ThemeList[] = [
{ {
title: "默认", title: "默认",
name: DEFAULT_THEME_NAME name: DEFAULT_THEME_NAME

View File

@ -7,13 +7,13 @@ export enum DeviceType {
Desktop Desktop
} }
interface ISidebar { interface Sidebar {
opened: boolean opened: boolean
withoutAnimation: boolean withoutAnimation: boolean
} }
export const useAppStore = defineStore("app", () => { export const useAppStore = defineStore("app", () => {
const sidebar: ISidebar = reactive({ const sidebar: Sidebar = reactive({
opened: getSidebarStatus() !== "closed", opened: getSidebarStatus() !== "closed",
withoutAnimation: false withoutAnimation: false
}) })

View File

@ -6,7 +6,7 @@ import { useTagsViewStore } from "./tags-view"
import { getToken, removeToken, setToken } from "@/utils/cache/cookies" import { getToken, removeToken, setToken } from "@/utils/cache/cookies"
import router, { resetRouter } from "@/router" import router, { resetRouter } from "@/router"
import { loginApi, getUserInfoApi } from "@/api/login" import { loginApi, getUserInfoApi } from "@/api/login"
import { type ILoginRequestData } from "@/api/login/types/login" import { type LoginRequestData } from "@/api/login/types/login"
import { type RouteRecordRaw } from "vue-router" import { type RouteRecordRaw } from "vue-router"
import asyncRouteSettings from "@/config/async-route" import asyncRouteSettings from "@/config/async-route"
@ -23,7 +23,7 @@ export const useUserStore = defineStore("user", () => {
roles.value = value roles.value = value
} }
/** 登录 */ /** 登录 */
const login = (loginData: ILoginRequestData) => { const login = (loginData: LoginRequestData) => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
loginApi({ loginApi({
username: loginData.username, username: loginData.username,

View File

@ -6,7 +6,7 @@ import { User, Lock, Key, Picture, Loading } from "@element-plus/icons-vue"
import ThemeSwitch from "@/components/ThemeSwitch/index.vue" import ThemeSwitch from "@/components/ThemeSwitch/index.vue"
import { type FormInstance, FormRules } from "element-plus" import { type FormInstance, FormRules } from "element-plus"
import { getLoginCodeApi } from "@/api/login" import { getLoginCodeApi } from "@/api/login"
import { type ILoginRequestData } from "@/api/login/types/login" import { type LoginRequestData } from "@/api/login/types/login"
const router = useRouter() const router = useRouter()
const loginFormRef = ref<FormInstance | null>(null) const loginFormRef = ref<FormInstance | null>(null)
@ -16,7 +16,7 @@ const loading = ref(false)
/** 验证码图片 URL */ /** 验证码图片 URL */
const codeUrl = ref("") const codeUrl = ref("")
/** 登录表单数据 */ /** 登录表单数据 */
const loginForm: ILoginRequestData = reactive({ const loginForm: LoginRequestData = reactive({
username: "admin", username: "admin",
password: "12345678", password: "12345678",
code: "" code: ""

View File

@ -1,7 +1,7 @@
<script lang="ts" setup> <script lang="ts" setup>
import { reactive, ref, watch } from "vue" import { reactive, ref, watch } from "vue"
import { createTableDataApi, deleteTableDataApi, updateTableDataApi, getTableDataApi } from "@/api/table" import { createTableDataApi, deleteTableDataApi, updateTableDataApi, getTableDataApi } from "@/api/table"
import { type IGetTableData } from "@/api/table/types/table" import { type GetTableData } from "@/api/table/types/table"
import { type FormInstance, type FormRules, ElMessage, ElMessageBox } from "element-plus" import { type FormInstance, type FormRules, ElMessage, ElMessageBox } from "element-plus"
import { Search, Refresh, CirclePlus, Delete, Download, RefreshRight } from "@element-plus/icons-vue" import { Search, Refresh, CirclePlus, Delete, Download, RefreshRight } from "@element-plus/icons-vue"
import { usePagination } from "@/hooks/usePagination" import { usePagination } from "@/hooks/usePagination"
@ -59,7 +59,7 @@ const resetForm = () => {
//#endregion //#endregion
//#region //#region
const handleDelete = (row: IGetTableData) => { const handleDelete = (row: GetTableData) => {
ElMessageBox.confirm(`正在删除用户:${row.username},确认删除?`, "提示", { ElMessageBox.confirm(`正在删除用户:${row.username},确认删除?`, "提示", {
confirmButtonText: "确定", confirmButtonText: "确定",
cancelButtonText: "取消", cancelButtonText: "取消",
@ -75,7 +75,7 @@ const handleDelete = (row: IGetTableData) => {
//#region //#region
const currentUpdateId = ref<undefined | string>(undefined) const currentUpdateId = ref<undefined | string>(undefined)
const handleUpdate = (row: IGetTableData) => { const handleUpdate = (row: GetTableData) => {
currentUpdateId.value = row.id currentUpdateId.value = row.id
formData.username = row.username formData.username = row.username
dialogVisible.value = true dialogVisible.value = true
@ -83,7 +83,7 @@ const handleUpdate = (row: IGetTableData) => {
//#endregion //#endregion
//#region //#region
const tableData = ref<IGetTableData[]>([]) const tableData = ref<GetTableData[]>([])
const searchFormRef = ref<FormInstance | null>(null) const searchFormRef = ref<FormInstance | null>(null)
const searchData = reactive({ const searchData = reactive({
username: "", username: "",

View File

@ -21,7 +21,7 @@ defineOptions({
}) })
//#region vxe-grid //#region vxe-grid
interface IRowMeta { interface RowMeta {
id: string id: string
username: string username: string
roles: string roles: string
@ -141,7 +141,7 @@ const xGridOpt: VxeGridProps = reactive({
crudStore.clearTable() crudStore.clearTable()
return new Promise<any>((resolve: Function) => { return new Promise<any>((resolve: Function) => {
let total = 0 let total = 0
let result: IRowMeta[] = [] let result: RowMeta[] = []
/** 加载数据 */ /** 加载数据 */
const callback = (res: GetTableResponseData) => { const callback = (res: GetTableResponseData) => {
if (res && res.data) { if (res && res.data) {
@ -269,7 +269,7 @@ const crudStore = reactive({
/** 清空表格数据 */ /** 清空表格数据 */
clearTable: () => xGridDom.value?.reloadData([]), clearTable: () => xGridDom.value?.reloadData([]),
/** 点击显示弹窗 */ /** 点击显示弹窗 */
onShowModal: (row?: IRowMeta) => { onShowModal: (row?: RowMeta) => {
if (row) { if (row) {
crudStore.isUpdate = true crudStore.isUpdate = true
xModalOpt.title = "修改用户" xModalOpt.title = "修改用户"
@ -325,7 +325,7 @@ const crudStore = reactive({
} }
}, },
/** 删除 */ /** 删除 */
onDelete: (row: IRowMeta) => { onDelete: (row: RowMeta) => {
const tip = `确定 <strong style='color:red;'>删除</strong> 用户 <strong style='color:#409eff;'>${row.username}</strong> ` const tip = `确定 <strong style='color:red;'>删除</strong> 用户 <strong style='color:#409eff;'>${row.username}</strong> `
const config: ElMessageBoxOptions = { const config: ElMessageBoxOptions = {
type: "warning", type: "warning",
@ -350,7 +350,7 @@ const crudStore = reactive({
}, },
/** 删除后是否返回上一页 */ /** 删除后是否返回上一页 */
afterDelete: () => { afterDelete: () => {
const tableData: IRowMeta[] = xGridDom.value!.getData() const tableData: RowMeta[] = xGridDom.value!.getData()
const pager: VxeGridPropTypes.ProxyAjaxQueryPageParams = xGridDom.value?.getProxyInfo()?.pager const pager: VxeGridPropTypes.ProxyAjaxQueryPageParams = xGridDom.value?.getProxyInfo()?.pager
if (pager && pager.currentPage > 1 && tableData.length === 1) { if (pager && pager.currentPage > 1 && tableData.length === 1) {
--pager.currentPage --pager.currentPage

2
types/api.d.ts vendored
View File

@ -1,5 +1,5 @@
/** 所有 api 接口的响应数据都应该准守该格式 */ /** 所有 api 接口的响应数据都应该准守该格式 */
interface IApiResponseData<T> { interface ApiResponseData<T> {
code: number code: number
data: T data: T
message: string message: string