From b508e6f20238caf6f000a2ac617bb6a4ca37d56b Mon Sep 17 00:00:00 2001 From: RuoYi <yzz_ivy@163.com> Date: 星期三, 11 十二月 2019 18:12:00 +0800 Subject: [PATCH] 新增用户导入 --- ruoyi-ui/src/views/system/user/index.vue | 93 ++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 88 insertions(+), 5 deletions(-) diff --git a/ruoyi-ui/src/views/system/user/index.vue b/ruoyi-ui/src/views/system/user/index.vue index 00c3645..aae3e82 100644 --- a/ruoyi-ui/src/views/system/user/index.vue +++ b/ruoyi-ui/src/views/system/user/index.vue @@ -114,6 +114,15 @@ </el-col> <el-col :span="1.5"> <el-button + type="info" + icon="el-icon-upload2" + size="mini" + @click="handleImport" + v-hasPermi="['system:user:import']" + >瀵煎叆</el-button> + </el-col> + <el-col :span="1.5"> + <el-button type="warning" icon="el-icon-download" size="mini" @@ -284,11 +293,43 @@ <el-button @click="cancel">鍙� 娑�</el-button> </div> </el-dialog> + + <!-- 鐢ㄦ埛瀵煎叆瀵硅瘽妗� --> + <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px"> + <el-upload + ref="upload" + :limit="1" + accept=".xlsx, .xls" + :headers="upload.headers" + :action="upload.url + '?updateSupport=' + upload.updateSupport" + :disabled="upload.isUploading" + :on-progress="handleFileUploadProgress" + :on-success="handleFileSuccess" + :auto-upload="false" + drag + > + <i class="el-icon-upload"></i> + <div class="el-upload__text"> + 灏嗘枃浠舵嫋鍒版澶勶紝鎴� + <em>鐐瑰嚮涓婁紶</em> + </div> + <div class="el-upload__tip" slot="tip"> + <el-checkbox v-model="upload.updateSupport" />鏄惁鏇存柊宸茬粡瀛樺湪鐨勭敤鎴锋暟鎹� + <el-link type="info" style="font-size:12px" @click="importTemplate">涓嬭浇妯℃澘</el-link> + </div> + <div class="el-upload__tip" style="color:red" slot="tip">鎻愮ず锛氫粎鍏佽瀵煎叆鈥渪ls鈥濇垨鈥渪lsx鈥濇牸寮忔枃浠讹紒</div> + </el-upload> + <div slot="footer" class="dialog-footer"> + <el-button type="primary" @click="submitFileForm">纭� 瀹�</el-button> + <el-button @click="upload.open = false">鍙� 娑�</el-button> + </div> + </el-dialog> </div> </template> <script> -import { listUser, getUser, delUser, addUser, updateUser, exportUser, resetUserPwd, changeUserStatus } from "@/api/system/user"; +import { listUser, getUser, delUser, addUser, updateUser, exportUser, resetUserPwd, changeUserStatus, importTemplate } from "@/api/system/user"; +import { getToken } from "@/utils/auth"; import { treeselect } from "@/api/system/dept"; import Treeselect from "@riophae/vue-treeselect"; import "@riophae/vue-treeselect/dist/vue-treeselect.css"; @@ -335,6 +376,21 @@ defaultProps: { children: "children", label: "label" + }, + // 鐢ㄦ埛瀵煎叆鍙傛暟 + upload: { + // 鏄惁鏄剧ず寮瑰嚭灞傦紙鐢ㄦ埛瀵煎叆锛� + open: false, + // 寮瑰嚭灞傛爣棰橈紙鐢ㄦ埛瀵煎叆锛� + title: "", + // 鏄惁绂佺敤涓婁紶 + isUploading: false, + // 鏄惁鏇存柊宸茬粡瀛樺湪鐨勭敤鎴锋暟鎹� + updateSupport: 0, + // 璁剧疆涓婁紶鐨勮姹傚ご閮� + headers: { Authorization: "Bearer " + getToken() }, + // 涓婁紶鐨勫湴鍧� + url: process.env.VUE_APP_BASE_API + "/system/user/importData" }, // 鏌ヨ鍙傛暟 queryParams: { @@ -473,9 +529,9 @@ }, // 澶氶�夋閫変腑鏁版嵁 handleSelectionChange(selection) { - this.ids = selection.map(item => item.userId) - this.single = selection.length!=1 - this.multiple = !selection.length + this.ids = selection.map(item => item.userId); + this.single = selection.length != 1; + this.multiple = !selection.length; }, /** 鏂板鎸夐挳鎿嶄綔 */ handleAdd() { @@ -493,7 +549,7 @@ handleUpdate(row) { this.reset(); this.getTreeselect(); - const userId = row.userId || this.ids + const userId = row.userId || this.ids; getUser(userId).then(response => { this.form = response.data; this.postOptions = response.posts; @@ -574,6 +630,33 @@ }).then(response => { this.download(response.msg); }).catch(function() {}); + }, + /** 瀵煎叆鎸夐挳鎿嶄綔 */ + handleImport() { + this.upload.title = "鐢ㄦ埛瀵煎叆"; + this.upload.open = true; + }, + /** 涓嬭浇妯℃澘鎿嶄綔 */ + importTemplate() { + importTemplate().then(response => { + this.download(response.msg); + }); + }, + // 鏂囦欢涓婁紶涓鐞� + handleFileUploadProgress(event, file, fileList) { + this.upload.isUploading = true; + }, + // 鏂囦欢涓婁紶鎴愬姛澶勭悊 + handleFileSuccess(response, file, fileList) { + this.upload.open = false; + this.upload.isUploading = false; + this.$refs.upload.clearFiles(); + this.$alert(response.msg, "瀵煎叆缁撴灉", { dangerouslyUseHTMLString: true }); + this.getList(); + }, + // 鎻愪氦涓婁紶鏂囦欢 + submitFileForm() { + this.$refs.upload.submit(); } } }; -- Gitblit v1.9.3