截止‘运力管理’模块

This commit is contained in:
2026-07-20 11:26:51 +08:00
parent e66b4a3680
commit c6dffb5d97
98 changed files with 19429 additions and 176 deletions

View File

@@ -0,0 +1,665 @@
<template>
<basic-container class="airport-master-page">
<avue-crud
:option="option"
:table-loading="loading"
:data="data"
v-model:page="page"
v-model="form"
ref="crud"
:permission="permissionList"
:before-open="beforeOpen"
@row-save="rowSave"
@row-update="rowUpdate"
@row-del="rowDel"
@search-change="searchChange"
@search-reset="searchReset"
@selection-change="selectionChange"
@current-change="currentChange"
@size-change="sizeChange"
@refresh-change="refreshChange"
@on-load="onLoad"
>
<template #menu-left>
<el-button
type="primary"
icon="el-icon-upload"
plain
v-if="hasPermission('airport_master_import')"
@click="handleImport"
>批量导入
</el-button>
<el-button
type="primary"
icon="el-icon-download"
plain
v-if="hasPermission('airport_master_template')"
@click="handleTemplate"
>下载模板
</el-button>
<el-button
type="primary"
icon="el-icon-download"
plain
v-if="hasPermission('airport_master_export')"
@click="handleExport"
>批量导出
</el-button>
<el-button
type="danger"
icon="el-icon-delete"
plain
v-if="hasPermission('airport_master_delete')"
@click="handleDelete"
>批量删除
</el-button>
</template>
<template #status="{ row }">
<el-tag :type="row.status === 1 ? 'primary' : 'info'">
{{ row.status === 1 ? '启用' : '停用' }}
</el-tag>
</template>
<template #menu="{ row, index }">
<el-button
type="primary"
text
icon="el-icon-edit"
v-if="hasPermission('airport_master_edit')"
@click="$refs.crud.rowEdit(row, index)"
>
编辑
</el-button>
<el-button
type="primary"
text
:icon="row.status === 1 ? 'el-icon-close' : 'el-icon-check'"
v-if="hasPermission('airport_master_status')"
@click="handleStatus(row)"
>
{{ row.status === 1 ? '停用' : '启用' }}
</el-button>
</template>
</avue-crud>
<el-dialog title="空港机场主数据导入" append-to-body v-model="excelBox" width="555px">
<avue-form
:option="excelOption"
v-model="excelForm"
:upload-before="uploadBefore"
:upload-after="uploadAfter"
>
<template #excelTemplate>
<el-button type="primary" @click="handleTemplate">
点击下载<i class="el-icon-download el-icon--right"></i>
</el-button>
</template>
</avue-form>
</el-dialog>
</basic-container>
</template>
<script>
import { getList, getDetail, submit, remove, changeStatus } from '@/api/base/airport-master';
import { getLazyTree } from '@/api/base/region';
import { exportBlob } from '@/api/common';
import { mapGetters } from 'vuex';
import { downloadXls } from '@/utils/util';
import { formatUpdateUserName } from '@/utils/audit';
import { getToken } from '@/utils/auth';
import NProgress from 'nprogress';
import 'nprogress/nprogress.css';
export default {
data() {
const validateIataCode = (rule, value, callback) => {
if (!/^[A-Z]{3}$/.test(String(value || '').toUpperCase())) {
callback(new Error('IATA编码为3位大写字母'));
} else {
callback();
}
};
const validateIcaoCode = (rule, value, callback) => {
if (!/^[A-Z]{4}$/.test(String(value || '').toUpperCase())) {
callback(new Error('ICAO代码为4位大写字母'));
} else {
callback();
}
};
const validateLongitude = (rule, value, callback) => {
if (value === undefined || value === null || value === '') {
callback();
} else if (Number(value) < -180 || Number(value) > 180) {
callback(new Error('经度范围为 -180 到 180'));
} else {
callback();
}
};
const validateLatitude = (rule, value, callback) => {
if (value === undefined || value === null || value === '') {
callback();
} else if (Number(value) < -90 || Number(value) > 90) {
callback(new Error('纬度范围为 -90 到 90'));
} else {
callback();
}
};
return {
form: {},
query: {},
loading: true,
data: [],
excelBox: false,
excelForm: {},
provinceOptions: [],
cityOptions: [],
page: {
pageSize: 10,
pageSizes: [10, 20, 50, 100],
currentPage: 1,
total: 0,
},
selectionList: [],
option: {
height: 'auto',
calcHeight: 32,
dialogWidth: 980,
tip: false,
searchShow: true,
searchMenuSpan: 6,
border: true,
index: true,
indexLabel: '序号',
indexWidth: 70,
viewBtn: false,
delBtn: false,
editBtn: false,
selection: true,
dialogClickModal: false,
menuWidth: 160,
column: [
{
label: '编码',
prop: 'code',
search: true,
addDisabled: true,
editDisabled: true,
placeholder: '系统自动生成',
searchPlaceholder: '请输入编码',
},
{
label: 'IATA编码',
prop: 'iataCode',
minWidth: 120,
maxlength: 3,
rules: [
{ required: true, message: '请输入IATA编码', trigger: 'blur' },
{ validator: validateIataCode, trigger: 'blur' },
],
change: ({ value }) => this.handleIataChange(value),
blur: ({ value }) => this.handleIataChange(value),
},
{
label: 'ICAO代码',
prop: 'icaoCode',
minWidth: 100,
maxlength: 4,
rules: [
{ required: true, message: '请输入ICAO代码', trigger: 'blur' },
{ validator: validateIcaoCode, trigger: 'blur' },
],
change: ({ value }) => this.handleIcaoChange(value),
blur: ({ value }) => this.handleIcaoChange(value),
},
{
label: '机场标准名称',
prop: 'name',
minWidth: 180,
search: true,
rules: [{ required: true, message: '请输入机场标准名称', trigger: 'blur' }],
},
{
label: '机场简称',
prop: 'shortName',
minWidth: 130,
},
{
label: '所属省份',
prop: 'provinceCode',
type: 'select',
minWidth: 120,
hide: true,
props: {
label: 'title',
value: 'id',
},
dicData: [],
filterable: true,
rules: [{ required: true, message: '请选择省份', trigger: 'change' }],
change: ({ value }) => this.handleProvinceChange(value),
},
{
label: '所属省份',
prop: 'provinceName',
minWidth: 140,
addDisplay: false,
editDisplay: false,
},
{
label: '所属城市',
prop: 'cityCode',
type: 'select',
minWidth: 120,
hide: true,
props: {
label: 'title',
value: 'id',
},
dicData: [],
filterable: true,
rules: [{ required: true, message: '请选择城市', trigger: 'change' }],
change: ({ value }) => this.handleCityChange(value),
},
{
label: '所属城市',
prop: 'cityName',
minWidth: 140,
addDisplay: false,
editDisplay: false,
},
{
label: '经度',
prop: 'longitude',
type: 'number',
precision: 6,
rules: [{ validator: validateLongitude, trigger: 'blur' }],
},
{
label: '纬度',
prop: 'latitude',
type: 'number',
precision: 6,
rules: [{ validator: validateLatitude, trigger: 'blur' }],
},
{
label: '数据来源',
prop: 'dataSource',
type: 'select',
search: true,
dicData: [
{ label: '全部', value: '' },
{ label: '初始导入', value: '初始导入' },
{ label: '批量导入', value: '批量导入' },
{ label: '手动录入', value: '手动录入' },
],
},
{
label: '启停状态',
prop: 'status',
type: 'select',
search: true,
slot: true,
dataType: 'number',
dicData: [
{ label: '全部', value: '' },
{ label: '启用', value: 1 },
{ label: '停用', value: 2 },
],
},
{
label: '备注',
prop: 'remark',
type: 'textarea',
minRows: 4,
span: 24,
hide: true,
maxlength: 200,
showWordLimit: true,
rules: [{ max: 200, message: '备注不能超过200字', trigger: 'blur' }],
},
{
label: '更新人',
prop: 'updateUserName',
formatter: formatUpdateUserName,
addDisplay: false,
editDisplay: false,
minWidth: 120,
},
{
label: '更新时间',
prop: 'updateTime',
type: 'datetime',
format: 'YYYY-MM-DD HH:mm:ss',
valueFormat: 'YYYY-MM-DD HH:mm:ss',
addDisplay: false,
editDisplay: false,
display: false,
minWidth: 160,
},
{
label: '创建时间',
prop: 'createTime',
type: 'datetime',
format: 'YYYY-MM-DD HH:mm:ss',
valueFormat: 'YYYY-MM-DD HH:mm:ss',
addDisplay: false,
editDisplay: false,
display: false,
minWidth: 160,
},
],
},
excelOption: {
submitBtn: false,
emptyBtn: false,
column: [
{
label: '模板上传',
prop: 'excelFile',
type: 'upload',
drag: true,
loadText: '模板上传中,请稍等',
span: 24,
propsHttp: {
res: 'data',
},
tip: '请上传 .xls,.xlsx 标准格式文件',
accept: '.xls,.xlsx',
action: '/blade-system/airport-master/import-airport-master',
},
{
label: '模板下载',
prop: 'excelTemplate',
formslot: true,
span: 24,
},
],
},
};
},
computed: {
...mapGetters(['permission', 'userInfo']),
permissionList() {
return {
addBtn: this.hasPermission('airport_master_add'),
};
},
isAdmin() {
const authority = this.userInfo && this.userInfo.authority;
return Array.isArray(authority) ? authority.includes('admin') : String(authority || '').includes('admin');
},
ids() {
let ids = [];
this.selectionList.forEach(ele => {
ids.push(ele.id);
});
return ids.join(',');
},
},
created() {
this.loadProvinceOptions();
},
methods: {
hasPermission(code) {
return this.isAdmin || this.validData(this.permission && this.permission[code], false);
},
findColumn(prop) {
return this.option.column.find(item => item.prop === prop);
},
loadProvinceOptions() {
getLazyTree('00').then(res => {
this.provinceOptions = res.data.data;
this.findColumn('provinceCode').dicData = this.provinceOptions;
});
},
loadCityOptions(provinceCode) {
if (!provinceCode) {
this.cityOptions = [];
this.findColumn('cityCode').dicData = [];
return Promise.resolve();
}
return getLazyTree(provinceCode).then(res => {
this.cityOptions = res.data.data;
this.findColumn('cityCode').dicData = this.cityOptions;
});
},
handleIataChange(value) {
this.form.iataCode = String(value || '')
.toUpperCase()
.replace(/[^A-Z]/g, '')
.slice(0, 3);
this.form.code = this.form.iataCode ? `JC-${this.form.iataCode}` : '';
},
handleIcaoChange(value) {
this.form.icaoCode = String(value || '')
.toUpperCase()
.replace(/[^A-Z]/g, '')
.slice(0, 4);
},
handleProvinceChange(value) {
const province = this.provinceOptions.find(item => item.id === value);
this.form.provinceName = province ? province.title : '';
this.form.cityCode = undefined;
this.form.cityName = '';
this.loadCityOptions(value);
},
handleCityChange(value) {
const city = this.cityOptions.find(item => item.id === value);
this.form.cityName = city ? city.title : '';
},
normalizeRow(row) {
row.code = row.iataCode ? `JC-${row.iataCode}` : row.code;
if (!row.dataSource) row.dataSource = '手动录入';
if (!row.status) row.status = 1;
return row;
},
validateUnique(row) {
const rowId = String(row.id || '');
const hasDuplicate = (params, prop) => {
return getList(1, 10, params).then(res => {
const records = res.data.data.records || [];
return records.some(item => item[prop] === row[prop] && String(item.id || '') !== rowId);
});
};
return Promise.all([
hasDuplicate({ iataCode: row.iataCode }, 'iataCode'),
hasDuplicate({ icaoCode: row.icaoCode }, 'icaoCode'),
]).then(([iataExists, icaoExists]) => {
if (iataExists) {
return Promise.reject(new Error('该IATA编码已存在'));
}
if (icaoExists) {
return Promise.reject(new Error('该ICAO代码已存在'));
}
return Promise.resolve();
});
},
handleSubmitError(error, loading) {
const uniqueMessages = ['该IATA编码已存在', '该ICAO代码已存在'];
if (uniqueMessages.includes(error.message)) {
this.$message.warning(error.message);
}
window.console.log(error);
loading();
},
rowSave(row, done, loading) {
const submitRow = this.normalizeRow(row);
this.validateUnique(submitRow)
.then(() => submit(submitRow))
.then(() => {
this.onLoad(this.page);
this.$message({ type: 'success', message: '操作成功!' });
done();
})
.catch(error => this.handleSubmitError(error, loading));
},
rowUpdate(row, index, done, loading) {
const submitRow = this.normalizeRow(row);
this.validateUnique(submitRow)
.then(() => submit(submitRow))
.then(() => {
this.onLoad(this.page);
this.$message({ type: 'success', message: '操作成功!' });
done();
})
.catch(error => this.handleSubmitError(error, loading));
},
rowDel(row) {
this.$confirm('确定将选择数据删除?', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
})
.then(() => remove(row.id))
.then(() => {
this.onLoad(this.page);
this.$message({ type: 'success', message: '操作成功!' });
});
},
handleDelete() {
if (this.selectionList.length === 0) {
this.$message.warning('请选择至少一条数据');
return;
}
this.$confirm('确定将选择数据删除?', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
})
.then(() => remove(this.ids))
.then(() => {
this.onLoad(this.page);
this.$message({ type: 'success', message: '操作成功!' });
this.$refs.crud.toggleSelection();
});
},
handleStatus(row) {
const nextStatus = row.status === 1 ? 2 : 1;
const actionName = nextStatus === 1 ? '启用' : '停用';
this.$confirm(`是否确认${actionName}该条数据?`, {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
})
.then(() => changeStatus(row.id, nextStatus))
.then(() => {
this.onLoad(this.page);
this.$message({ type: 'success', message: '操作成功!' });
});
},
beforeOpen(done, type) {
if (['edit', 'view'].includes(type)) {
getDetail(this.form.id).then(res => {
this.form = res.data.data;
this.loadCityOptions(this.form.provinceCode).then(() => done());
});
return;
}
this.form.code = '';
this.form.dataSource = '手动录入';
this.form.status = 1;
this.loadCityOptions(this.form.provinceCode).then(() => done());
},
searchReset() {
this.query = {};
this.onLoad(this.page);
},
searchChange(params, done) {
this.query = params;
this.page.currentPage = 1;
this.onLoad(this.page, params);
done();
},
selectionChange(list) {
this.selectionList = list;
},
selectionClear() {
this.selectionList = [];
this.$refs.crud.toggleSelection();
},
currentChange(currentPage) {
this.page.currentPage = currentPage;
},
sizeChange(pageSize) {
this.page.pageSize = pageSize;
},
refreshChange() {
this.onLoad(this.page, this.query);
},
onLoad(page, params = {}) {
this.loading = true;
getList(page.currentPage, page.pageSize, { ...params, ...this.query })
.then(res => {
const data = res.data.data;
this.page.total = data.total;
this.data = data.records;
this.selectionClear();
})
.finally(() => {
this.loading = false;
});
},
handleImport() {
this.excelBox = true;
},
uploadBefore(file, done) {
const fileName = file && file.name ? file.name.toLowerCase() : '';
if (!/\.(xls|xlsx)$/.test(fileName)) {
this.$message.error('请上传 .xls,.xlsx 标准格式文件');
return false;
}
if (typeof done === 'function') {
done();
}
return true;
},
uploadAfter(res, done) {
this.excelBox = false;
this.onLoad(this.page);
done();
},
handleExport() {
this.$confirm('是否导出空港机场主数据?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
}).then(() => {
NProgress.start();
exportBlob('/blade-system/airport-master/export-airport-master', this.buildExportParams())
.then(res => {
downloadXls(
res.data,
`空港机场主数据${this.$dayjs().format('YYYY-MM-DD HH:mm:ss')}.xlsx`
);
})
.finally(() => {
NProgress.done();
});
});
},
buildExportParams() {
return {
...this.query,
ids: this.ids,
[this.website.tokenHeader]: getToken(),
};
},
handleTemplate() {
exportBlob(
`/blade-system/airport-master/export-template?${this.website.tokenHeader}=${getToken()}`
).then(res => {
downloadXls(res.data, '空港机场主数据模板.xlsx');
});
},
},
};
</script>
<style lang="scss" scoped>
.airport-master-page {
:deep(.avue-crud__header),
:deep(.el-table th .cell),
:deep(.el-table td .cell) {
white-space: nowrap;
}
}
</style>

