Commit 533d35c7 authored by 王玉鑫's avatar 王玉鑫

feat: 临时提交

parent 7f5f467b
......@@ -66,5 +66,6 @@ module.exports = {
},
],
'vue-scoped-css/require-v-deep-argument': 'off',
'vue/no-v-html': 'off',
},
};
import { useQueryList } from '@/composable/useQueryList.ts';
import { ref, type Ref, watchEffect, computed } from 'vue';
import { ref, type Ref, watchEffect, computed, nextTick, } from 'vue';
import { RequestUrl } from '@/types/api.ts';
import type { CommonListResp, CommonListParams } from '@/types/common';
import type { RouteName } from '@/router/router.ts';
......@@ -7,14 +7,25 @@ import { useRoute } from 'vue-router';
import { useRequest } from './useRequest.ts';
import { useJump } from './useJump.ts';
type CurrentUrl = RequestUrl | { target: RequestUrl };
export function useListView<
T extends { id: number; [index: string]: any },
C extends Record<any, any> & { name?: string },
>(url: RequestUrl) {
>(url: CurrentUrl) {
const { open, router } = useJump();
const { request: requestList } = useRequest<CommonListResp<T>, CommonListParams<C>>(url, {
const getCurrentUrl = () => {
if (typeof url === 'string') {
return url;
} else {
return url.target;
}
};
const { request: requestList } = useRequest<CommonListResp<T>, CommonListParams<C>>(
getCurrentUrl(),
{
method: 'POST',
});
},
);
const { pageNum, pageSize, totalCount, queryList, initPagination } = useQueryList<T, C>(
requestList,
......@@ -43,8 +54,7 @@ export function useListView<
watchEffect(async () => {
try {
console.log(url);
const { data } = await queryList(searchParams.value || {});
const { data } = await queryList(searchParams.value || {}, getCurrentUrl());
handleUrlClear();
datas.value = data.records;
} catch (error) {
......@@ -72,7 +82,9 @@ export function useListView<
for (const item of selectList.value) {
temp[item.key] = item.value;
}
if (currentName.value) {
temp.name = currentName.value;
}
initPagination();
searchParams.value = temp;
};
......@@ -81,9 +93,13 @@ export function useListView<
* 名称搜索
*/
const handleNameSearch = (params: { value: { key: string; value: string }[] }) => {
nextTick(() => {
currentName.value = params.value[0].value;
if (currentName.value) {
searchParams.value.name = currentName.value;
}
initPagination();
});
};
return {
......
......@@ -4,7 +4,10 @@ import type { CommonListParams, CommonListResp } from '@/types/common';
import type { ResponseData } from './useRequest.ts';
import { useMessage } from './useMessage.ts';
export type QueryFn<T, C> = (params: C) => Promise<ResponseData<CommonListResp<T>>>;
export type QueryFn<T, C> = (
params: C,
specialUrl?: string,
) => Promise<ResponseData<CommonListResp<T>>>;
interface Pagination {
size?: number;
......@@ -55,12 +58,12 @@ export function useQueryList<T, C>(queryFn: QueryFn<T, CommonListParams<C>>) {
};
};
const queryList = (params: C, reload = false) => {
const queryList = (params: C, specialUrl = '', reload = false) => {
if (reload) {
initPagination();
}
return queryFn(assignPageParams(params)).then((res) => {
return queryFn(assignPageParams(params), specialUrl).then((res) => {
const { success, msg, data } = res;
if (success) {
if (!isUndefined(data.total)) {
......
......@@ -83,7 +83,7 @@ export function useRequest<T = Record<any, any>, P = Record<any, any>>(
) {
const appStore = useAppStore();
const request = (params: P = {} as P) => {
const request = (params: P = {} as P, specialUrl = '') => {
const publicKey =
'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDfGTt8qny6pipLYYhBVAIGZ6CgMdmYCVPy3bAi8AO1MvOD3Pba1OxLSEvtctOmcibO6NL5NZgQrsTjfu1RMSJkwv1vY/GsKH4c/fbmd3QPhuKUZNHQhTMicbeGFadMM2xRkBkZDjeakemqTdLQFnkRFSeE35GKRkBBimOm4YWBQwIDAQAB';
const uuid = generateRandomStr(16);
......@@ -94,7 +94,7 @@ export function useRequest<T = Record<any, any>, P = Record<any, any>>(
const paramsConfig = config.method === 'GET' ? { params } : { data: params };
return requestInstance.request<T, ResponseData<T>>({
url: `${url}/${path}`,
url: `${specialUrl || url}/${path}`,
...paramsConfig,
...config,
headers: {
......
......@@ -83,7 +83,7 @@
</template>
<script lang="ts" setup>
import { ref } from 'vue';
import { computed, markRaw, ref, shallowRef } from 'vue';
// import { useRequest } from '@/composable/useRequest.ts';
import { RequestUrl } from '@/types/api.ts';
import { useListView } from '@/composable/useListView.ts';
......@@ -148,6 +148,10 @@ const tabList = ref<tabItem[]>([
const activeTab = ref<number>(0);
const currentUrl = computed(() => {
return tabList.value[activeTab.value].apiURL;
});
// let requestFn: any = null;
// const request = (url: any) => {
......@@ -157,20 +161,9 @@ const activeTab = ref<number>(0);
// requestFn = r.request;
// };
// const requestAPI:any = RequestUrl.developZoneList
const { pageNum, pageSize, totalCount, datas, handleDetail, queryList } = useListView(
tabList.value[activeTab.value].apiURL,
const { pageNum, pageSize, totalCount, datas, handleDetail, handleFilterChange } = useListView(
shallowRef({ target: currentUrl }),
);
// 处理筛选条件
const handleFilterChange = async (selectList: any) => {
const temp: any = {};
for (const item of selectList.value) {
temp[item.key] = item.value;
}
pageNum.value = 1;
const { data } = await queryList(temp);
datas.value = data.records;
};
</script>
<style lang="scss" scoped>
.container-left p {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment