From 5863205a338ea13ecd45ee796119a1837ae2ecdb Mon Sep 17 00:00:00 2001
From: dshclm <3321914460@qq.com>
Date: Thu, 11 Jul 2024 09:52:11 +0800
Subject: [PATCH] =?UTF-8?q?=E8=AF=95=E9=A2=98=E5=AF=BC=E5=85=A5=E3=80=81?=
 =?UTF-8?q?=E6=A8=A1=E6=9D=BF=E4=B8=8B=E8=BD=BD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../web/controller/exam/QuController.java     |   6 +
 .../templates/system/elExam/qu/qu.html        | 144 +++++-------------
 .../templates/system/elExam/qu/toImport.html  | 135 ++++++++++++++++
 3 files changed, 183 insertions(+), 102 deletions(-)
 create mode 100644 ruoyi-admin/src/main/resources/templates/system/elExam/qu/toImport.html

diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/exam/QuController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/exam/QuController.java
index e88402f..689c256 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/exam/QuController.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/exam/QuController.java
@@ -182,6 +182,12 @@ public class QuController extends BaseController {
     }
 
 
+    @RequiresPermissions("system:qu:import")
+    @GetMapping("/toImport")
+    public String toImport() {
+        return prefix + "/toImport";
+    }
+
     @ApiOperation("导入Excel")
     @RequiresPermissions("system:qu:import")
     @ResponseBody
diff --git a/ruoyi-admin/src/main/resources/templates/system/elExam/qu/qu.html b/ruoyi-admin/src/main/resources/templates/system/elExam/qu/qu.html
index 95d683e..07a526e 100644
--- a/ruoyi-admin/src/main/resources/templates/system/elExam/qu/qu.html
+++ b/ruoyi-admin/src/main/resources/templates/system/elExam/qu/qu.html
@@ -39,7 +39,7 @@
 		        <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:qu:remove">
 		            <i class="fa fa-remove"></i> 删除
 		        </a>
-				<a class="btn btn-info" @click="toImport()" shiro:hasPermission="system:qu:import">
+				<a class="btn btn-info" onclick="toImport()" shiro:hasPermission="system:qu:import">
 					<i class="fa fa-upload"></i> 导入
 				</a>
 	        </div>
@@ -47,17 +47,6 @@
 	            <table id="bootstrap-table"></table>
 	        </div>
     	</div>
-		<el-dialog
-			:visible.sync="importVisible"
-			title="导入试题"
-			width="30%"
-		>
-			<el-row>
-				<el-button type="primary" @click="chooseFile()">上传导入</el-button>
-				<el-button type="warning" @click="downloadTemplate()">下载导入模板</el-button>
-				<input ref="upFile" class="file" name="file" type="file" style="display: none" @change="doImport">
-			</el-row>
-		</el-dialog>
     </div>
     <th:block th:include="include :: footer" />
 	<th:block th:include="include :: element-js" />
@@ -110,96 +99,47 @@
             };
             $.table.init(options);
         });
-		// function  toImport(){
-		// 	$.modal.open("试题导入", prefix + "/toImport",'500','300');
-		// }
-		console.log(document.getElementsByClassName('fixed-sidebar'))
-		// 请求实例
-		const instance = axios.create({
-			baseURL: ctx,
-			timeout: 60000
-		})
-		var app = new Vue({
-			el: '#app',
-			data: {
-				importVisible:false
-			},
-			mounted(){
-
-			},
-			methods: {
-				toImport(){
-					this.importVisible = true
-				},
-				// 只是为了美化一下导入按钮
-				chooseFile: function() {
-					this.$refs.upFile.dispatchEvent(new MouseEvent('click'))
-				},
-				downloadTemplate() {
-					// 创建一个隐藏的<a>标签
-					var link = document.createElement('a');
-					link.style.display = 'none';
-					document.body.appendChild(link);
-					link.setAttribute('href', '/file/试题导入模板.xlsx');
-					link.setAttribute('download', '试题导入模板.xlsx');
-					link.click();
-					document.body.removeChild(link);
-				},
-				upload(url, file, data) {
-					const formData = new FormData()
-					formData.append('file', file)
-
-					// 附加数据
-					if (data) {
-						Object.keys(data).forEach((key) => {
-							formData.append(key, data[key])
-						})
-					}
-					const loading = this.$loading({
-						lock: true,
-						text: 'Loading',
-						spinner: 'el-icon-loading',
-						background: 'rgba(0, 0, 0, 0.7)'
-					});
-					return new Promise((resolve, reject) => {
-						instance.request({
-							url: url,
-							method: 'post',
-							data: formData,
-							timeout: 1200000
-						}).then(response => {
-							loading.close();
-							console.log(response)
-							resolve(response)
-						}).catch(err => {
-							reject(err)
-						})
-					})
-				},
-				importExcel(file) {
-					return this.upload('system/qu/import', file)
-				},
-				doImport(e) {
-					const file = e.target.files[0]
-					let that = this
-					this.importExcel(file).then((res)=>{
-						console.log(res)
-						if (res.data.code !== 0) {
-							that.$alert(res.data.msg, '导入信息', {
-								dangerouslyUseHTMLString: true
-							})
-						} else {
-							that.$message({
-								message: '数据导入成功!',
-								type: 'success'
-							})
-							this.importVisible = false
-							$.table.refresh()
-						}
-					})
-				},
-			},
-		});
+		function  toImport(){
+			open("试题导入", prefix + "/toImport",'500','300');
+		}
+		// 弹出层指定宽度
+		function open(title, url, width, height, callback) {
+			// 如果是移动端,就使用自适应大小弹窗
+			if ($.common.isMobile()) {
+				width = 'auto';
+				height = 'auto';
+			}
+			if ($.common.isEmpty(title)) {
+				title = false;
+			}
+			if ($.common.isEmpty(url)) {
+				url = "/404.html";
+			}
+			if ($.common.isEmpty(width)) {
+				width = 800;
+			}
+			if ($.common.isEmpty(height)) {
+				height = ($(window).height() - 50);
+			}
+			if ($.common.isEmpty(callback)) {
+				callback = function(index, layero) {
+					var iframeWin = layero.find('iframe')[0];
+					iframeWin.contentWindow.submitHandler(index, layero);
+				}
+			}
+			top.layer.open({
+				type: 2,
+				area: [width + 'px', height + 'px'],
+				fix: false,
+				//不固定
+				maxmin: true,
+				shade: 0.3,
+				title: title,
+				content: url,
+				// 弹层外区域关闭
+				shadeClose: true,
+			});
+		}
     </script>
 </body>
 </html>