View File

@@ -0,0 +1,815 @@
<template>
<basic-container class="common-address-page">
<avue-crud
:option="option"
:table-loading="loading"
:data="data"
v-model:page="page"
v-model="form"
ref="crud"
:permission="permissionList"
:before-open="beforeOpen"
@row-save="rowSave"
@row-update="rowUpdate"
@row-del="rowDel"
@search-change="searchChange"
@search-reset="searchReset"
@selection-change="selectionChange"
@current-change="currentChange"
@size-change="sizeChange"
@refresh-change="refreshChange"
@on-load="onLoad"
>
<template #menu-left>
<el-button
type="primary"
icon="el-icon-plus"
plain
v-if="hasPermission('common_address_add')"
@click="$refs.crud.rowAdd()"
>新增
</el-button>
<el-button
type="primary"
icon="el-icon-download"
plain
v-if="hasPermission('common_address_export')"
@click="handleExport"
>批量导出
</el-button>
<el-button
type="danger"
icon="el-icon-delete"
plain
v-if="hasPermission('common_address_delete')"
@click="handleDelete"
>批量删除
</el-button>
<el-switch
v-if="canViewAllDept"
v-model="allDept"
class="common-address-page__scope"
active-text="全部组织"
inactive-text="当前组织"
:active-value="1"
:inactive-value="0"
@change="handleScopeChange"
/>
</template>
<template #siteCodeDisplay="{ row }">
<span>{{ row.addressType === '常规地址' ? '/' : row.siteCodeDisplay || row.siteCode }}</span>
</template>
<template #menu="{ row, index }">
<el-button
type="primary"
text
icon="el-icon-view"
v-if="hasPermission('common_address_view')"
@click="$refs.crud.rowView(row, index)"
>
查看
</el-button>
<el-button
type="primary"
text
icon="el-icon-edit"
v-if="hasPermission('common_address_edit') && !row.readonly"
@click="$refs.crud.rowEdit(row, index)"
>
编辑
</el-button>
<el-button
type="primary"
text
icon="el-icon-delete"
v-if="hasPermission('common_address_delete') && !row.readonly"
@click="rowDel(row)"
>
删除
</el-button>
</template>
<template #sourceId-form>
<el-select
v-model="form.sourceId"
filterable
remote
clearable
:remote-method="loadSourceOptions"
:loading="sourceLoading"
:disabled="dialogReadonly || form.addressType === '常规地址'"
placeholder="请选择来源主数据"
style="width: 100%"
@change="handleSourceChange"
>
<el-option
v-for="item in sourceOptions"
:key="item.sourceId"
:label="`${item.addressName}${item.siteCode}`"
:value="item.sourceId"
/>
</el-select>
</template>
<template #detailAddress-form>
<div class="common-address-page__address">
<el-input
v-model="form.detailAddress"
type="textarea"
:rows="3"
maxlength="255"
show-word-limit
:disabled="dialogReadonly || form.addressType !== '常规地址'"
/>
<el-button
icon="el-icon-location"
plain
:disabled="dialogReadonly || form.addressType !== '常规地址'"
@click="handleMapPick"
>
地图选点
</el-button>
</div>
</template>
</avue-crud>
<el-dialog
title="地图选点"
append-to-body
v-model="mapBox"
width="920px"
class="common-address-page__map-dialog"
@opened="initTiandituMap"
>
<div class="common-address-page__map-toolbar">
<el-input
v-model="mapKeyword"
clearable
placeholder="输入地址关键词"
@keyup.enter="searchMapKeyword"
/>
<el-button type="primary" icon="el-icon-search" :loading="mapLoading" @click="searchMapKeyword">
搜索
</el-button>
</div>
<div ref="tiandituMap" class="common-address-page__map"></div>
<div class="common-address-page__map-info">
<span>{{ mapStatus }}</span>
<span v-if="mapSelected.longitude">
经度{{ mapSelected.longitude }}纬度{{ mapSelected.latitude }}
</span>
</div>
<template #footer>
<el-button @click="mapBox = false">取消</el-button>
<el-button type="primary" :disabled="!mapSelected.longitude" @click="confirmMapPick">
确定
</el-button>
</template>
</el-dialog>
</basic-container>
</template>
<script>
import { getDetail, getList, getSourceOptions, remove, submit } from '@/api/base/common-address';
import { getDeptTree } from '@/api/system/dept';
import { exportBlob } from '@/api/common';
import { createOption } from '@/option/base/common-address';
import { mapGetters } from 'vuex';
import { downloadXls } from '@/utils/util';
import { getToken } from '@/utils/auth';
import NProgress from 'nprogress';
import 'nprogress/nprogress.css';
const TIANDITU_KEY = '71f234f251d4cb1feeb3c293a0f21709';
let tiandituLoader;
export default {
data() {
const validateLongitude = (rule, value, callback) => {
if (value === undefined || value === null || value === '') {
callback();
} else if (Number(value) < -180 || Number(value) > 180) {
callback(new Error('经度范围为 -180 到 180'));
} else {
callback();
}
};
const validateLatitude = (rule, value, callback) => {
if (value === undefined || value === null || value === '') {
callback();
} else if (Number(value) < -90 || Number(value) > 90) {
callback(new Error('纬度范围为 -90 到 90'));
} else {
callback();
}
};
return {
form: {},
query: {},
loading: true,
data: [],
allDept: 0,
dialogReadonly: false,
sourceLoading: false,
sourceOptions: [],
deptOptions: [],
mapBox: false,
mapLoading: false,
mapKeyword: '',
mapStatus: '可搜索地址或点击地图选点',
mapSelected: {},
tiandituMap: null,
tiandituMarker: null,
tiandituGeocoder: null,
tiandituClickHandler: null,
option: createOption({ validateLongitude, validateLatitude }),
page: {
pageSize: 10,
pageSizes: [10, 20, 50, 100],
currentPage: 1,
total: 0,
},
selectionList: [],
};
},
computed: {
...mapGetters(['permission', 'userInfo']),
permissionList() {
return {
addBtn: this.hasPermission('common_address_add'),
};
},
isAdmin() {
const authority = this.userInfo && this.userInfo.authority;
return Array.isArray(authority) ? authority.includes('admin') : String(authority || '').includes('admin');
},
canViewAllDept() {
return this.isAdmin;
},
ids() {
return this.selectionList.map(item => item.id).join(',');
},
},
created() {
this.initDeptTree();
},
methods: {
hasPermission(code) {
return this.isAdmin || this.validData(this.permission && this.permission[code], false);
},
initDeptTree() {
getDeptTree(this.userInfo.tenantId).then(res => {
this.deptOptions = this.flattenDept(res.data.data || []);
const deptColumn = this.findColumn(this.option.column, 'deptId');
deptColumn.dicData = this.deptOptions;
});
},
flattenDept(tree, level = 0) {
const result = [];
tree.forEach(item => {
result.push({
label: `${' '.repeat(level)}${item.title || item.deptName || item.name}`,
value: item.id,
rawLabel: item.title || item.deptName || item.name,
});
if (item.children && item.children.length) {
result.push(...this.flattenDept(item.children, level + 1));
}
});
return result;
},
handleScopeChange() {
if (!this.canViewAllDept) {
this.allDept = 0;
}
if (!this.allDept) {
this.query.deptId = undefined;
}
this.page.currentPage = 1;
this.onLoad(this.page);
},
loadSourceOptions(keyword = '') {
if (!this.form.addressType || this.form.addressType === '常规地址') {
this.sourceOptions = [];
return;
}
this.sourceLoading = true;
getSourceOptions(this.form.addressType, keyword)
.then(res => {
this.sourceOptions = res.data.data || [];
})
.finally(() => {
this.sourceLoading = false;
});
},
handleSourceChange(value) {
const source = this.sourceOptions.find(item => item.sourceId === value);
if (!source) return;
this.form.addressName = this.form.addressName || source.addressName;
this.form.siteCode = source.siteCode;
this.form.siteCodeDisplay = source.siteCode;
this.form.detailAddress = source.detailAddress;
this.form.regionName = source.regionName;
this.form.longitude = source.longitude;
this.form.latitude = source.latitude;
},
handleAddressTypeChange(value, reset = true) {
const sourceColumn = this.findColumn(this.option.column, 'sourceId');
sourceColumn.rules = value === '常规地址' ? [] : [{ required: true, message: '请选择来源主数据', trigger: 'change' }];
const sourceDisabled = value === '常规地址';
this.findColumn(this.option.column, 'longitude').disabled = !sourceDisabled;
this.findColumn(this.option.column, 'latitude').disabled = !sourceDisabled;
if (value === '常规地址') {
if (reset) {
this.form.sourceId = undefined;
this.form.siteCode = '/';
this.form.siteCodeDisplay = '/';
this.sourceOptions = [];
}
return;
}
if (reset) {
this.form.sourceId = undefined;
this.form.siteCode = '';
this.form.siteCodeDisplay = '';
}
this.loadSourceOptions();
},
normalizeRow(row) {
const submitRow = {
...row,
addressName: String(row.addressName || '').trim(),
addressType: String(row.addressType || '').trim(),
detailAddress: String(row.detailAddress || '').trim(),
regionName: String(row.regionName || '').trim(),
contactName: String(row.contactName || '').trim(),
contactPhone: String(row.contactPhone || '').trim(),
remark: String(row.remark || '').trim(),
};
if (submitRow.addressType === '常规地址') {
submitRow.siteCode = '/';
submitRow.sourceId = undefined;
}
return submitRow;
},
validateRequiredFields(row) {
if (!row.addressType) {
this.$message.warning('请选择类型');
return false;
}
if (!row.addressName) {
this.$message.warning('请输入地址名称');
return false;
}
if (!row.detailAddress) {
this.$message.warning('请输入详细地址');
return false;
}
if (row.addressType !== '常规地址' && !row.sourceId) {
this.$message.warning('请选择来源主数据');
return false;
}
if (row.remark && row.remark.length > 200) {
this.$message.warning('备注不能超过200个字');
return false;
}
if (row.longitude !== undefined && row.longitude !== null && row.longitude !== '') {
if (Number(row.longitude) < -180 || Number(row.longitude) > 180) {
this.$message.warning('经度范围为 -180 到 180');
return false;
}
row.longitude = Number(row.longitude).toFixed(6);
}
if (row.latitude !== undefined && row.latitude !== null && row.latitude !== '') {
if (Number(row.latitude) < -90 || Number(row.latitude) > 90) {
this.$message.warning('纬度范围为 -90 到 90');
return false;
}
row.latitude = Number(row.latitude).toFixed(6);
}
return true;
},
stopSubmitLoading(loading) {
if (typeof loading === 'function') {
loading();
}
},
rowSave(row, done, loading) {
const submitRow = this.normalizeRow(row);
if (!this.validateRequiredFields(submitRow)) {
this.stopSubmitLoading(loading);
return;
}
submit(submitRow).then(
() => {
this.onLoad(this.page);
this.$message({ type: 'success', message: '操作成功!' });
done();
},
error => {
window.console.log(error);
loading();
}
);
},
rowUpdate(row, index, done, loading) {
const submitRow = this.normalizeRow(row);
if (!this.validateRequiredFields(submitRow)) {
this.stopSubmitLoading(loading);
return;
}
submit(submitRow).then(
() => {
this.onLoad(this.page);
this.$message({ type: 'success', message: '操作成功!' });
done();
},
error => {
window.console.log(error);
loading();
}
);
},
rowDel(row) {
this.$confirm('确定将选择数据删除?', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
})
.then(() => remove(row.id))
.then(res => {
this.afterRemove(res.data.data);
});
},
handleDelete() {
if (this.selectionList.length === 0) {
this.$message.warning('请选择至少一条数据');
return;
}
const editableSelection = this.selectionList.filter(item => !item.readonly);
if (!editableSelection.length) {
this.$message.warning('所选数据均为只读组织数据');
return;
}
this.$confirm('确定将选择数据删除?', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
})
.then(() => remove(editableSelection.map(item => item.id).join(',')))
.then(res => {
this.afterRemove(res.data.data);
});
},
afterRemove(result = {}) {
this.onLoad(this.page);
const successCount = result.successCount || 0;
const skippedCount = result.skippedCount || 0;
if (skippedCount) {
this.$message.warning(`成功删除${successCount}条,${skippedCount}条因业务引用已跳过`);
} else {
this.$message({ type: 'success', message: '删除成功!' });
}
this.$refs.crud.toggleSelection();
},
beforeOpen(done, type) {
this.dialogReadonly = type === 'view';
const addressTypeColumn = this.findColumn(this.option.column, 'addressType');
addressTypeColumn.change = ({ value }) => this.handleAddressTypeChange(value);
if (type === 'add') {
this.form.addressType = this.form.addressType || '常规地址';
this.form.siteCode = '/';
this.form.siteCodeDisplay = '/';
this.handleAddressTypeChange(this.form.addressType);
done();
return;
}
if (['edit', 'view'].includes(type)) {
getDetail(this.form.id).then(res => {
this.form = res.data.data;
this.handleAddressTypeChange(this.form.addressType, false);
if (this.form.addressType !== '常规地址' && this.form.sourceId) {
this.sourceOptions = [
{
sourceId: this.form.sourceId,
addressName: this.form.addressName,
siteCode: this.form.siteCode,
detailAddress: this.form.detailAddress,
regionName: this.form.regionName,
longitude: this.form.longitude,
latitude: this.form.latitude,
},
];
}
done();
});
return;
}
done();
},
searchReset() {
this.query = {};
this.page.currentPage = 1;
this.onLoad(this.page);
},
searchChange(params, done) {
this.query = params;
this.page.currentPage = 1;
this.onLoad(this.page, params);
done();
},
selectionChange(list) {
this.selectionList = list;
},
selectionClear() {
this.selectionList = [];
this.$refs.crud.toggleSelection();
},
currentChange(currentPage) {
this.page.currentPage = currentPage;
},
sizeChange(pageSize) {
this.page.pageSize = pageSize;
},
refreshChange() {
this.onLoad(this.page, this.query);
},
onLoad(page, params = {}) {
this.loading = true;
getList(page.currentPage, page.pageSize, { ...params, ...this.query, allDept: this.allDept })
.then(res => {
const data = res.data.data;
this.page.total = data.total;
this.data = data.records;
this.selectionClear();
})
.finally(() => {
this.loading = false;
});
},
handleExport() {
this.$confirm('是否导出常用地址?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
}).then(() => {
NProgress.start();
exportBlob('/blade-transport/common-address/export-common-address', this.buildExportParams())
.then(res => {
downloadXls(res.data, `常用地址${this.$dayjs().format('YYYY-MM-DD HH:mm:ss')}.xlsx`);
})
.finally(() => {
NProgress.done();
});
});
},
buildExportParams() {
return {
...this.query,
allDept: this.allDept,
ids: this.ids,
[this.website.tokenHeader]: getToken(),
};
},
handleMapPick() {
if (this.dialogReadonly || this.form.addressType !== '常规地址') {
return;
}
this.mapKeyword = this.form.detailAddress || this.form.regionName || '';
this.mapSelected = this.buildMapSelection({
lng: this.form.longitude,
lat: this.form.latitude,
address: this.form.detailAddress,
regionName: this.form.regionName,
});
this.mapStatus = this.mapSelected.longitude ? '已加载当前经纬度,可重新选点' : '可搜索地址或点击地图选点';
this.mapBox = true;
},
loadTianditu() {
if (window.T && window.T.Map) {
return Promise.resolve();
}
if (!tiandituLoader) {
tiandituLoader = new Promise((resolve, reject) => {
const script = document.createElement('script');
script.src = `https://api.tianditu.gov.cn/api?v=4.0&tk=${TIANDITU_KEY}`;
script.async = true;
script.onload = resolve;
script.onerror = () => reject(new Error('天地图组件加载失败'));
document.body.appendChild(script);
});
}
return tiandituLoader;
},
initTiandituMap() {
this.loadTianditu()
.then(() => {
this.$nextTick(() => {
if (!this.tiandituMap) {
const center = this.toLngLat(
this.mapSelected.longitude || 116.40769,
this.mapSelected.latitude || 39.89945
);
this.tiandituMap = new window.T.Map(this.$refs.tiandituMap);
this.tiandituMap.centerAndZoom(center, this.mapSelected.longitude ? 14 : 11);
this.tiandituMap.addControl(new window.T.Control.Zoom());
this.tiandituClickHandler = event => this.pickMapPoint(event.lnglat);
this.tiandituMap.addEventListener('click', this.tiandituClickHandler);
this.tiandituGeocoder = new window.T.Geocoder();
} else {
if (typeof this.tiandituMap.checkResize === 'function') {
this.tiandituMap.checkResize();
}
}
if (this.mapSelected.longitude) {
this.renderMapMarker(this.toLngLat(this.mapSelected.longitude, this.mapSelected.latitude));
}
});
})
.catch(() => {
this.$message.error('天地图组件加载失败,请稍后重试或重新打开弹窗');
this.mapBox = false;
});
},
searchMapKeyword() {
const keyword = String(this.mapKeyword || '').trim();
if (!keyword) {
this.$message.warning('请输入地址关键词');
return;
}
this.loadTianditu()
.then(() => {
this.mapLoading = true;
if (!this.tiandituGeocoder) {
this.tiandituGeocoder = new window.T.Geocoder();
}
this.tiandituGeocoder.getPoint(keyword, result => {
this.mapLoading = false;
const point = this.resolveMapPoint(result);
if (!point) {
this.mapStatus = '未找到匹配地址';
this.$message.warning('地图搜索无匹配地址');
return;
}
this.pickMapPoint(point, keyword);
});
})
.catch(() => {
this.$message.error('天地图组件加载失败,请稍后重试或重新打开弹窗');
});
},
pickMapPoint(lnglat, keyword) {
const longitude = this.getPointLng(lnglat);
const latitude = this.getPointLat(lnglat);
if (longitude === undefined || latitude === undefined) {
this.$message.warning('选点坐标无效');
return;
}
const point = this.toLngLat(longitude, latitude);
this.renderMapMarker(point);
this.mapSelected = this.buildMapSelection({ lng: longitude, lat: latitude, address: keyword });
this.mapStatus = '正在反查地址...';
if (!this.tiandituGeocoder) {
this.tiandituGeocoder = new window.T.Geocoder();
}
this.tiandituGeocoder.getLocation(point, result => {
const address = this.resolveMapAddress(result);
this.mapSelected = {
...this.mapSelected,
detailAddress: address.detailAddress || this.mapSelected.detailAddress,
regionName: address.regionName || this.mapSelected.regionName,
regionCode: address.regionCode || this.mapSelected.regionCode,
};
this.mapKeyword = this.mapSelected.detailAddress || this.mapKeyword;
this.mapStatus = this.mapSelected.detailAddress || '已选点,可确认回填';
});
},
renderMapMarker(point) {
if (!this.tiandituMap || !window.T) return;
if (this.tiandituMarker) {
this.tiandituMap.removeOverLay(this.tiandituMarker);
}
this.tiandituMarker = new window.T.Marker(point);
this.tiandituMap.addOverLay(this.tiandituMarker);
this.tiandituMap.panTo(point);
},
confirmMapPick() {
if (!this.mapSelected.longitude) {
this.$message.warning('请先搜索或点击地图完成选点');
return;
}
this.form.detailAddress = this.mapSelected.detailAddress || this.form.detailAddress;
this.form.regionName = this.mapSelected.regionName || this.form.regionName;
this.form.regionCode = this.mapSelected.regionCode || this.form.regionCode;
this.form.longitude = this.mapSelected.longitude;
this.form.latitude = this.mapSelected.latitude;
this.mapBox = false;
},
buildMapSelection({ lng, lat, address, regionName, regionCode }) {
const longitude = lng === undefined || lng === null || lng === '' ? '' : Number(lng).toFixed(6);
const latitude = lat === undefined || lat === null || lat === '' ? '' : Number(lat).toFixed(6);
return {
longitude,
latitude,
detailAddress: address || '',
regionName: regionName || '',
regionCode: regionCode || '',
};
},
toLngLat(lng, lat) {
return new window.T.LngLat(Number(lng), Number(lat));
},
getPointLng(point) {
if (!point) return undefined;
if (typeof point.getLng === 'function') return point.getLng();
return point.lng ?? point.lon;
},
getPointLat(point) {
if (!point) return undefined;
if (typeof point.getLat === 'function') return point.getLat();
return point.lat;
},
resolveMapPoint(result) {
if (!result) return null;
if (typeof result.getLocationPoint === 'function') return result.getLocationPoint();
if (Array.isArray(result)) return result[0] || null;
if (result.location) return result.location;
if (result.lnglat) return result.lnglat;
if (result.lonlat) return result.lonlat;
if (result.getLng || result.lng || result.lon) return result;
return null;
},
resolveMapAddress(result = {}) {
const component =
(typeof result.getAddressComponent === 'function' && result.getAddressComponent()) ||
result.addressComponent ||
{};
const detailAddress =
(typeof result.getAddress === 'function' && result.getAddress()) ||
result.formatted_address ||
result.address ||
result.formattedAddress ||
'';
const regionName = [component.province, component.city, component.county || component.district]
.filter(Boolean)
.join('');
return {
detailAddress,
regionName,
regionCode: component.countyCode || component.adcode || component.cityCode || '',
};
},
},
};
</script>
<style lang="scss" scoped>
.common-address-page {
&__scope {
margin-left: 12px;
vertical-align: middle;
}
&__address {
display: flex;
gap: 10px;
align-items: flex-start;
.el-input {
flex: 1;
}
.el-button {
flex: 0 0 auto;
}
}
&__map-toolbar {
display: flex;
gap: 10px;
margin-bottom: 12px;
.el-input {
flex: 1;
}
}
&__map {
width: 100%;
height: 460px;
border: 1px solid #dcdfe6;
}
&__map-info {
display: flex;
justify-content: space-between;
gap: 16px;
min-height: 22px;
margin-top: 10px;
color: #606266;
font-size: 13px;
}
}
</style>

580
src/views/base/currency.vue Normal file
View File

@@ -0,0 +1,580 @@
<template>
<basic-container class="currency-page">
<avue-crud
:option="option"
:table-loading="loading"
:data="data"
v-model:page="page"
v-model="form"
ref="crud"
:permission="permissionList"
:before-open="beforeOpen"
@row-save="rowSave"
@row-update="rowUpdate"
@search-change="searchChange"
@search-reset="searchReset"
@selection-change="selectionChange"
@current-change="currentChange"
@size-change="sizeChange"
@refresh-change="refreshChange"
@on-load="onLoad"
>
<template #menu-left>
<el-button
type="primary"
icon="el-icon-upload"
plain
v-if="permission.currency_import"
@click="handleImport"
>批量导入
</el-button>
<el-button
type="primary"
icon="el-icon-download"
plain
v-if="permission.currency_template"
@click="handleTemplate"
>下载模板
</el-button>
<el-button
type="primary"
icon="el-icon-download"
plain
v-if="permission.currency_export"
@click="handleExport"
>批量导出
</el-button>
</template>
<template #codeForm>
<el-autocomplete
v-model="form.code"
:fetch-suggestions="fetchCurrencyOptions"
clearable
placeholder="请输入币种编码查询选择"
value-key="code"
class="currency-page__input"
@select="handleCurrencySelect"
@change="handleCodeChange"
>
<template #default="{ item }">
<span>{{ item.code }}</span>
<span class="currency-page__option-name">{{ item.name }}</span>
</template>
</el-autocomplete>
</template>
<template #status="{ row }">
<el-tag :type="row.status === 1 ? 'primary' : 'info'">
{{ row.status === 1 ? '启用' : '停用' }}
</el-tag>
</template>
<template #menu="{ row, index }">
<el-button
type="primary"
text
icon="el-icon-edit"
v-if="permission.currency_edit"
@click="$refs.crud.rowEdit(row, index)"
>
编辑
</el-button>
<el-button
type="primary"
text
:icon="row.status === 1 ? 'el-icon-close' : 'el-icon-check'"
v-if="permission.currency_status"
@click="handleStatus(row)"
>
{{ row.status === 1 ? '停用' : '启用' }}
</el-button>
</template>
</avue-crud>
<el-dialog title="币种汇率导入" append-to-body v-model="excelBox" width="555px">
<avue-form :option="excelOption" v-model="excelForm" :upload-after="uploadAfter">
<template #excelTemplate>
<el-button type="primary" @click="handleTemplate">
点击下载<i class="el-icon-download el-icon--right"></i>
</el-button>
</template>
</avue-form>
</el-dialog>
</basic-container>
</template>
<script>
import { changeStatus, getDetail, getList, submit } from '@/api/base/currency';
import { exportBlob } from '@/api/common';
import { mapGetters } from 'vuex';
import { downloadXls } from '@/utils/util';
import { getToken } from '@/utils/auth';
import NProgress from 'nprogress';
import 'nprogress/nprogress.css';
const statusDic = [
{ label: '启用', value: 1 },
{ label: '停用', value: 2 },
];
const sourceDic = [
{ label: '手工录入', value: '手工录入' },
{ label: '批量导入', value: '批量导入' },
];
export default {
data() {
const validateCurrencyCode = (rule, value, callback) => {
if (!/^[A-Z]{3}$/.test(value || '')) {
callback(new Error('币种编码为3位大写字母'));
} else {
callback();
}
};
const validateExchangeRate = (rule, value, callback) => {
if (value === undefined || value === null || value === '') {
callback(new Error('请输入汇率'));
} else if (Number(value) <= 0) {
callback(new Error('汇率必须大于0'));
} else if (!/^\d+(\.\d{1,6})?$/.test(String(value))) {
callback(new Error('汇率最多保留6位小数'));
} else {
callback();
}
};
return {
form: {},
query: {},
loading: true,
data: [],
excelBox: false,
excelForm: {},
page: {
pageSize: 10,
currentPage: 1,
total: 0,
},
selectionList: [],
option: {
height: 'auto',
calcHeight: 32,
dialogWidth: 860,
labelPosition: 'top',
tip: false,
searchShow: true,
searchMenuSpan: 6,
border: true,
index: true,
indexLabel: '序号',
viewBtn: false,
delBtn: false,
editBtn: false,
selection: true,
dialogClickModal: false,
menuWidth: 170,
menuFixed: 'right',
column: [
{
label: '币种编码',
prop: 'code',
search: true,
formslot: true,
minWidth: 120,
maxlength: 3,
rules: [
{ required: true, message: '请选择币种编码', trigger: 'blur' },
{ validator: validateCurrencyCode, trigger: 'blur' },
],
},
{
label: '币种名称',
prop: 'name',
minWidth: 150,
search: true,
disabled: true,
rules: [{ required: true, message: '请选择币种编码带出币种名称', trigger: 'blur' }],
},
{
label: '汇率',
prop: 'exchangeRate',
type: 'number',
search: true,
minWidth: 120,
precision: 6,
rules: [{ validator: validateExchangeRate, trigger: 'blur' }],
},
{
label: '生效日期',
prop: 'effectiveDate',
type: 'date',
format: 'YYYY-MM-DD',
valueFormat: 'YYYY-MM-DD',
minWidth: 130,
rules: [{ required: true, message: '请选择生效日期', trigger: 'click' }],
},
{
label: '生效日期',
prop: 'effectiveDateRange',
type: 'date',
format: 'YYYY-MM-DD',
valueFormat: 'YYYY-MM-DD',
searchRange: true,
search: true,
hide: true,
addDisplay: false,
editDisplay: false,
viewDisplay: false,
},
{
label: '失效日期',
prop: 'expiryDate',
type: 'date',
format: 'YYYY-MM-DD',
valueFormat: 'YYYY-MM-DD',
minWidth: 130,
addDisplay: false,
editDisplay: false,
},
{
label: '失效日期',
prop: 'expiryDateRange',
type: 'date',
format: 'YYYY-MM-DD',
valueFormat: 'YYYY-MM-DD',
searchRange: true,
search: true,
hide: true,
addDisplay: false,
editDisplay: false,
viewDisplay: false,
},
{
label: '状态',
prop: 'status',
type: 'select',
search: true,
slot: true,
dataType: 'number',
dicData: statusDic,
value: 1,
minWidth: 100,
},
{
label: '来源',
prop: 'dataSource',
type: 'select',
search: true,
dicData: sourceDic,
value: '手工录入',
minWidth: 120,
addDisplay: false,
editDisplay: false,
},
{
label: '备注',
prop: 'remark',
type: 'textarea',
minRows: 4,
span: 24,
hide: true,
maxlength: 200,
showWordLimit: true,
rules: [{ max: 200, message: '最多 200 个字符', trigger: 'blur' }],
},
{
label: '更新时间',
prop: 'updateTime',
type: 'datetime',
format: 'YYYY-MM-DD HH:mm:ss',
valueFormat: 'YYYY-MM-DD HH:mm:ss',
addDisplay: false,
editDisplay: false,
display: false,
minWidth: 160,
},
{
label: '更新时间',
prop: 'updateTimeRange',
type: 'datetime',
format: 'YYYY-MM-DD HH:mm:ss',
valueFormat: 'YYYY-MM-DD HH:mm:ss',
searchRange: true,
search: true,
hide: true,
addDisplay: false,
editDisplay: false,
viewDisplay: false,
},
],
},
excelOption: {
submitBtn: false,
emptyBtn: false,
column: [
{
label: '模板上传',
prop: 'excelFile',
type: 'upload',
drag: true,
loadText: '模板上传中,请稍等',
span: 24,
propsHttp: {
res: 'data',
},
tip: '请上传 .xls,.xlsx 标准格式文件',
action: '/blade-system/currency/import-currency',
},
{
label: '模板下载',
prop: 'excelTemplate',
formslot: true,
span: 24,
},
],
},
};
},
computed: {
...mapGetters(['permission']),
permissionList() {
return {
addBtn: this.validData(this.permission.currency_add, false),
};
},
ids() {
return this.selectionList.map(ele => ele.id).join(',');
},
},
methods: {
handleCodeChange(value) {
this.form.code = String(value || '').toUpperCase().replace(/[^A-Z]/g, '').slice(0, 3);
const matched = this.data.find(item => item.code === this.form.code);
if (matched) {
this.form.name = matched.name;
}
},
fetchCurrencyOptions(queryString, callback) {
getList(1, 20, { code: String(queryString || '').toUpperCase() })
.then(res => {
const records = res.data.data.records || [];
const exists = new Map();
records.forEach(item => {
if (!exists.has(item.code)) {
exists.set(item.code, {
code: item.code,
value: item.code,
name: item.name,
});
}
});
callback(Array.from(exists.values()));
})
.catch(() => callback([]));
},
handleCurrencySelect(item) {
this.form.code = item.code;
this.form.name = item.name;
},
normalizeRow(row) {
const values = { ...row };
values.code = String(values.code || '').toUpperCase();
values.dataSource = values.dataSource || '手工录入';
values.status = values.status || 1;
return values;
},
validateRow(row) {
if (row.remark && row.remark.length > 200) {
this.$message.warning('备注不能超过 200 字');
return false;
}
if (Number(row.exchangeRate) <= 0) {
this.$message.warning('汇率必须大于0');
return false;
}
if (!/^\d+(\.\d{1,6})?$/.test(String(row.exchangeRate))) {
this.$message.warning('汇率最多保留6位小数');
return false;
}
return true;
},
rowSave(row, done, loading) {
const values = this.normalizeRow(row);
if (!this.validateRow(values)) {
loading();
return;
}
submit(values).then(
() => {
this.onLoad(this.page);
this.$message({ type: 'success', message: '操作成功!' });
done();
},
error => {
window.console.log(error);
loading();
}
);
},
rowUpdate(row, index, done, loading) {
const values = this.normalizeRow(row);
if (!this.validateRow(values)) {
loading();
return;
}
submit(values).then(
() => {
this.onLoad(this.page);
this.$message({ type: 'success', message: '操作成功!' });
done();
},
error => {
window.console.log(error);
loading();
}
);
},
handleStatus(row) {
const nextStatus = row.status === 1 ? 2 : 1;
const actionName = nextStatus === 1 ? '启用' : '停用';
this.$confirm(`是否确认${actionName}该条汇率?`, {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
})
.then(() => changeStatus(row.id, nextStatus))
.then(() => {
this.onLoad(this.page);
this.$message({ type: 'success', message: '操作成功!' });
});
},
beforeOpen(done, type) {
if (['edit', 'view'].includes(type)) {
getDetail(this.form.id).then(res => {
this.form = res.data.data;
done();
});
return;
}
this.form = {
status: 1,
dataSource: '手工录入',
};
done();
},
searchReset() {
this.query = {};
this.onLoad(this.page);
},
searchChange(params, done) {
this.query = params;
this.page.currentPage = 1;
this.onLoad(this.page, params);
done();
},
selectionChange(list) {
this.selectionList = list;
},
selectionClear() {
this.selectionList = [];
this.$refs.crud.toggleSelection();
},
currentChange(currentPage) {
this.page.currentPage = currentPage;
},
sizeChange(pageSize) {
this.page.pageSize = pageSize;
},
refreshChange() {
this.onLoad(this.page, this.query);
},
buildQuery(params = {}) {
const values = { ...params, ...this.query };
const rangeMap = {
effectiveDateRange: ['effectiveDateStart', 'effectiveDateEnd'],
expiryDateRange: ['expiryDateStart', 'expiryDateEnd'],
updateTimeRange: ['updateTimeStart', 'updateTimeEnd'],
};
Object.keys(rangeMap).forEach(key => {
const range = values[key];
if (range && range.length === 2) {
values[rangeMap[key][0]] = range[0];
values[rangeMap[key][1]] = range[1];
}
values[key] = null;
});
return values;
},
onLoad(page, params = {}) {
this.loading = true;
getList(page.currentPage, page.pageSize, this.buildQuery(params))
.then(res => {
const result = res.data.data;
this.page.total = result.total;
this.data = result.records;
if (result.records.length === 0 && result.total > 0 && page.currentPage > 1) {
this.page.currentPage = page.currentPage - 1;
this.onLoad(this.page, this.query);
}
this.selectionClear();
})
.finally(() => {
this.loading = false;
});
},
handleImport() {
this.excelBox = true;
},
uploadAfter(res, done) {
this.excelBox = false;
this.onLoad(this.page);
done();
},
handleExport() {
this.$confirm('是否导出币种汇率数据?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
}).then(() => {
NProgress.start();
exportBlob('/blade-system/currency/export-currency', this.buildExportParams())
.then(res => {
downloadXls(res.data, `币种汇率${this.$dayjs().format('YYYY-MM-DD HH:mm:ss')}.xlsx`);
})
.finally(() => {
NProgress.done();
});
});
},
buildExportParams() {
return {
...this.buildQuery(),
ids: this.ids,
[this.website.tokenHeader]: getToken(),
};
},
handleTemplate() {
exportBlob(`/blade-system/currency/export-template?${this.website.tokenHeader}=${getToken()}`).then(res => {
downloadXls(res.data, '币种汇率模板.xlsx');
});
},
},
};
</script>
<style lang="scss" scoped>
.currency-page {
:deep(.el-table th .cell),
:deep(.el-table td .cell) {
white-space: nowrap;
}
&__input {
width: 100%;
}
&__option-name {
float: right;
color: #8492a6;
font-size: 13px;
margin-left: 16px;
}
}
</style>

