From 9057e04efad1b7d61c77a72e5c37a504d0aee935 Mon Sep 17 00:00:00 2001 From: doum <doum> Date: 星期五, 26 九月 2025 09:24:03 +0800 Subject: [PATCH] H5静态化 --- admin/src/components/common/ImportWindow.vue | 202 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 202 insertions(+), 0 deletions(-) diff --git a/admin/src/components/common/ImportWindow.vue b/admin/src/components/common/ImportWindow.vue new file mode 100644 index 0000000..ed8e4bc --- /dev/null +++ b/admin/src/components/common/ImportWindow.vue @@ -0,0 +1,202 @@ +<template> + <el-dialog + width="500px" + :title="title" + :visible.sync="visible" + append-to-body + custom-class="eva-dialog import-window" + :close-on-click-modal="false" + :close-on-press-escape="false" + :show-close="false" + > + <el-upload + drag + :show-file-list="false" + action="none" + accept=".xlsx" + :before-upload="handleBeforeUpload" + > + <template v-if="form.file == null"> + <i class="el-icon-upload"></i> + <div class="el-upload__text">灏嗘枃浠舵嫋鍒版澶勶紝鎴�<em>鐐瑰嚮涓婁紶</em></div> + </template> + <template v-else> + <i class="el-icon-files"></i> + <div class="el-upload__text">{{form.file.name}}<em></em></div> + </template> + </el-upload> + <div slot="footer" class="import-window__footer"> + <div class="sync-exists"> + <el-checkbox v-model="form.sync"/><span>鍚屾宸插瓨鍦ㄧ殑鏁版嵁</span> + </div> + <div class="opera"> + <el-button type="text" icon="el-icon-download" @click="downloadTemplate">涓嬭浇妯$増</el-button> + <el-button @click="cancel">{{cancelText}}</el-button> + <el-button type="primary" @click="confirm" :loading="isWorking">{{confirmText}}</el-button> + </div> + </div> + </el-dialog> +</template> + +<script> +import request from '@/utils/request' +import { downloadLocalFile } from '@/api/system/common' +export default { + name: 'ImportWindow', + props: { + // 瀵煎叆鎺ュ彛鍦板潃 + action: { + required: true + }, + // 纭鎸夐挳鏂囨 + confirmText: { + type: String, + default: '瀵煎叆' + }, + // 鍙栨秷鎸夐挳鏂囨 + cancelText: { + type: String, + default: '鍙栨秷' + }, + // 妯$増鍦板潃 + templatePath: { + required: true + }, + // 涓嬭浇鍚庣殑妯$増鏂囦欢鍚嶇О + templateName: { + required: true + } + }, + data () { + return { + visible: false, + isWorking: false, + title: '瀵煎叆鏁版嵁', + form: { + sync: false, + file: false + } + } + }, + methods: { + /** + * 鎵撳紑绐楀彛 + * + * @param title 绐楀彛鏍囬 + */ + open (title) { + this.visible = true + this.title = title + this.form.sync = false + this.form.file = null + }, + /** + * 纭畾瀵煎叆 + */ + confirm () { + if (this.form.file == null) { + this.$tip.warning('璇烽�夋嫨鏂囦欢') + return + } + this.isWorking = true + const param = new FormData() + param.set('file', this.form.file) + param.set('sync', this.form.sync) + request.post(this.action, param, { + headers: { + 'Content-Type': 'multipart/form-data;charset=UTF-8' + } + }) + .then(data => { + this.$tip.success('瀵煎叆鎴愬姛锛屽叡瀵煎叆' + data + '鏉¤褰�') + this.visible = false + this.$emit('success') + }) + .catch(e => { + this.$tip.apiFailed(e) + }) + .finally(() => { + this.isWorking = false + }) + }, + /** + * 鍙栨秷 + */ + cancel () { + this.visible = false + }, + /** + * 涓嬭浇妯$増 + */ + downloadTemplate () { + downloadLocalFile({ + path: this.templatePath, + name: this.templateName + }) + .then(data => { + this.download(data) + }) + .catch(e => { + this.$tip.apiFailed(e) + }) + }, + /** + * 鏂囦欢涓婁紶鍓嶅瓨鍌ㄤ笂浼犵殑鏂囦欢 + * + * @param file 闇�瀵煎叆鐨勬枃浠� + */ + handleBeforeUpload (file) { + this.form.file = file + return false + } + } +} +</script> + +<style lang="scss"> +@import "../../assets/style/variables"; +.import-window { + .el-upload { + width: 100%; + .el-upload-dragger { + width: 100%; + .el-icon-upload, .el-icon-files { + font-size: 67px; + color: #C0C4CC; + margin: 40px 0 16px; + line-height: 50px; + } + } + } + .import-window__footer { + display: flex; + .sync-exists { + width: 200px; + flex-shrink: 0; + text-align: left; + font-size: 13px; + display: flex; + align-items: center; + .el-checkbox { + margin-right: 10px; + } + & > * { + vertical-align: middle; + } + } + .opera { + flex-grow: 1; + a { + font-size: 12px; + margin-right: 10px; + text-decoration: none; + .el-icon-download { + font-size: 15px; + position: relative; + top: 2px; + } + } + } + } +} +</style> -- Gitblit v1.9.3