Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ApiSelect demo): add demo about ApiSelect's use #757

Merged
merged 3 commits into from
Jun 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions mock/demo/select-demo.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { MockMethod } from 'vite-plugin-mock';
import { resultSuccess } from '../_util';

const list: any[] = [];
const demoList = (() => {
const result: any[] = [];
const result = {
list: list,
};
for (let index = 0; index < 20; index++) {
result.push({
label: `选项${index}`,
value: `${index}`,
result.list.push({
name: `选项${index}`,
id: `${index}`,
});
}
return result;
Expand All @@ -15,8 +18,8 @@ const demoList = (() => {
export default [
{
url: '/basic-api/select/getDemoOptions',
timeout: 2000,
method: 'get',
timeout: 1000,
method: 'post',
response: ({ query }) => {
console.log(query);
return resultSuccess(demoList);
Expand Down
4 changes: 4 additions & 0 deletions src/api/demo/model/optionsModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ export interface DemoOptionsItem {
value: string;
}

export interface selectParams {
id: number | string;
}

/**
* @description: Request list return value
*/
Expand Down
5 changes: 3 additions & 2 deletions src/api/demo/select.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { defHttp } from '/@/utils/http/axios';
import { DemoOptionsItem } from './model/optionsModel';
import { DemoOptionsItem, selectParams } from './model/optionsModel';
enum Api {
OPTIONS_LIST = '/select/getDemoOptions',
}

/**
* @description: Get sample options value
*/
export const optionsListApi = () => defHttp.get<DemoOptionsItem[]>({ url: Api.OPTIONS_LIST });
export const optionsListApi = (params?: selectParams) =>
defHttp.post<DemoOptionsItem[]>({ url: Api.OPTIONS_LIST, params });
28 changes: 28 additions & 0 deletions src/views/demo/form/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -272,11 +272,39 @@
label: '远程下拉',
required: true,
componentProps: {
// more details see /src/components/Form/src/components/ApiSelect.vue
api: optionsListApi,
params: {
id: 1,
},
// use [res.data.result.list] (no res.data.result) as options datas
// result: {
// list: [
// {
// name: "选项0",
// id: "0"
// },
// ]
// }
resultField: 'list',
// use name as label
labelField: 'name',
// use id as value
valueField: 'id',
// not request untill to select
immediate: false,
onChange: (e) => {
console.log('selected:', e);
},
// atfer request callback
onOptionsChange: (options) => {
console.log('get options', options.length, options);
},
},
colProps: {
span: 8,
},
// set default value
defaultValue: '0',
},
{
Expand Down