View File

@@ -0,0 +1,290 @@
<template>
<basic-container>
<avue-crud
:option="option"
:table-loading="loading"
:data="data"
v-model:page="page"
v-model="form"
ref="crud"
:permission="permissionList"
:before-open="beforeOpen"
@row-save="rowSave"
@row-update="rowUpdate"
@row-del="rowDel"
@search-change="searchChange"
@search-reset="searchReset"
@selection-change="selectionChange"
@current-change="currentChange"
@size-change="sizeChange"
@refresh-change="refreshChange"
@on-load="onLoad"
>
<template #menu-left>
<el-button
type="danger"
icon="el-icon-delete"
plain
v-if="permission.customer_type_delete"
@click="handleDelete"
>批量删除
</el-button>
</template>
<template #status="{ row }">
<el-tag :type="row.status === 1 ? 'primary' : 'info'">
{{ row.status === 1 ? '启用' : '停用' }}
</el-tag>
</template>
<template #menu="{ row, index }">
<el-button
type="primary"
text
icon="el-icon-edit"
v-if="permission.customer_type_edit"
@click="$refs.crud.rowEdit(row, index)"
>
编辑
</el-button>
<el-button
type="primary"
text
:icon="row.status === 1 ? 'el-icon-close' : 'el-icon-check'"
v-if="permission.customer_type_status"
@click="handleStatus(row)"
>
{{ row.status === 1 ? '停用' : '启用' }}
</el-button>
</template>
</avue-crud>
</basic-container>
</template>
<script>
import { getList, getDetail, submit, remove, changeStatus } from '@/api/base/customer-type';
import { mapGetters } from 'vuex';
export default {
data() {
return {
form: {},
query: {},
loading: true,
data: [],
page: {
pageSize: 10,
currentPage: 1,
total: 0,
},
selectionList: [],
option: {
height: 'auto',
calcHeight: 32,
dialogWidth: 680,
tip: false,
searchShow: true,
searchMenuSpan: 6,
border: true,
index: true,
indexLabel: '序号',
viewBtn: false,
delBtn: false,
editBtn: false,
selection: true,
dialogClickModal: false,
menuWidth: 160,
column: [
{
label: '中文名称',
prop: 'name',
minWidth: 140,
search: true,
maxlength: 50,
rules: [{ required: true, message: '请输入中文名称', trigger: 'blur' }],
},
{
label: '英文名称',
prop: 'englishName',
minWidth: 160,
search: true,
maxlength: 100,
},
{
label: '状态',
prop: 'status',
type: 'select',
search: true,
slot: true,
dataType: 'number',
dicData: [
{ label: '启用', value: 1 },
{ label: '停用', value: 2 },
],
value: 1,
},
{
label: '更新时间',
prop: 'updateTime',
type: 'datetime',
format: 'YYYY-MM-DD HH:mm:ss',
valueFormat: 'YYYY-MM-DD HH:mm:ss',
addDisplay: false,
editDisplay: false,
display: false,
minWidth: 160,
},
{
label: '创建时间',
prop: 'createTime',
type: 'datetime',
format: 'YYYY-MM-DD HH:mm:ss',
valueFormat: 'YYYY-MM-DD HH:mm:ss',
addDisplay: false,
editDisplay: false,
display: false,
minWidth: 160,
},
],
},
};
},
computed: {
...mapGetters(['permission']),
permissionList() {
return {
addBtn: this.validData(this.permission.customer_type_add, false),
};
},
ids() {
let ids = [];
this.selectionList.forEach(ele => {
ids.push(ele.id);
});
return ids.join(',');
},
},
methods: {
normalizeRow(row) {
row.name = String(row.name || '').trim();
row.englishName = String(row.englishName || '').trim();
if (!row.status) row.status = 1;
return row;
},
rowSave(row, done, loading) {
submit(this.normalizeRow(row)).then(
() => {
this.onLoad(this.page);
this.$message({ type: 'success', message: '操作成功!' });
done();
},
error => {
window.console.log(error);
loading();
}
);
},
rowUpdate(row, index, done, loading) {
submit(this.normalizeRow(row)).then(
() => {
this.onLoad(this.page);
this.$message({ type: 'success', message: '操作成功!' });
done();
},
error => {
window.console.log(error);
loading();
}
);
},
rowDel(row) {
this.$confirm('确定将选择数据删除?', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
})
.then(() => remove(row.id))
.then(() => {
this.onLoad(this.page);
this.$message({ type: 'success', message: '操作成功!' });
});
},
handleDelete() {
if (this.selectionList.length === 0) {
this.$message.warning('请选择至少一条数据');
return;
}
this.$confirm('确定将选择数据删除?', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
})
.then(() => remove(this.ids))
.then(() => {
this.onLoad(this.page);
this.$message({ type: 'success', message: '操作成功!' });
this.$refs.crud.toggleSelection();
});
},
handleStatus(row) {
const nextStatus = row.status === 1 ? 2 : 1;
const actionName = nextStatus === 1 ? '启用' : '停用';
this.$confirm(`是否确认${actionName}该条数据?`, {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
})
.then(() => changeStatus(row.id, nextStatus))
.then(() => {
this.onLoad(this.page);
this.$message({ type: 'success', message: '操作成功!' });
});
},
beforeOpen(done, type) {
if (['edit', 'view'].includes(type)) {
getDetail(this.form.id).then(res => {
this.form = res.data.data;
done();
});
return;
}
this.form.status = 1;
done();
},
searchReset() {
this.query = {};
this.onLoad(this.page);
},
searchChange(params, done) {
this.query = params;
this.page.currentPage = 1;
this.onLoad(this.page, params);
done();
},
selectionChange(list) {
this.selectionList = list;
},
selectionClear() {
this.selectionList = [];
this.$refs.crud.toggleSelection();
},
currentChange(currentPage) {
this.page.currentPage = currentPage;
},
sizeChange(pageSize) {
this.page.pageSize = pageSize;
},
refreshChange() {
this.onLoad(this.page, this.query);
},
onLoad(page, params = {}) {
this.loading = true;
getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
const data = res.data.data;
this.page.total = data.total;
this.data = data.records;
this.loading = false;
this.selectionClear();
});
},
},
};
</script>

