Commit 5fb3dcba authored by 水落(YangLei)'s avatar 水落(YangLei)

feat: 代码优化

parent 799f3e81
......@@ -24,6 +24,8 @@ export default {
request: Function,
formatData: { type: Object, default: undefined },
getName: Function,
labelFiled: String, // 和 formatData 一样 传一种就行了
valueFiled: String,
},
data() {
return {
......@@ -34,6 +36,9 @@ export default {
if (this.request) {
const newArr = await this.request();
this.data = this.formatData ? await formatObj(newArr, this.formatData) : newArr;
this.data = this.labelFiled
? formatObj(newArr, { label: this.labelFiled, value: this.valueFiled, key: this.valueFiled })
: this.data;
}
},
methods: {
......
......@@ -21,8 +21,9 @@ export default {
props: {
url: String,
searchField: String,
formatData: Object,
mode: String,
labelFiled: String,
valueFiled: String,
},
model: {
prop: 'value',
......@@ -38,10 +39,11 @@ export default {
},
methods: {
async getData(searchString) {
this.options = formatObj(
await getReq(this.url, { [this.searchField]: searchString }),
this.formatData,
);
this.options = formatObj(await getReq(this.url, { [this.searchField]: searchString }), {
label: this.labelFiled,
value: this.valueFiled,
key: this.valueFiled,
});
},
handleSearch(value) {
if (this.timeOut) clearTimeout(this.timeOut);
......
export const areaFormatData = {
label: 'regionName',
value: 'regionId',
key: 'regionId',
};
export const statusFormtData = {
label: 'paramName',
value: 'paramValue',
key: 'paramValue',
};
export const banZuFormatData = {
label: 'paramName',
value: 'paramValue',
key: 'paramValue',
};
......@@ -4,8 +4,9 @@
<a-form-model-item label="地区" prop="regionId">
<RequestSelect
:request="getAreaListDataApi"
:formatData="areaFormatData"
v-model="form.regionId"
labelFiled="regionName"
valueFiled="regionId"
/>
</a-form-model-item>
......@@ -21,8 +22,9 @@
<a-form-model-item label="班组" prop="shiftType">
<RequestSelect
:request="getBanZuListApi"
:formatData="banZuFormatData"
v-model="form.shiftType"
labelFiled="paramName"
valueFiled="paramValue"
/>
</a-form-model-item>
......@@ -39,7 +41,8 @@
<SearchSelect
url="/api/v1/users/searching"
searchField="userName"
:formatData="formatXunJianRenData"
labelFiled="userName"
valueFiled="userId"
v-model="form.inspectionIdList"
mode="multiple"
/>
......@@ -54,7 +57,6 @@ import RequestSelect from '@/components/MySelect/RequestSelect.vue';
import SearchSelect from '@/components/MySelect/search_select.vue';
import UrlSelect from '@/components/MySelect/url_select.vue';
import { getAreaListDataApi, getBanZuListApi, addXunJianTaskApi } from '@/api';
import { areaFormatData, banZuFormatData } from './common';
export default {
props: {
......@@ -65,7 +67,6 @@ export default {
data() {
return {
getAreaListDataApi,
banZuFormatData,
getBanZuListApi,
form: {},
rules: {
......@@ -75,12 +76,6 @@ export default {
routeId: [{ required: true }],
regionId: [{ required: true }],
},
areaFormatData,
formatXunJianRenData: {
value: 'userId',
label: 'userName',
key: 'userId',
},
};
},
computed: {
......
......@@ -19,57 +19,73 @@
<a-date-picker
class="tw-w-full"
show-time
v-model="query.startTime"
v-model="query.endTime"
valueFormat="YYYY-MM-DD HH:mm:ss"
/>
</my-form-item>
<my-form-item label="地区">
<RequestSelect
:request="getAreaListDataApi"
:formatData="areaFormatData"
v-model="query.regionId"
labelFiled="regionName"
valueFiled="regionId"
/>
</my-form-item>
<my-form-item label="专业">
<RequestSelect
:request="getAreaListDataApi"
:formatData="areaFormatData"
v-model="query.regionId"
<UrlSelect
:url="
query.regionId
? `/ranger/inspection/api/v1/specialities/valid/regions/${query.regionId}/list`
: ''
"
v-model="query.specialityId"
labelFiled="specialityName"
valueFiled="specialityId"
/>
</my-form-item>
<my-form-item label="线路">
<RequestSelect
:request="getAreaListDataApi"
:formatData="areaFormatData"
v-model="query.regionId"
<UrlSelect
:url="
query.regionId
? `/ranger/inspection/api/v1/routes/regions/${query.regionId}/list`
: ''
"
labelFiled="routeName"
valueFiled="routeId"
v-model="query.routeId"
/>
</my-form-item>
<my-form-item label="班组">
<RequestSelect
:request="getBanZuListApi"
:formatData="banZuFormatData"
v-model="query.shiftType"
labelFiled="paramName"
valueFiled="paramValue"
/>
</my-form-item>
<my-form-item label="巡检状态">
<RequestSelect
:request="getBusinessListApi"
:formatData="statusFormtData"
v-model="query.inspectionState"
labelFiled="paramName"
valueFiled="paramValue"
/>
</my-form-item>
<my-form-item label="任务类型">
<RequestSelect
:request="getTaskTypeApi"
:formatData="taskTypeFormatData"
v-model="query.jobType"
labelFiled="paramName"
valueFiled="paramValue"
/>
</my-form-item>
<my-form-item label="巡检人">
<RequestSelect
:request="getBusinessListApi"
:formatData="statusFormtData"
<SearchSelect
url="/api/v1/users/searching"
searchField="userName"
v-model="query.lastInspectionStaffId"
labelFiled="userName"
valueFiled="userId"
/>
</my-form-item>
</template>
......@@ -98,20 +114,20 @@
<script>
import Table from '@/components/table/table.vue';
import Form from './form.vue';
import UrlSelect from '@/components/MySelect/url_select.vue';
import { getXunJianDownloadUrlApi } from '@/api';
import { downloadFileByUrl } from '@/utils';
import RequestSelect from '@/components/MySelect/RequestSelect.vue';
import SearchSelect from '@/components/MySelect/search_select.vue';
import { getAreaListDataApi, getBusinessListApi, getBanZuListApi, getTaskTypeApi } from '@/api';
import { areaFormatData, statusFormtData, banZuFormatData } from './common';
export default {
components: { Table, Form, RequestSelect },
components: { Table, Form, RequestSelect, UrlSelect, SearchSelect },
data() {
return {
getAreaListDataApi,
getBusinessListApi,
getBanZuListApi,
banZuFormatData,
getTaskTypeApi,
addBtn: {
title: '新建临时任务',
......@@ -124,13 +140,6 @@ export default {
{ type: 'confirm' },
],
selected: [],
areaFormatData,
statusFormtData,
taskTypeFormatData: {
label: 'paramName',
value: 'paramValue',
key: 'paramValue',
},
};
},
methods: {
......
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