diff --git a/ruoyi-admin/src/main/resources/templates/system/elExam/qu/toImport.html b/ruoyi-admin/src/main/resources/templates/system/elExam/qu/toImport.html
new file mode 100644
index 0000000..0b8a50b
--- /dev/null
+++ b/ruoyi-admin/src/main/resources/templates/system/elExam/qu/toImport.html
@@ -0,0 +1,135 @@
+<!DOCTYPE html>
+<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
+<head>
+    <th:block th:include="include :: header('试题导入')" />
+    <th:block th:include="include :: element-css" />
+</head>
+<body class="white-bg" style="text-align: center;">
+<div class="wrapper wrapper-content animated fadeInRight ibox-content" id="app">
+    <el-row>
+        <el-button type="primary" @click="chooseFile()">上传导入</el-button>
+        <el-button type="warning" @click="downloadTemplate()">下载导入模板</el-button>
+        <input ref="upFile" class="file" name="file" type="file" style="display: none" @change="doImport">
+    </el-row>
+</div>
+<th:block th:include="include :: footer" />
+<th:block th:include="include :: element-js" />
+<script th:inline="javascript">
+    var prefix = ctx + "system/qu";
+    // 请求实例
+    const instance = axios.create({
+        baseURL: ctx,
+        timeout: 60000
+    })
+    var app = new Vue({
+        el: '#app',
+        data: {
+            importVisible:false
+        },
+        mounted(){
+
+        },
+        methods: {
+            toImport(){
+                this.importVisible = true
+            },
+            // 只是为了美化一下导入按钮
+            chooseFile: function() {
+                this.$refs.upFile.dispatchEvent(new MouseEvent('click'))
+            },
+            downloadTemplate() {
+                // 创建一个隐藏的<a>标签
+                var link = document.createElement('a');
+                link.style.display = 'none';
+                document.body.appendChild(link);
+                link.setAttribute('href', '/file/试题导入模板.xlsx');
+                link.setAttribute('download', '试题导入模板.xlsx');
+                link.click();
+                document.body.removeChild(link);
+            },
+            upload(url, file, data) {
+                const formData = new FormData()
+                formData.append('file', file)
+
+                // 附加数据
+                if (data) {
+                    Object.keys(data).forEach((key) => {
+                        formData.append(key, data[key])
+                    })
+                }
+                const loading = this.$loading({
+                    lock: true,
+                    text: 'Loading',
+                    spinner: 'el-icon-loading',
+                    background: 'rgba(0, 0, 0, 0.7)'
+                });
+                return new Promise((resolve, reject) => {
+                    instance.request({
+                        url: url,
+                        method: 'post',
+                        data: formData,
+                        timeout: 1200000
+                    }).then(response => {
+                        loading.close();
+                        console.log(response)
+                        resolve(response)
+                    }).catch(err => {
+                        reject(err)
+                    })
+                })
+            },
+            importExcel(file) {
+                return this.upload('system/qu/import', file)
+            },
+            doImport(e) {
+                const file = e.target.files[0]
+                let that = this
+                this.importExcel(file).then((res)=>{
+                    console.log(res)
+                    if (res.data.code !== 0) {
+                        that.$alert(res.data.msg, '导入信息', {
+                            dangerouslyUseHTMLString: true
+                        })
+                    } else {
+                        that.$message({
+                            message: '数据导入成功!',
+                            type: 'success'
+                        })
+                        this.importVisible = false
+                        this.successCallback(res)
+                    }
+                })
+            },
+            // 成功回调执行事件(父窗体静默更新)
+            successCallback: function(result) {
+                if (result.data.code == web_status.SUCCESS) {
+                    var parent = activeWindow();
+                    if ($.common.isEmpty(parent.table)) {
+                        $.modal.msgSuccessReload(result.data.msg);
+                    } else if (parent.table.options.type == table_type.bootstrapTable) {
+                        $.modal.close();
+                        parent.$.modal.msgSuccess(result.data.msg);
+                        parent.$.table.refresh();
+                    } else if (parent.table.options.type == table_type.bootstrapTreeTable) {
+                        $.modal.close();
+                        parent.$.modal.msgSuccess(result.data.msg);
+                        parent.$.treeTable.refresh();
+                    }
+                } else if (result.data.code == web_status.WARNING) {
+                    $.modal.alertWarning(result.data.msg)
+                }  else {
+                    $.modal.alertError(result.data.msg);
+                }
+                $.modal.closeLoading();
+                $.modal.enable();
+            },
+        },
+    });
+    function submitHandler() {
+        if ($.validate.form()) {
+            $.operate.save(prefix + "/edit", $('#form-train-edit').serialize());
+        }
+    }
+</script>
+</body>
+</html>