290
src/views/base/fee-item.vue Normal file
View File

@@ -0,0 +1,290 @@
<template>
<basic-container>
<avue-crud
:option="option"
:table-loading="loading"
:data="data"
v-model:page="page"
v-model="form"
ref="crud"
:permission="permissionList"
:before-open="beforeOpen"
@row-save="rowSave"
@row-update="rowUpdate"
@row-del="rowDel"
@search-change="searchChange"
@search-reset="searchReset"
@selection-change="selectionChange"
@current-change="currentChange"
@size-change="sizeChange"
@refresh-change="refreshChange"
@on-load="onLoad"
>
<template #menu-left>
<el-button
type="danger"
icon="el-icon-delete"
plain
v-if="permission.fee_item_delete"
@click="handleDelete"
>批量删除
</el-button>
</template>
<template #status="{ row }">
<el-tag :type="row.status === 1 ? 'primary' : 'info'">
{{ row.status === 1 ? '启用' : '停用' }}
</el-tag>
</template>
<template #menu="{ row, index }">
<el-button
type="primary"
text
icon="el-icon-edit"
v-if="permission.fee_item_edit"
@click="$refs.crud.rowEdit(row, index)"
>
编辑
</el-button>
<el-button
type="primary"
text
:icon="row.status === 1 ? 'el-icon-close' : 'el-icon-check'"
v-if="permission.fee_item_status"
@click="handleStatus(row)"
>
{{ row.status === 1 ? '停用' : '启用' }}
</el-button>
</template>
</avue-crud>
</basic-container>
</template>
<script>
import { getList, getDetail, submit, remove, changeStatus } from '@/api/base/fee-item';
import { mapGetters } from 'vuex';
export default {
data() {
return {
form: {},
query: {},
loading: true,
data: [],
page: {
pageSize: 10,
currentPage: 1,
total: 0,
},
selectionList: [],
option: {
height: 'auto',
calcHeight: 32,
dialogWidth: 680,
tip: false,
searchShow: true,
searchMenuSpan: 6,
border: true,
index: true,
indexLabel: '序号',
viewBtn: false,
delBtn: false,
editBtn: false,
selection: true,
dialogClickModal: false,
menuWidth: 160,
column: [
{
label: '中文名称',
prop: 'name',
minWidth: 140,
search: true,
maxlength: 50,
rules: [{ required: true, message: '请输入中文名称', trigger: 'blur' }],
},
{
label: '英文名称',
prop: 'englishName',
minWidth: 160,
search: true,
maxlength: 100,
},
{
label: '状态',
prop: 'status',
type: 'select',
search: true,
slot: true,
dataType: 'number',
dicData: [
{ label: '启用', value: 1 },
{ label: '停用', value: 2 },
],
value: 1,
},
{
label: '更新时间',
prop: 'updateTime',
type: 'datetime',
format: 'YYYY-MM-DD HH:mm:ss',
valueFormat: 'YYYY-MM-DD HH:mm:ss',
addDisplay: false,
editDisplay: false,
display: false,
minWidth: 160,
},
{
label: '创建时间',
prop: 'createTime',
type: 'datetime',
format: 'YYYY-MM-DD HH:mm:ss',
valueFormat: 'YYYY-MM-DD HH:mm:ss',
addDisplay: false,
editDisplay: false,
display: false,
minWidth: 160,
},
],
},
};
},
computed: {
...mapGetters(['permission']),
permissionList() {
return {
addBtn: this.validData(this.permission.fee_item_add, false),
};
},
ids() {
let ids = [];
this.selectionList.forEach(ele => {
ids.push(ele.id);
});
return ids.join(',');
},
},
methods: {
normalizeRow(row) {
row.name = String(row.name || '').trim();
row.englishName = String(row.englishName || '').trim();
if (!row.status) row.status = 1;
return row;
},
rowSave(row, done, loading) {
submit(this.normalizeRow(row)).then(
() => {
this.onLoad(this.page);
this.$message({ type: 'success', message: '操作成功!' });
done();
},
error => {
window.console.log(error);
loading();
}
);
},
rowUpdate(row, index, done, loading) {
submit(this.normalizeRow(row)).then(
() => {
this.onLoad(this.page);
this.$message({ type: 'success', message: '操作成功!' });
done();
},
error => {
window.console.log(error);
loading();
}
);
},
rowDel(row) {
this.$confirm('确定将选择数据删除?', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
})
.then(() => remove(row.id))
.then(() => {
this.onLoad(this.page);
this.$message({ type: 'success', message: '操作成功!' });
});
},
handleDelete() {
if (this.selectionList.length === 0) {
this.$message.warning('请选择至少一条数据');
return;
}
this.$confirm('确定将选择数据删除?', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
})
.then(() => remove(this.ids))
.then(() => {
this.onLoad(this.page);
this.$message({ type: 'success', message: '操作成功!' });
this.$refs.crud.toggleSelection();
});
},
handleStatus(row) {
const nextStatus = row.status === 1 ? 2 : 1;
const actionName = nextStatus === 1 ? '启用' : '停用';
this.$confirm(`是否确认${actionName}该条数据?`, {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
})
.then(() => changeStatus(row.id, nextStatus))
.then(() => {
this.onLoad(this.page);
this.$message({ type: 'success', message: '操作成功!' });
});
},
beforeOpen(done, type) {
if (['edit', 'view'].includes(type)) {
getDetail(this.form.id).then(res => {
this.form = res.data.data;
done();
});
return;
}
this.form.status = 1;
done();
},
searchReset() {
this.query = {};
this.onLoad(this.page);
},
searchChange(params, done) {
this.query = params;
this.page.currentPage = 1;
this.onLoad(this.page, params);
done();
},
selectionChange(list) {
this.selectionList = list;
},
selectionClear() {
this.selectionList = [];
this.$refs.crud.toggleSelection();
},
currentChange(currentPage) {
this.page.currentPage = currentPage;
},
sizeChange(pageSize) {
this.page.pageSize = pageSize;
},
refreshChange() {
this.onLoad(this.page, this.query);
},
onLoad(page, params = {}) {
this.loading = true;
getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
const data = res.data.data;
this.page.total = data.total;
this.data = data.records;
this.loading = false;
this.selectionClear();
});
},
},
};
</script>

