Commit b8d9ea1b15f3d70905c01447984538bb5f557e99
1 parent
9c977621
feat: 新增文件上传模板
Showing
3 changed files
with
338 additions
and
21 deletions
src/api/template/template.js
0 → 100644
| 1 | +import request from '@/utils/request' | |
| 2 | + | |
| 3 | +// 查询车队与线路对应模板列表 | |
| 4 | +export function listTemplate(query) { | |
| 5 | + return request({ | |
| 6 | + url: '/template/template/list', | |
| 7 | + method: 'get', | |
| 8 | + params: query | |
| 9 | + }) | |
| 10 | +} | |
| 11 | + | |
| 12 | +// 查询车队与线路对应模板详细 | |
| 13 | +export function getTemplate(id) { | |
| 14 | + return request({ | |
| 15 | + url: '/template/template/' + id, | |
| 16 | + method: 'get' | |
| 17 | + }) | |
| 18 | +} | |
| 19 | + | |
| 20 | +// 新增车队与线路对应模板 | |
| 21 | +export function addTemplate(data) { | |
| 22 | + return request({ | |
| 23 | + url: '/template/template', | |
| 24 | + method: 'post', | |
| 25 | + data: data | |
| 26 | + }) | |
| 27 | +} | |
| 28 | + | |
| 29 | +// 修改车队与线路对应模板 | |
| 30 | +export function updateTemplate(data) { | |
| 31 | + return request({ | |
| 32 | + url: '/template/template', | |
| 33 | + method: 'put', | |
| 34 | + data: data | |
| 35 | + }) | |
| 36 | +} | |
| 37 | + | |
| 38 | +// 删除车队与线路对应模板 | |
| 39 | +export function delTemplate(id) { | |
| 40 | + return request({ | |
| 41 | + url: '/template/template/' + id, | |
| 42 | + method: 'delete' | |
| 43 | + }) | |
| 44 | +} | ... | ... |
src/components/FileUpload/index.vue
| 1 | 1 | <template> |
| 2 | 2 | <div class="upload-file"> |
| 3 | - <el-upload | |
| 4 | - multiple | |
| 5 | - :action="uploadFileUrl" | |
| 6 | - :before-upload="handleBeforeUpload" | |
| 7 | - :file-list="fileList" | |
| 8 | - :limit="limit" | |
| 9 | - :on-error="handleUploadError" | |
| 10 | - :on-exceed="handleExceed" | |
| 11 | - :on-success="handleUploadSuccess" | |
| 12 | - :show-file-list="false" | |
| 13 | - :headers="headers" | |
| 14 | - class="upload-file-uploader" | |
| 15 | - ref="fileUpload" | |
| 16 | - > | |
| 3 | + <el-upload multiple :action="uploadFileUrl" :before-upload="handleBeforeUpload" :file-list="fileList" :limit="limit" | |
| 4 | + :on-error="handleUploadError" :on-exceed="handleExceed" :on-success="handleUploadSuccess" :show-file-list="false" | |
| 5 | + :headers="headers" class="upload-file-uploader" ref="fileUpload"> | |
| 17 | 6 | <!-- 上传按钮 --> |
| 18 | 7 | <el-button type="primary">选取文件</el-button> |
| 19 | 8 | </el-upload> |
| ... | ... | @@ -56,12 +45,19 @@ const props = defineProps({ |
| 56 | 45 | // 文件类型, 例如['png', 'jpg', 'jpeg'] |
| 57 | 46 | fileType: { |
| 58 | 47 | type: Array, |
| 59 | - default: () => ["doc", "xls", "ppt", "txt", "pdf"], | |
| 48 | + default: () => ["doc", "docx", "xls", "xlsx", "ppt", "txt", "pdf"], | |
| 60 | 49 | }, |
| 61 | 50 | // 是否显示提示 |
| 62 | 51 | isShowTip: { |
| 63 | 52 | type: Boolean, |
| 64 | 53 | default: true |
| 54 | + }, | |
| 55 | + prefix: { | |
| 56 | + type: String, | |
| 57 | + default: "/common/upload" | |
| 58 | + }, | |
| 59 | + callBackUpload: { | |
| 60 | + type: Function, | |
| 65 | 61 | } |
| 66 | 62 | }); |
| 67 | 63 | |
| ... | ... | @@ -70,7 +66,7 @@ const emit = defineEmits(); |
| 70 | 66 | const number = ref(0); |
| 71 | 67 | const uploadList = ref([]); |
| 72 | 68 | const baseUrl = import.meta.env.VITE_APP_BASE_API; |
| 73 | -const uploadFileUrl = ref(import.meta.env.VITE_APP_BASE_API + "/common/upload"); // 上传文件服务器地址 | |
| 69 | +const uploadFileUrl = ref(import.meta.env.VITE_APP_BASE_API + props.prefix); // 上传文件服务器地址 | |
| 74 | 70 | const headers = ref({ Authorization: "Bearer " + getToken() }); |
| 75 | 71 | const fileList = ref([]); |
| 76 | 72 | const showTip = computed( |
| ... | ... | @@ -94,7 +90,7 @@ watch(() => props.modelValue, val => { |
| 94 | 90 | fileList.value = []; |
| 95 | 91 | return []; |
| 96 | 92 | } |
| 97 | -},{ deep: true, immediate: true }); | |
| 93 | +}, { deep: true, immediate: true }); | |
| 98 | 94 | |
| 99 | 95 | // 上传前校检格式和大小 |
| 100 | 96 | function handleBeforeUpload(file) { |
| ... | ... | @@ -160,14 +156,24 @@ function uploadedSuccessfully() { |
| 160 | 156 | emit("update:modelValue", listToString(fileList.value)); |
| 161 | 157 | proxy.$modal.closeLoading(); |
| 162 | 158 | } |
| 159 | + try { | |
| 160 | + proxy.callBackUpload(); | |
| 161 | + } catch (error) { | |
| 162 | + | |
| 163 | + } | |
| 163 | 164 | } |
| 164 | 165 | |
| 165 | 166 | // 获取文件名称 |
| 166 | 167 | function getFileName(name) { |
| 167 | - if (name.lastIndexOf("/") > -1) { | |
| 168 | - return name.slice(name.lastIndexOf("/") + 1); | |
| 169 | - } else { | |
| 170 | - return ""; | |
| 168 | + console.log(name); | |
| 169 | + try { | |
| 170 | + if (name.lastIndexOf("/") > -1) { | |
| 171 | + return name.slice(name.lastIndexOf("/") + 1); | |
| 172 | + } else { | |
| 173 | + return ""; | |
| 174 | + } | |
| 175 | + } catch (res) { | |
| 176 | + return "文件" | |
| 171 | 177 | } |
| 172 | 178 | } |
| 173 | 179 | |
| ... | ... | @@ -188,18 +194,21 @@ function listToString(list, separator) { |
| 188 | 194 | .upload-file-uploader { |
| 189 | 195 | margin-bottom: 5px; |
| 190 | 196 | } |
| 197 | + | |
| 191 | 198 | .upload-file-list .el-upload-list__item { |
| 192 | 199 | border: 1px solid #e4e7ed; |
| 193 | 200 | line-height: 2; |
| 194 | 201 | margin-bottom: 10px; |
| 195 | 202 | position: relative; |
| 196 | 203 | } |
| 204 | + | |
| 197 | 205 | .upload-file-list .ele-upload-list__item-content { |
| 198 | 206 | display: flex; |
| 199 | 207 | justify-content: space-between; |
| 200 | 208 | align-items: center; |
| 201 | 209 | color: inherit; |
| 202 | 210 | } |
| 211 | + | |
| 203 | 212 | .ele-upload-list__item-content-action .el-link { |
| 204 | 213 | margin-right: 10px; |
| 205 | 214 | } | ... | ... |
src/views/template/template/index.vue
0 → 100644
| 1 | +<template> | |
| 2 | + <div class="app-container"> | |
| 3 | + <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="100px"> | |
| 4 | + <el-form-item label="车队名称" prop="fleetName"> | |
| 5 | + <el-input v-model="queryParams.fleetName" placeholder="请输入车队名称" clearable @keyup.enter="handleQuery" /> | |
| 6 | + </el-form-item> | |
| 7 | + <el-form-item label="线路名称" prop="lineName"> | |
| 8 | + <el-input v-model="queryParams.lineName" placeholder="请输入线路名称" clearable @keyup.enter="handleQuery" /> | |
| 9 | + </el-form-item> | |
| 10 | + <el-form-item> | |
| 11 | + <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button> | |
| 12 | + <el-button icon="Refresh" @click="resetQuery">重置</el-button> | |
| 13 | + </el-form-item> | |
| 14 | + </el-form> | |
| 15 | + | |
| 16 | + <el-row :gutter="10" class="mb8"> | |
| 17 | + <el-col :span="1.5"> | |
| 18 | + <el-button type="primary" plain icon="Plus" @click="handleAdd" | |
| 19 | + v-hasPermi="['template:template:add']">新增</el-button> | |
| 20 | + </el-col> | |
| 21 | + <el-col :span="1.5"> | |
| 22 | + <el-button type="success" plain icon="Edit" :disabled="single" @click="handleUpdate" | |
| 23 | + v-hasPermi="['template:template:edit']">修改</el-button> | |
| 24 | + </el-col> | |
| 25 | + <el-col :span="1.5"> | |
| 26 | + <el-button type="danger" plain icon="Delete" :disabled="multiple" @click="handleDelete" | |
| 27 | + v-hasPermi="['template:template:remove']">删除</el-button> | |
| 28 | + </el-col> | |
| 29 | + <el-col :span="1.5"> | |
| 30 | + <el-button type="warning" plain icon="Download" @click="handleExport" | |
| 31 | + v-hasPermi="['template:template:export']">导出</el-button> | |
| 32 | + </el-col> | |
| 33 | + <el-col :span="1.5"> | |
| 34 | + <el-button type="warning" plain icon="Download" @click="handleDownloadTemplate" | |
| 35 | + v-hasPermi="['template:template:export']">下载全量导入模板</el-button> | |
| 36 | + </el-col> | |
| 37 | + <el-col :span="1.5"> | |
| 38 | + <el-button type="warning" plain icon="Upload" @click="handleImport" | |
| 39 | + v-hasPermi="['template:template:import']">上传全量导入文件</el-button> | |
| 40 | + </el-col> | |
| 41 | + <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar> | |
| 42 | + </el-row> | |
| 43 | + | |
| 44 | + <el-table v-loading="loading" :data="templateList" @selection-change="handleSelectionChange"> | |
| 45 | + <el-table-column type="selection" width="55" align="center" /> | |
| 46 | + <el-table-column label="序号" type="index" width="60" align="center"> | |
| 47 | + <template #default="scope"> | |
| 48 | + {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }} | |
| 49 | + </template> | |
| 50 | + </el-table-column> | |
| 51 | + <el-table-column label="车队名称" align="center" prop="fleetName" /> | |
| 52 | + <el-table-column label="线路名称" align="center" prop="lineName" /> | |
| 53 | + <el-table-column label="备注" align="center" prop="remark" /> | |
| 54 | + <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right" width="160"> | |
| 55 | + <template #default="scope"> | |
| 56 | + <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" | |
| 57 | + v-hasPermi="['template:template:edit']">修改</el-button> | |
| 58 | + <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" | |
| 59 | + v-hasPermi="['template:template:remove']">删除</el-button> | |
| 60 | + </template> | |
| 61 | + </el-table-column> | |
| 62 | + </el-table> | |
| 63 | + | |
| 64 | + <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" | |
| 65 | + @pagination="getList" /> | |
| 66 | + | |
| 67 | + <!-- 添加或修改车队与线路对应模板对话框 --> | |
| 68 | + <el-dialog :title="title" v-model="open" width="500px" append-to-body> | |
| 69 | + <el-form ref="templateRef" :model="form" :rules="rules" label-width="80px"> | |
| 70 | + <el-form-item label="车队名称" prop="fleetName"> | |
| 71 | + <el-input v-model="form.fleetName" placeholder="请输入车队名称" /> | |
| 72 | + </el-form-item> | |
| 73 | + <el-form-item label="线路名称" prop="lineName"> | |
| 74 | + <el-input v-model="form.lineName" placeholder="请输入线路名称" /> | |
| 75 | + </el-form-item> | |
| 76 | + <el-form-item label="备注" prop="remark"> | |
| 77 | + <el-input v-model="form.remark" placeholder="请输入备注" /> | |
| 78 | + </el-form-item> | |
| 79 | + </el-form> | |
| 80 | + <template #footer> | |
| 81 | + <div class="dialog-footer"> | |
| 82 | + <el-button type="primary" @click="submitForm">确 定</el-button> | |
| 83 | + <el-button @click="cancel">取 消</el-button> | |
| 84 | + </div> | |
| 85 | + </template> | |
| 86 | + </el-dialog> | |
| 87 | + <!-- 添加或修改车队与线路对应模板对话框 --> | |
| 88 | + <el-dialog :title="title" v-model="isShowTipOpen" width="800px" append-to-body> | |
| 89 | + <file-upload :callBackUpload="callBackUpload" :limit="1" :isShowTip="isShowTip" | |
| 90 | + prefix="/big/view/importExcel"></file-upload> | |
| 91 | + </el-dialog> | |
| 92 | + </div> | |
| 93 | +</template> | |
| 94 | + | |
| 95 | +<script setup name="Template"> | |
| 96 | +import { addTemplate, delTemplate, getTemplate, listTemplate, updateTemplate } from "@/api/template/template"; | |
| 97 | +import { ElNotification } from 'element-plus'; | |
| 98 | +import moment from 'moment'; | |
| 99 | +import { ref } from "vue"; | |
| 100 | +const { proxy } = getCurrentInstance(); | |
| 101 | + | |
| 102 | +const templateList = ref([]); | |
| 103 | +const open = ref(false); | |
| 104 | +const loading = ref(true); | |
| 105 | +const showSearch = ref(true); | |
| 106 | +const ids = ref([]); | |
| 107 | +const single = ref(true); | |
| 108 | +const multiple = ref(true); | |
| 109 | +const total = ref(0); | |
| 110 | +const title = ref(""); | |
| 111 | +const isShowTip = ref(false); | |
| 112 | +const isShowTipOpen = ref(false) | |
| 113 | +const data = reactive({ | |
| 114 | + form: {}, | |
| 115 | + queryParams: { | |
| 116 | + pageNum: 1, | |
| 117 | + pageSize: 10, | |
| 118 | + fleetName: null, | |
| 119 | + lineName: null, | |
| 120 | + }, | |
| 121 | + rules: { | |
| 122 | + } | |
| 123 | +}); | |
| 124 | + | |
| 125 | +const { queryParams, form, rules } = toRefs(data); | |
| 126 | + | |
| 127 | +/** 查询车队与线路对应模板列表 */ | |
| 128 | +function getList() { | |
| 129 | + loading.value = true; | |
| 130 | + listTemplate(queryParams.value).then(response => { | |
| 131 | + templateList.value = response.rows; | |
| 132 | + total.value = response.total; | |
| 133 | + loading.value = false; | |
| 134 | + }); | |
| 135 | +} | |
| 136 | + | |
| 137 | +// 取消按钮 | |
| 138 | +function cancel() { | |
| 139 | + open.value = false; | |
| 140 | + reset(); | |
| 141 | +} | |
| 142 | + | |
| 143 | +function handleImport() { | |
| 144 | + isShowTip.value = true; | |
| 145 | + isShowTipOpen.value = true; | |
| 146 | +} | |
| 147 | + | |
| 148 | +function callBackUpload() { | |
| 149 | + console.log("上传完成"); | |
| 150 | + isShowTip.value = false; | |
| 151 | + isShowTipOpen.value = false; | |
| 152 | + getList(); | |
| 153 | + ElNotification({ | |
| 154 | + title: '提示', | |
| 155 | + message: '上传完成', | |
| 156 | + duration: 0, | |
| 157 | + }) | |
| 158 | + isShowTipOpen.value = false; | |
| 159 | + isShowTip.value = false; | |
| 160 | + | |
| 161 | +} | |
| 162 | + | |
| 163 | +// 表单重置 | |
| 164 | +function reset() { | |
| 165 | + form.value = { | |
| 166 | + id: null, | |
| 167 | + fleetName: null, | |
| 168 | + lineName: null, | |
| 169 | + createTime: null, | |
| 170 | + updateTime: null, | |
| 171 | + createBy: null, | |
| 172 | + updateBy: null, | |
| 173 | + remark: null | |
| 174 | + }; | |
| 175 | + proxy.resetForm("templateRef"); | |
| 176 | +} | |
| 177 | + | |
| 178 | +/** 搜索按钮操作 */ | |
| 179 | +function handleQuery() { | |
| 180 | + queryParams.value.pageNum = 1; | |
| 181 | + getList(); | |
| 182 | +} | |
| 183 | + | |
| 184 | +/** 重置按钮操作 */ | |
| 185 | +function resetQuery() { | |
| 186 | + proxy.resetForm("queryRef"); | |
| 187 | + handleQuery(); | |
| 188 | +} | |
| 189 | + | |
| 190 | +// 多选框选中数据 | |
| 191 | +function handleSelectionChange(selection) { | |
| 192 | + ids.value = selection.map(item => item.id); | |
| 193 | + single.value = selection.length != 1; | |
| 194 | + multiple.value = !selection.length; | |
| 195 | +} | |
| 196 | + | |
| 197 | +/** 新增按钮操作 */ | |
| 198 | +function handleAdd() { | |
| 199 | + reset(); | |
| 200 | + open.value = true; | |
| 201 | + title.value = "添加车队与线路对应模板"; | |
| 202 | +} | |
| 203 | + | |
| 204 | +/** 修改按钮操作 */ | |
| 205 | +function handleUpdate(row) { | |
| 206 | + reset(); | |
| 207 | + const _id = row.id || ids.value | |
| 208 | + getTemplate(_id).then(response => { | |
| 209 | + form.value = response.data; | |
| 210 | + open.value = true; | |
| 211 | + title.value = "修改车队与线路对应模板"; | |
| 212 | + }); | |
| 213 | +} | |
| 214 | + | |
| 215 | +/** 提交按钮 */ | |
| 216 | +function submitForm() { | |
| 217 | + proxy.$refs["templateRef"].validate(valid => { | |
| 218 | + if (valid) { | |
| 219 | + if (form.value.id != null) { | |
| 220 | + updateTemplate(form.value).then(response => { | |
| 221 | + proxy.$modal.msgSuccess("修改成功"); | |
| 222 | + open.value = false; | |
| 223 | + getList(); | |
| 224 | + }); | |
| 225 | + } else { | |
| 226 | + addTemplate(form.value).then(response => { | |
| 227 | + proxy.$modal.msgSuccess("新增成功"); | |
| 228 | + open.value = false; | |
| 229 | + getList(); | |
| 230 | + }); | |
| 231 | + } | |
| 232 | + } | |
| 233 | + }); | |
| 234 | +} | |
| 235 | + | |
| 236 | +/** 删除按钮操作 */ | |
| 237 | +function handleDelete(row) { | |
| 238 | + const _ids = row.id || ids.value; | |
| 239 | + proxy.$modal.confirm('是否确认删除车队与线路对应模板编号为"' + _ids + '"的数据项?').then(function () { | |
| 240 | + return delTemplate(_ids); | |
| 241 | + }).then(() => { | |
| 242 | + getList(); | |
| 243 | + proxy.$modal.msgSuccess("删除成功"); | |
| 244 | + }).catch(() => { }); | |
| 245 | +} | |
| 246 | + | |
| 247 | +/** 导出按钮操作 */ | |
| 248 | +function handleExport() { | |
| 249 | + let namePre = moment().format("YYYY-MM") | |
| 250 | + proxy.download('template/template/export', { | |
| 251 | + ...queryParams.value | |
| 252 | + }, `${namePre}车队与线路匹配表.xlsx`) | |
| 253 | +} | |
| 254 | + | |
| 255 | +/** 下载模板 */ | |
| 256 | +function handleDownloadTemplate() { | |
| 257 | + let namePre = moment().format("YYYY-MM") | |
| 258 | + proxy.download('big/view/exportExcel', { | |
| 259 | + ...queryParams.value | |
| 260 | + }, `${namePre}车队与线路匹配表全量导入模板.xlsx`) | |
| 261 | + | |
| 262 | +} | |
| 263 | +getList(); | |
| 264 | +</script> | ... | ... |