View File

@@ -0,0 +1,804 @@
<template>
<basic-container class="port-terminal-page">
<avue-crud
:option="option"
:table-loading="loading"
:data="data"
v-model:page="page"
v-model="form"
ref="crud"
:permission="permissionList"
:before-open="beforeOpen"
@row-save="rowSave"
@row-update="rowUpdate"
@row-del="rowDel"
@search-change="searchChange"
@search-reset="searchReset"
@selection-change="selectionChange"
@current-change="currentChange"
@size-change="sizeChange"
@refresh-change="refreshChange"
@on-load="onLoad"
>
<template #menu-left>
<el-button
type="primary"
icon="el-icon-upload"
plain
v-if="hasPermission('port_terminal_import')"
@click="handleImport"
>批量导入
</el-button>
<el-button
type="primary"
icon="el-icon-download"
plain
v-if="hasPermission('port_terminal_template')"
@click="handleTemplate"
>下载模板
</el-button>
<el-button
type="primary"
icon="el-icon-download"
plain
v-if="hasPermission('port_terminal_export')"
@click="handleExport"
>批量导出
</el-button>
<el-button
type="danger"
icon="el-icon-delete"
plain
v-if="hasPermission('port_terminal_delete')"
@click="handleDelete"
>批量删除
</el-button>
</template>
<template #parentName="{ row }">
<span>{{ row.category === '港口' ? '-' : row.parentName }}</span>
</template>
<template #parentCode="{ row }">
<span>{{ row.category === '港口' ? '-' : row.parentCode }}</span>
</template>
<template #status="{ row }">
<el-tag :type="row.status === 1 ? 'primary' : 'info'">
{{ row.status === 1 ? '启用' : '停用' }}
</el-tag>
</template>
<template #menu="{ row, index }">
<el-button
type="primary"
text
icon="el-icon-edit"
v-if="hasPermission('port_terminal_edit')"
@click="$refs.crud.rowEdit(row, index)"
>
编辑
</el-button>
<el-button
type="primary"
text
:icon="row.status === 1 ? 'el-icon-close' : 'el-icon-check'"
v-if="hasPermission('port_terminal_status')"
@click="handleStatus(row)"
>
{{ row.status === 1 ? '停用' : '启用' }}
</el-button>
</template>
<template #regionCode-form>
<el-cascader
v-model="form.regionCode"
:props="regionProps"
clearable
filterable
:disabled="isParentRegionLocked"
style="width: 100%"
@change="handleRegionChange"
/>
</template>
</avue-crud>
<el-dialog title="港口码头主数据导入" append-to-body v-model="excelBox" width="555px">
<avue-form
:option="excelOption"
v-model="excelForm"
:upload-before="uploadBefore"
:upload-after="uploadAfter"
>
<template #excelTemplate>
<el-button type="primary" @click="handleTemplate">
点击下载<i class="el-icon-download el-icon--right"></i>
</el-button>
</template>
</avue-form>
</el-dialog>
</basic-container>
</template>
<script>
import {
getList,
getDetail,
submit,
remove,
changeStatus,
getPortSelect,
} from '@/api/base/port-terminal';
import { getLazyTree } from '@/api/base/region';
import { exportBlob } from '@/api/common';
import { mapGetters } from 'vuex';
import { downloadXls } from '@/utils/util';
import { formatUpdateUserName } from '@/utils/audit';
import { getToken } from '@/utils/auth';
import NProgress from 'nprogress';
import 'nprogress/nprogress.css';
export default {
data() {
const validateCode = (rule, value, callback) => {
const code = String(value || '').toUpperCase();
if (this.form.category === '港口') {
if (!/^[A-Z]{5}$/.test(code)) {
callback(new Error('港口编码为5位大写字母CNSHG'));
} else {
callback();
}
return;
}
if (this.form.category === '码头') {
if (!/^[A-Z]{5}-[A-Z0-9]+$/.test(code)) {
callback(new Error('码头编码格式为“港口编码-码头标识”CNSHG-CT1'));
} else if (this.form.parentCode && !code.startsWith(`${this.form.parentCode}-`)) {
callback(new Error(`码头编码须以所选上级港口编码 ${this.form.parentCode}- 开头`));
} else {
callback();
}
return;
}
callback();
};
const validateLongitude = (rule, value, callback) => {
if (value === undefined || value === null || value === '') {
callback();
} else if (Number(value) < -180 || Number(value) > 180) {
callback(new Error('经度范围为 -180 到 180'));
} else {
callback();
}
};
const validateLatitude = (rule, value, callback) => {
if (value === undefined || value === null || value === '') {
callback();
} else if (Number(value) < -90 || Number(value) > 90) {
callback(new Error('纬度范围为 -90 到 90'));
} else {
callback();
}
};
return {
form: {},
query: {},
loading: true,
data: [],
excelBox: false,
excelForm: {},
portOptions: [],
regionNodeMap: {},
regionNameMap: {},
regionProps: {
lazy: true,
lazyLoad: this.loadRegionNode,
label: 'title',
value: 'id',
checkStrictly: false,
emitPath: true,
},
page: {
pageSize: 10,
pageSizes: [10, 20, 50, 100],
currentPage: 1,
total: 0,
},
selectionList: [],
option: {
height: 'auto',
calcHeight: 32,
dialogWidth: 980,
tip: false,
searchShow: true,
searchMenuSpan: 6,
border: true,
index: true,
indexLabel: '序号',
indexWidth: 70,
viewBtn: false,
delBtn: false,
editBtn: false,
selection: true,
dialogClickModal: false,
menuWidth: 160,
column: [
{
label: '编码',
prop: 'code',
search: true,
width: 140,
placeholder: '港口如 CNSHG码头如 CNSHG-CT1',
rules: [
{ required: true, message: '请输入编码', trigger: 'blur' },
{ validator: validateCode, trigger: 'blur' },
],
change: ({ value }) => this.handleCodeChange(value),
blur: ({ value }) => this.handleCodeChange(value),
},
{
label: '港口/码头名称',
prop: 'name',
minWidth: 140,
search: true,
rules: [{ required: true, message: '请输入港口/码头名称', trigger: 'blur' }],
},
{
label: '类型',
prop: 'category',
type: 'select',
search: true,
dicData: [
{ label: '全部', value: '' },
{ label: '港口', value: '港口' },
{ label: '码头', value: '码头' },
],
rules: [{ required: true, message: '请选择类型', trigger: 'change' }],
change: ({ value }) => this.handleCategoryChange(value),
},
{
label: '上级港口',
prop: 'parentId',
type: 'select',
props: {
label: 'name',
value: 'id',
},
dicData: [],
hide: true,
rules: [{ required: false, message: '请选择上级港口', trigger: 'change' }],
change: ({ value }) => this.handleParentChange(value),
},
{
label: '上级港口',
prop: 'parentName',
minWidth: 120,
slot: true,
addDisplay: false,
editDisplay: false,
},
{
label: '上级港口编码',
prop: 'parentCode',
minWidth: 120,
slot: true,
disabled: true,
},
{
label: '城市',
prop: 'regionCode',
formslot: true,
hide: true,
span: 12,
rules: [{ required: true, message: '请选择所属城市', trigger: 'change' }],
},
{
label: '国家',
prop: 'country',
search: true,
addDisplay: false,
editDisplay: false,
minWidth: 100,
},
{
label: '城市',
prop: 'city',
search: true,
addDisplay: false,
editDisplay: false,
minWidth: 100,
},
{
label: '经度',
prop: 'longitude',
type: 'number',
precision: 6,
minWidth: 130,
rules: [{ validator: validateLongitude, trigger: 'blur' }],
},
{
label: '纬度',
prop: 'latitude',
type: 'number',
precision: 6,
minWidth: 130,
rules: [{ validator: validateLatitude, trigger: 'blur' }],
},
{
label: '数据来源',
prop: 'dataSource',
type: 'select',
search: true,
dicData: [
{ label: '全部', value: '' },
{ label: '初始化导入', value: '初始化导入' },
{ label: '批量导入', value: '批量导入' },
{ label: '手工导入', value: '手工导入' },
],
},
{
label: '启停状态',
prop: 'status',
type: 'select',
search: true,
slot: true,
dataType: 'number',
dicData: [
{ label: '全部', value: '' },
{ label: '启用', value: 1 },
{ label: '停用', value: 2 },
],
},
{
label: '备注',
prop: 'remark',
type: 'textarea',
minRows: 4,
span: 24,
hide: true,
maxlength: 200,
showWordLimit: true,
rules: [{ max: 200, message: '备注不能超过200个字', trigger: 'blur' }],
},
{
label: '更新人',
prop: 'updateUserName',
formatter: formatUpdateUserName,
addDisplay: false,
editDisplay: false,
minWidth: 120,
},
{
label: '更新时间',
prop: 'updateTime',
type: 'datetime',
format: 'YYYY-MM-DD HH:mm:ss',
valueFormat: 'YYYY-MM-DD HH:mm:ss',
addDisplay: false,
editDisplay: false,
minWidth: 160,
},
{
label: '创建时间',
prop: 'createTime',
type: 'datetime',
format: 'YYYY-MM-DD HH:mm:ss',
valueFormat: 'YYYY-MM-DD HH:mm:ss',
addDisplay: false,
editDisplay: false,
display: false,
minWidth: 160,
},
],
},
excelOption: {
submitBtn: false,
emptyBtn: false,
column: [
{
label: '模板上传',
prop: 'excelFile',
type: 'upload',
drag: true,
loadText: '模板上传中,请稍等',
span: 24,
propsHttp: {
res: 'data',
},
tip: '请上传 .xls,.xlsx 标准格式文件',
accept: '.xls,.xlsx',
action: '/blade-system/port-terminal/import-port-terminal',
},
{
label: '模板下载',
prop: 'excelTemplate',
formslot: true,
span: 24,
},
],
},
};
},
computed: {
...mapGetters(['permission', 'userInfo']),
permissionList() {
return {
addBtn: this.hasPermission('port_terminal_add'),
};
},
isAdmin() {
const authority = this.userInfo && this.userInfo.authority;
return Array.isArray(authority) ? authority.includes('admin') : String(authority || '').includes('admin');
},
isParentRegionLocked() {
return this.form.category === '码头' && !!this.form.parentId;
},
ids() {
let ids = [];
this.selectionList.forEach(ele => {
ids.push(ele.id);
});
return ids.join(',');
},
},
created() {
this.loadPortOptions();
},
methods: {
hasPermission(code) {
return this.isAdmin || this.validData(this.permission && this.permission[code], false);
},
handleCodeChange(value) {
const code = String(value || '').toUpperCase();
if (this.form.category === '港口') {
this.form.code = code.replace(/[^A-Z]/g, '').slice(0, 5);
return;
}
if (this.form.category === '码头') {
this.form.code = code.replace(/[^A-Z0-9-]/g, '');
}
},
loadRegionNode(node, resolve) {
const parentCode = node.level === 0 ? '00' : node.value;
getLazyTree(parentCode).then(res => {
const regionList = res.data.data || [];
const nodes = regionList.map(region => {
this.regionNodeMap[region.id] = region;
this.regionNameMap[region.title] = region.id;
return {
id: region.id,
title: region.title,
leaf: node.level >= 1,
};
});
resolve(nodes);
});
},
loadPortOptions() {
getPortSelect().then(res => {
this.portOptions = res.data.data;
this.findColumn(this.option.column, 'parentId').dicData = this.portOptions;
});
},
handleCategoryChange(value) {
const parentColumn = this.findColumn(this.option.column, 'parentId');
parentColumn.rules[0].required = value === '码头';
if (value === '港口') {
this.form.parentId = undefined;
this.form.parentCode = '';
this.form.parentName = '';
}
this.handleCodeChange(this.form.code);
},
handleParentChange(value) {
const parent = this.portOptions.find(item => item.id === value);
if (!parent) return;
const terminalCode = String(this.form.code || '')
.split('-')
.slice(1)
.join('-');
this.form.parentCode = parent.code;
this.form.parentName = parent.name;
if (this.form.category === '码头' && terminalCode) {
this.form.code = `${parent.code}-${terminalCode}`;
}
this.form.country = parent.country;
this.form.city = parent.city;
this.resolveRegionCode(parent.country, parent.city).then(regionCode => {
this.form.regionCode = regionCode;
});
},
handleRegionChange(value) {
const regionCode = Array.isArray(value) ? value : [];
const provinceCode = regionCode[0];
const cityCode = regionCode[1];
const province = this.regionNodeMap[provinceCode];
const city = this.regionNodeMap[cityCode];
this.form.country = province ? province.title : '';
this.form.city = city ? city.title : '';
},
resolveRegionCode(country, city) {
if (!country || !city) {
return Promise.resolve([]);
}
const provinceCode = this.regionNameMap[country];
if (provinceCode) {
const cityCode = this.regionNameMap[city];
if (cityCode) {
return Promise.resolve([provinceCode, cityCode]);
}
return this.loadRegionList(provinceCode).then(cityList => {
const cityNode = cityList.find(item => item.title === city);
return cityNode ? [provinceCode, cityNode.id] : [provinceCode];
});
}
return this.loadRegionList('00').then(provinceList => {
const province = provinceList.find(item => item.title === country);
if (!province) {
return [];
}
return this.loadRegionList(province.id).then(cityList => {
const cityNode = cityList.find(item => item.title === city);
return cityNode ? [province.id, cityNode.id] : [province.id];
});
});
},
loadRegionList(parentCode) {
return getLazyTree(parentCode).then(res => {
const regionList = res.data.data || [];
regionList.forEach(region => {
this.regionNodeMap[region.id] = region;
this.regionNameMap[region.title] = region.id;
});
return regionList;
});
},
normalizeRow(row) {
row.code = String(row.code || '').toUpperCase();
if (row.category === '港口') {
row.parentId = undefined;
row.parentCode = undefined;
row.parentName = undefined;
}
if (!row.dataSource) row.dataSource = '手工导入';
if (!row.status) row.status = 1;
return row;
},
validateRequiredFields(row) {
const isBlank = value => value === undefined || value === null || String(value).trim() === '';
if (isBlank(row.code)) {
this.$message.warning('请输入编码');
return false;
}
if (isBlank(row.name)) {
this.$message.warning('请输入港口/码头名称');
return false;
}
if (isBlank(row.category)) {
this.$message.warning('请选择类型');
return false;
}
if (row.category === '码头' && isBlank(row.parentId)) {
this.$message.warning('请选择上级港口');
return false;
}
if (!Array.isArray(row.regionCode) || row.regionCode.length < 2) {
this.$message.warning('请选择所属城市');
return false;
}
return true;
},
stopSubmitLoading(loading) {
if (typeof loading === 'function') {
loading();
}
},
rowSave(row, done, loading) {
const submitRow = this.normalizeRow(row);
if (!this.validateRequiredFields(submitRow)) {
this.stopSubmitLoading(loading);
return;
}
submit(submitRow).then(
() => {
this.onLoad(this.page);
this.loadPortOptions();
this.$message({ type: 'success', message: '操作成功!' });
done();
},
error => {
window.console.log(error);
loading();
}
);
},
rowUpdate(row, index, done, loading) {
const submitRow = this.normalizeRow(row);
if (!this.validateRequiredFields(submitRow)) {
this.stopSubmitLoading(loading);
return;
}
submit(submitRow).then(
() => {
this.onLoad(this.page);
this.loadPortOptions();
this.$message({ type: 'success', message: '操作成功!' });
done();
},
error => {
window.console.log(error);
loading();
}
);
},
rowDel(row) {
this.$confirm('确定将选择数据删除?', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
})
.then(() => remove(row.id))
.then(() => {
this.onLoad(this.page);
this.loadPortOptions();
this.$message({ type: 'success', message: '操作成功!' });
});
},
handleDelete() {
if (this.selectionList.length === 0) {
this.$message.warning('请选择至少一条数据');
return;
}
this.$confirm('确定将选择数据删除?', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
})
.then(() => remove(this.ids))
.then(() => {
this.onLoad(this.page);
this.loadPortOptions();
this.$message({ type: 'success', message: '操作成功!' });
this.$refs.crud.toggleSelection();
});
},
handleStatus(row) {
const nextStatus = row.status === 1 ? 2 : 1;
const actionName = nextStatus === 1 ? '启用' : '停用';
this.$confirm(`是否确认${actionName}该条数据?`, {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
})
.then(() => changeStatus(row.id, nextStatus))
.then(() => {
this.onLoad(this.page);
this.loadPortOptions();
this.$message({ type: 'success', message: '操作成功!' });
});
},
beforeOpen(done, type) {
if (type === 'add') {
this.form.category = this.form.category || '港口';
this.form.dataSource = this.form.dataSource || '手工导入';
this.form.status = this.form.status || 1;
}
this.handleCategoryChange(this.form.category || '港口');
if (['edit', 'view'].includes(type)) {
getDetail(this.form.id).then(res => {
this.form = res.data.data;
this.resolveRegionCode(this.form.country, this.form.city).then(regionCode => {
this.form.regionCode = regionCode;
this.handleCategoryChange(this.form.category);
done();
});
});
return;
} else {
this.resolveRegionCode(this.form.country, this.form.city).then(regionCode => {
this.form.regionCode = regionCode;
done();
});
return;
}
},
searchReset() {
this.query = {};
this.onLoad(this.page);
},
searchChange(params, done) {
this.query = params;
this.page.currentPage = 1;
this.onLoad(this.page, params);
done();
},
selectionChange(list) {
this.selectionList = list;
},
selectionClear() {
this.selectionList = [];
this.$refs.crud.toggleSelection();
},
currentChange(currentPage) {
this.page.currentPage = currentPage;
},
sizeChange(pageSize) {
this.page.pageSize = pageSize;
},
refreshChange() {
this.onLoad(this.page, this.query);
},
onLoad(page, params = {}) {
this.loading = true;
getList(page.currentPage, page.pageSize, { ...params, ...this.query })
.then(res => {
const data = res.data.data;
this.page.total = data.total;
this.data = data.records;
this.selectionClear();
})
.finally(() => {
this.loading = false;
});
},
handleImport() {
this.excelBox = true;
},
uploadBefore(file, done) {
const fileName = file && file.name ? file.name.toLowerCase() : '';
if (!/\.(xls|xlsx)$/.test(fileName)) {
this.$message.error('请上传 .xls,.xlsx 标准格式文件');
return false;
}
if (typeof done === 'function') {
done();
}
return true;
},
uploadAfter(res, done) {
this.excelBox = false;
this.onLoad(this.page);
this.loadPortOptions();
done();
},
handleExport() {
this.$confirm('是否导出港口码头主数据?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
}).then(() => {
NProgress.start();
exportBlob('/blade-system/port-terminal/export-port-terminal', this.buildExportParams())
.then(res => {
downloadXls(
res.data,
`港口码头主数据${this.$dayjs().format('YYYY-MM-DD HH:mm:ss')}.xlsx`
);
})
.finally(() => {
NProgress.done();
});
});
},
buildExportParams() {
return {
...this.query,
ids: this.ids,
[this.website.tokenHeader]: getToken(),
};
},
handleTemplate() {
exportBlob(
`/blade-system/port-terminal/export-template?${this.website.tokenHeader}=${getToken()}`
).then(res => {
downloadXls(res.data, '港口码头主数据模板.xlsx');
});
},
},
};
</script>
<style lang="scss" scoped>
.port-terminal-page {
:deep(.avue-crud__header),
:deep(.el-table th .cell),
:deep(.el-table td .cell) {
white-space: nowrap;
}
}
</style>

View File

@@ -0,0 +1,663 @@
<template>
<basic-container class="railway-station-page">
<avue-crud
:option="option"
:table-loading="loading"
:data="data"
v-model:page="page"
v-model="form"
ref="crud"
:permission="permissionList"
:before-open="beforeOpen"
@row-save="rowSave"
@row-update="rowUpdate"
@row-del="rowDel"
@search-change="searchChange"
@search-reset="searchReset"
@selection-change="selectionChange"
@current-change="currentChange"
@size-change="sizeChange"
@refresh-change="refreshChange"
@on-load="onLoad"
>
<template #menu-left>
<el-button
type="primary"
icon="el-icon-upload"
plain
v-if="hasPermission('railway_station_import')"
@click="handleImport"
>批量导入
</el-button>
<el-button
type="primary"
icon="el-icon-download"
plain
v-if="hasPermission('railway_station_template')"
@click="handleTemplate"
>下载模板
</el-button>
<el-button
type="primary"
icon="el-icon-download"
plain
v-if="hasPermission('railway_station_export')"
@click="handleExport"
>批量导出
</el-button>
<el-button
type="danger"
icon="el-icon-delete"
plain
v-if="hasPermission('railway_station_delete')"
@click="handleDelete"
>批量删除
</el-button>
</template>
<template #status="{ row }">
<el-tag :type="row.status === 1 ? 'primary' : 'info'">
{{ row.status === 1 ? '启用' : '停用' }}
</el-tag>
</template>
<template #menu="{ row, index }">
<el-button
type="primary"
text
icon="el-icon-edit"
v-if="hasPermission('railway_station_edit')"
@click="$refs.crud.rowEdit(row, index)"
>
编辑
</el-button>
<el-button
type="primary"
text
:icon="row.status === 1 ? 'el-icon-close' : 'el-icon-check'"
v-if="hasPermission('railway_station_status')"
@click="handleStatus(row)"
>
{{ row.status === 1 ? '停用' : '启用' }}
</el-button>
</template>
</avue-crud>
<el-dialog title="铁路车站主数据导入" append-to-body v-model="excelBox" width="555px">
<avue-form
:option="excelOption"
v-model="excelForm"
:upload-before="uploadBefore"
:upload-after="uploadAfter"
>
<template #excelTemplate>
<el-button type="primary" @click="handleTemplate">
点击下载<i class="el-icon-download el-icon--right"></i>
</el-button>
</template>
</avue-form>
</el-dialog>
</basic-container>
</template>
<script>
import { getList, getDetail, submit, remove, changeStatus } from '@/api/base/railway-station';
import { getLazyTree } from '@/api/base/region';
import { exportBlob } from '@/api/common';
import { mapGetters } from 'vuex';
import { downloadXls } from '@/utils/util';
import { formatUpdateUserName } from '@/utils/audit';
import { getToken } from '@/utils/auth';
import NProgress from 'nprogress';
import 'nprogress/nprogress.css';
export default {
data() {
const validateTmisCode = (rule, value, callback) => {
if (!/^\d{5}$/.test(value || '')) {
callback(new Error('TMIS国标编码为5位数字'));
} else {
callback();
}
};
const validateTelegraphCode = (rule, value, callback) => {
if (!/^[A-Z]{3}$/.test(String(value || '').toUpperCase())) {
callback(new Error('电报码为3位大写字母'));
} else {
callback();
}
};
const validateLongitude = (rule, value, callback) => {
if (value === undefined || value === null || value === '') {
callback();
} else if (Number(value) < -180 || Number(value) > 180) {
callback(new Error('经度范围为 -180 到 180'));
} else {
callback();
}
};
const validateLatitude = (rule, value, callback) => {
if (value === undefined || value === null || value === '') {
callback();
} else if (Number(value) < -90 || Number(value) > 90) {
callback(new Error('纬度范围为 -90 到 90'));
} else {
callback();
}
};
return {
form: {},
query: {},
loading: true,
data: [],
excelBox: false,
excelForm: {},
provinceOptions: [],
cityOptions: [],
page: {
pageSize: 10,
pageSizes: [10, 20, 50, 100],
currentPage: 1,
total: 0,
},
selectionList: [],
option: {
height: 'auto',
calcHeight: 32,
dialogWidth: 980,
tip: false,
searchShow: true,
searchMenuSpan: 6,
border: true,
index: true,
indexLabel: '序号',
indexWidth: 70,
viewBtn: false,
delBtn: false,
editBtn: false,
selection: true,
dialogClickModal: false,
menuWidth: 160,
column: [
{
label: '编码',
prop: 'code',
search: true,
addDisabled: true,
editDisabled: true,
placeholder: '系统自动生成',
searchPlaceholder: '请输入编码',
},
{
label: 'TMIS国标编码',
prop: 'tmisCode',
minWidth: 120,
maxlength: 5,
rules: [
{ required: true, message: '请输入TMIS国标编码', trigger: 'blur' },
{ validator: validateTmisCode, trigger: 'blur' },
],
change: ({ value }) => this.handleTmisChange(value),
},
{
label: '电报码',
prop: 'telegraphCode',
minWidth: 100,
maxlength: 3,
rules: [
{ required: true, message: '请输入电报码', trigger: 'blur' },
{ validator: validateTelegraphCode, trigger: 'blur' },
],
change: ({ value }) => this.handleTelegraphChange(value),
blur: ({ value }) => this.handleTelegraphChange(value),
},
{
label: '车站名称',
prop: 'name',
minWidth: 120,
search: true,
rules: [{ required: true, message: '请输入车站名称', trigger: 'blur' }],
},
{
label: '所属铁路线路',
prop: 'railwayLine',
minWidth: 130,
},
{
label: '所属省份',
prop: 'provinceCode',
type: 'select',
hide: true,
props: {
label: 'title',
value: 'id',
},
dicData: [],
filterable: true,
span: 12,
rules: [{ required: true, message: '请选择所属省份', trigger: 'change' }],
change: ({ value }) => this.handleProvinceChange(value),
},
{
label: '所属城市',
prop: 'cityCode',
type: 'select',
hide: true,
props: {
label: 'title',
value: 'id',
},
dicData: [],
filterable: true,
span: 12,
rules: [{ required: true, message: '请选择所属城市', trigger: 'change' }],
change: ({ value }) => this.handleCityChange(value),
},
{
label: '所属省份',
prop: 'provinceName',
minWidth: 140,
addDisplay: false,
editDisplay: false,
},
{
label: '所属城市',
prop: 'cityName',
minWidth: 140,
addDisplay: false,
editDisplay: false,
},
{
label: '经度',
prop: 'longitude',
type: 'number',
precision: 6,
rules: [{ validator: validateLongitude, trigger: 'blur' }],
},
{
label: '纬度',
prop: 'latitude',
type: 'number',
precision: 6,
rules: [{ validator: validateLatitude, trigger: 'blur' }],
},
{
label: '数据来源',
prop: 'dataSource',
type: 'select',
search: true,
dicData: [
{ label: '全部', value: '' },
{ label: '初始化导入', value: '初始化导入' },
{ label: '批量', value: '批量' },
{ label: '手动', value: '手动' },
],
},
{
label: '启停状态',
prop: 'status',
type: 'select',
search: true,
slot: true,
dataType: 'number',
dicData: [
{ label: '全部', value: '' },
{ label: '启用', value: 1 },
{ label: '停用', value: 2 },
],
},
{
label: '备注',
prop: 'remark',
type: 'textarea',
minRows: 4,
span: 24,
hide: true,
maxlength: 200,
showWordLimit: true,
rules: [{ max: 200, message: '备注不能超过200字', trigger: 'blur' }],
},
{
label: '更新人',
prop: 'updateUserName',
formatter: formatUpdateUserName,
addDisplay: false,
editDisplay: false,
minWidth: 120,
},
{
label: '更新时间',
prop: 'updateTime',
type: 'datetime',
format: 'YYYY-MM-DD HH:mm:ss',
valueFormat: 'YYYY-MM-DD HH:mm:ss',
addDisplay: false,
editDisplay: false,
display: false,
minWidth: 160,
},
{
label: '创建时间',
prop: 'createTime',
type: 'datetime',
format: 'YYYY-MM-DD HH:mm:ss',
valueFormat: 'YYYY-MM-DD HH:mm:ss',
addDisplay: false,
editDisplay: false,
display: false,
minWidth: 160,
},
],
},
excelOption: {
submitBtn: false,
emptyBtn: false,
column: [
{
label: '模板上传',
prop: 'excelFile',
type: 'upload',
drag: true,
loadText: '模板上传中,请稍等',
span: 24,
propsHttp: {
res: 'data',
},
tip: '请上传 .xls,.xlsx 标准格式文件',
accept: '.xls,.xlsx',
action: '/blade-system/railway-station/import-railway-station',
},
{
label: '模板下载',
prop: 'excelTemplate',
formslot: true,
span: 24,
},
],
},
};
},
computed: {
...mapGetters(['permission', 'userInfo']),
permissionList() {
return {
addBtn: this.hasPermission('railway_station_add'),
};
},
isAdmin() {
const authority = this.userInfo && this.userInfo.authority;
return Array.isArray(authority) ? authority.includes('admin') : String(authority || '').includes('admin');
},
ids() {
let ids = [];
this.selectionList.forEach(ele => {
ids.push(ele.id);
});
return ids.join(',');
},
},
created() {
this.loadProvinceOptions();
},
methods: {
hasPermission(code) {
return this.isAdmin || this.validData(this.permission && this.permission[code], false);
},
findColumn(prop) {
return this.option.column.find(item => item.prop === prop);
},
loadProvinceOptions() {
getLazyTree('00').then(res => {
this.provinceOptions = res.data.data;
this.findColumn('provinceCode').dicData = this.provinceOptions;
});
},
loadCityOptions(provinceCode) {
if (!provinceCode) {
this.cityOptions = [];
this.findColumn('cityCode').dicData = [];
return Promise.resolve();
}
return getLazyTree(provinceCode).then(res => {
this.cityOptions = res.data.data;
this.findColumn('cityCode').dicData = this.cityOptions;
});
},
handleTmisChange(value) {
this.form.tmisCode = String(value || '')
.replace(/\D/g, '')
.slice(0, 5);
this.form.code = this.form.tmisCode ? `TL${this.form.tmisCode}` : '';
},
handleTelegraphChange(value) {
this.form.telegraphCode = String(value || '')
.toUpperCase()
.replace(/[^A-Z]/g, '')
.slice(0, 3);
},
handleProvinceChange(value) {
const province = this.provinceOptions.find(item => item.id === value);
this.form.provinceName = province ? province.title : '';
this.form.cityCode = undefined;
this.form.cityName = '';
this.loadCityOptions(value);
},
handleCityChange(value) {
const city = this.cityOptions.find(item => item.id === value);
this.form.cityName = city ? city.title : '';
},
normalizeRow(row) {
row.code = row.tmisCode ? `TL${row.tmisCode}` : row.code;
if (!row.dataSource) row.dataSource = '手动';
if (!row.status) row.status = 1;
return row;
},
validateUnique(row) {
const rowId = String(row.id || '');
const hasDuplicate = (params, prop) => {
return getList(1, 10, params).then(res => {
const records = res.data.data.records || [];
return records.some(item => item[prop] === row[prop] && String(item.id || '') !== rowId);
});
};
return Promise.all([
hasDuplicate({ tmisCode: row.tmisCode }, 'tmisCode'),
hasDuplicate({ telegraphCode: row.telegraphCode }, 'telegraphCode'),
]).then(([tmisExists, telegraphExists]) => {
if (tmisExists) {
return Promise.reject(new Error('该TMIS编码已存在'));
}
if (telegraphExists) {
return Promise.reject(new Error('该电报码已存在'));
}
return Promise.resolve();
});
},
handleSubmitError(error, loading) {
const uniqueMessages = ['该TMIS编码已存在', '该电报码已存在'];
if (uniqueMessages.includes(error.message)) {
this.$message.warning(error.message);
}
window.console.log(error);
loading();
},
rowSave(row, done, loading) {
const submitRow = this.normalizeRow(row);
this.validateUnique(submitRow)
.then(() => submit(submitRow))
.then(() => {
this.onLoad(this.page);
this.$message({ type: 'success', message: '操作成功!' });
done();
})
.catch(error => this.handleSubmitError(error, loading));
},
rowUpdate(row, index, done, loading) {
const submitRow = this.normalizeRow(row);
this.validateUnique(submitRow)
.then(() => submit(submitRow))
.then(() => {
this.onLoad(this.page);
this.$message({ type: 'success', message: '操作成功!' });
done();
})
.catch(error => this.handleSubmitError(error, loading));
},
rowDel(row) {
this.$confirm('确定将选择数据删除?', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
})
.then(() => remove(row.id))
.then(() => {
this.onLoad(this.page);
this.$message({ type: 'success', message: '操作成功!' });
});
},
handleDelete() {
if (this.selectionList.length === 0) {
this.$message.warning('请选择至少一条数据');
return;
}
this.$confirm('确定将选择数据删除?', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
})
.then(() => remove(this.ids))
.then(() => {
this.onLoad(this.page);
this.$message({ type: 'success', message: '操作成功!' });
this.$refs.crud.toggleSelection();
});
},
handleStatus(row) {
const nextStatus = row.status === 1 ? 2 : 1;
const actionName = nextStatus === 1 ? '启用' : '停用';
this.$confirm(`是否确认${actionName}该条数据?`, {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
})
.then(() => changeStatus(row.id, nextStatus))
.then(() => {
this.onLoad(this.page);
this.$message({ type: 'success', message: '操作成功!' });
});
},
beforeOpen(done, type) {
if (['edit', 'view'].includes(type)) {
getDetail(this.form.id).then(res => {
this.form = res.data.data;
this.loadCityOptions(this.form.provinceCode).then(() => done());
});
return;
}
this.form.code = '';
this.form.dataSource = '手动';
this.form.status = 1;
this.loadCityOptions(this.form.provinceCode).then(() => done());
},
searchReset() {
this.query = {};
this.onLoad(this.page);
},
searchChange(params, done) {
this.query = params;
this.page.currentPage = 1;
this.onLoad(this.page, params);
done();
},
selectionChange(list) {
this.selectionList = list;
},
selectionClear() {
this.selectionList = [];
this.$refs.crud.toggleSelection();
},
currentChange(currentPage) {
this.page.currentPage = currentPage;
},
sizeChange(pageSize) {
this.page.pageSize = pageSize;
},
refreshChange() {
this.onLoad(this.page, this.query);
},
onLoad(page, params = {}) {
this.loading = true;
getList(page.currentPage, page.pageSize, { ...params, ...this.query })
.then(res => {
const data = res.data.data;
this.page.total = data.total;
this.data = data.records;
this.selectionClear();
})
.finally(() => {
this.loading = false;
});
},
handleImport() {
this.excelBox = true;
},
uploadBefore(file, done) {
const fileName = file && file.name ? file.name.toLowerCase() : '';
if (!/\.(xls|xlsx)$/.test(fileName)) {
this.$message.error('请上传 .xls,.xlsx 标准格式文件');
return false;
}
if (typeof done === 'function') {
done();
}
return true;
},
uploadAfter(res, done) {
this.excelBox = false;
this.onLoad(this.page);
done();
},
handleExport() {
this.$confirm('是否导出铁路车站主数据?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
}).then(() => {
NProgress.start();
exportBlob('/blade-system/railway-station/export-railway-station', this.buildExportParams())
.then(res => {
downloadXls(
res.data,
`铁路车站主数据${this.$dayjs().format('YYYY-MM-DD HH:mm:ss')}.xlsx`
);
})
.finally(() => {
NProgress.done();
});
});
},
buildExportParams() {
return {
...this.query,
ids: this.ids,
[this.website.tokenHeader]: getToken(),
};
},
handleTemplate() {
exportBlob(
`/blade-system/railway-station/export-template?${this.website.tokenHeader}=${getToken()}`
).then(res => {
downloadXls(res.data, '铁路车站主数据模板.xlsx');
});
},
},
};
</script>
<style lang="scss" scoped>
.railway-station-page {
:deep(.avue-crud__header),
:deep(.el-table th .cell),
:deep(.el-table td .cell) {
white-space: nowrap;
}
}
</style>

View File

@@ -40,6 +40,14 @@
@click="handleExport"
>导出
</el-button>
<el-button
v-if="permission.region_sync"
type="primary"
icon="el-icon-refresh"
:loading="syncLoading"
@click="handleSync"
>同步
</el-button>
<el-button
v-if="permission.region_debug"
type="primary"
@@ -75,7 +83,7 @@
</template>
<script>
import { getLazyTree, getDetail, submit, remove } from '@/api/base/region';
import { getLazyTree, getDetail, submit, remove, sync } from '@/api/base/region';
import { exportBlob } from '@/api/common';
import { mapGetters } from 'vuex';
import { validatenull } from '@/utils/validate';
@@ -91,6 +99,7 @@ export default {
treeCode: '',
treeParentCode: '',
treeData: [],
syncLoading: false,
treeOption: {
nodeKey: 'id',
lazy: true,
@@ -431,6 +440,28 @@ export default {
handleImport() {
this.excelBox = true;
},
handleSync() {
this.$confirm('确定同步最新行政区划数据?', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
})
.then(() => {
this.syncLoading = true;
return sync();
})
.then(() => {
this.$message({
type: 'success',
message: '同步成功!',
});
this.initTree();
this.regionForm = {};
})
.finally(() => {
this.syncLoading = false;
});
},
handleExport() {
this.$confirm('是否导出行政区划数据?', '提示', {
confirmButtonText: '确定',