index.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. <template>
  2. <div class="app-container">
  3. <el-form
  4. :model="queryParams"
  5. ref="queryForm"
  6. size="small"
  7. :inline="true"
  8. v-show="showSearch"
  9. label-width="68px"
  10. >
  11. <el-form-item label="学科名称" prop="dirName">
  12. <el-input
  13. v-model="queryParams.dirName"
  14. placeholder="请输入学科名称"
  15. clearable
  16. @keyup.enter.native="handleQuery"
  17. />
  18. </el-form-item>
  19. <el-form-item>
  20. <el-button
  21. type="primary"
  22. icon="el-icon-search"
  23. size="mini"
  24. @click="handleQuery"
  25. >搜索</el-button
  26. >
  27. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
  28. >重置</el-button
  29. >
  30. </el-form-item>
  31. </el-form>
  32. <el-row :gutter="10" class="mb8">
  33. <el-col :span="1.5">
  34. <el-button
  35. type="primary"
  36. plain
  37. icon="el-icon-plus"
  38. size="mini"
  39. @click="handleAdd"
  40. v-hasPermi="['eas:direction:add']"
  41. >新增</el-button
  42. >
  43. </el-col>
  44. <el-col :span="1.5">
  45. <el-button
  46. type="success"
  47. plain
  48. icon="el-icon-edit"
  49. size="mini"
  50. :disabled="single"
  51. @click="handleUpdate"
  52. v-hasPermi="['eas:direction:edit']"
  53. >修改</el-button
  54. >
  55. </el-col>
  56. <el-col :span="1.5">
  57. <el-button
  58. type="danger"
  59. plain
  60. icon="el-icon-delete"
  61. size="mini"
  62. :disabled="multiple"
  63. @click="handleDelete"
  64. v-hasPermi="['eas:direction:remove']"
  65. >删除</el-button
  66. >
  67. </el-col>
  68. <el-col :span="1.5">
  69. <el-button
  70. type="warning"
  71. plain
  72. icon="el-icon-download"
  73. size="mini"
  74. @click="handleExport"
  75. v-hasPermi="['eas:direction:export']"
  76. >导出</el-button
  77. >
  78. </el-col>
  79. <right-toolbar
  80. :showSearch.sync="showSearch"
  81. @queryTable="getList"
  82. ></right-toolbar>
  83. </el-row>
  84. <el-table
  85. v-loading="loading"
  86. :data="directionList"
  87. @selection-change="handleSelectionChange"
  88. >
  89. <el-table-column type="selection" width="55" align="center" />
  90. <el-table-column label="学科名称" align="center" prop="dirName" />
  91. <el-table-column label="学科介绍" align="center" prop="dirDesc" />
  92. <el-table-column label="封面" align="center" prop="dirImg" width="100">
  93. <template slot-scope="scope">
  94. <image-preview :src="scope.row.dirImg" :width="50" :height="50" />
  95. </template>
  96. </el-table-column>
  97. <el-table-column
  98. label="操作"
  99. align="center"
  100. class-name="small-padding fixed-width"
  101. >
  102. <template slot-scope="scope">
  103. <el-button
  104. size="mini"
  105. type="text"
  106. icon="el-icon-edit"
  107. @click="handleUpdate(scope.row)"
  108. v-hasPermi="['eas:direction:edit']"
  109. >修改</el-button
  110. >
  111. <el-button
  112. size="mini"
  113. type="text"
  114. icon="el-icon-delete"
  115. @click="handleDelete(scope.row)"
  116. v-hasPermi="['eas:direction:remove']"
  117. >删除</el-button
  118. >
  119. </template>
  120. </el-table-column>
  121. </el-table>
  122. <pagination
  123. v-show="total > 0"
  124. :total="total"
  125. :page.sync="queryParams.pageNum"
  126. :limit.sync="queryParams.pageSize"
  127. @pagination="getList"
  128. />
  129. <!-- 添加或修改学科对话框 -->
  130. <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
  131. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  132. <el-form-item label="学科名称" prop="dirName">
  133. <el-input v-model="form.dirName" placeholder="请输入学科名称" />
  134. </el-form-item>
  135. <el-form-item label="学科介绍">
  136. <editor v-model="form.dirDesc" :min-height="192" />
  137. </el-form-item>
  138. <el-form-item label="封面" prop="dirImg">
  139. <image-upload v-model="form.dirImg" />
  140. </el-form-item>
  141. </el-form>
  142. <div slot="footer" class="dialog-footer">
  143. <el-button type="primary" @click="submitForm">确 定</el-button>
  144. <el-button @click="cancel">取 消</el-button>
  145. </div>
  146. </el-dialog>
  147. </div>
  148. </template>
  149. <script>
  150. import {
  151. listDirection,
  152. getDirection,
  153. delDirection,
  154. addDirection,
  155. updateDirection,
  156. } from "@/api/eas/direction";
  157. export default {
  158. name: "Direction",
  159. data() {
  160. return {
  161. // 遮罩层
  162. loading: true,
  163. // 选中数组
  164. ids: [],
  165. // 非单个禁用
  166. single: true,
  167. // 非多个禁用
  168. multiple: true,
  169. // 显示搜索条件
  170. showSearch: true,
  171. // 总条数
  172. total: 0,
  173. // 学科表格数据
  174. directionList: [],
  175. // 弹出层标题
  176. title: "",
  177. // 是否显示弹出层
  178. open: false,
  179. // 查询参数
  180. queryParams: {
  181. pageNum: 1,
  182. pageSize: 10,
  183. dirName: null,
  184. dirDesc: null,
  185. dirImg: null,
  186. },
  187. // 表单参数
  188. form: {},
  189. // 表单校验
  190. rules: {},
  191. };
  192. },
  193. created() {
  194. this.getList();
  195. },
  196. methods: {
  197. /** 查询学科列表 */
  198. getList() {
  199. this.loading = true;
  200. listDirection(this.queryParams).then((response) => {
  201. this.directionList = response.rows;
  202. this.total = response.total;
  203. this.loading = false;
  204. });
  205. },
  206. // 取消按钮
  207. cancel() {
  208. this.open = false;
  209. this.reset();
  210. },
  211. // 表单重置
  212. reset() {
  213. this.form = {
  214. id: null,
  215. dirName: null,
  216. dirDesc: null,
  217. dirImg: null,
  218. };
  219. this.resetForm("form");
  220. },
  221. /** 搜索按钮操作 */
  222. handleQuery() {
  223. this.queryParams.pageNum = 1;
  224. this.getList();
  225. },
  226. /** 重置按钮操作 */
  227. resetQuery() {
  228. this.resetForm("queryForm");
  229. this.handleQuery();
  230. },
  231. // 多选框选中数据
  232. handleSelectionChange(selection) {
  233. this.ids = selection.map((item) => item.id);
  234. this.single = selection.length !== 1;
  235. this.multiple = !selection.length;
  236. },
  237. /** 新增按钮操作 */
  238. handleAdd() {
  239. this.reset();
  240. this.open = true;
  241. this.title = "添加学科";
  242. },
  243. /** 修改按钮操作 */
  244. handleUpdate(row) {
  245. this.reset();
  246. const id = row.id || this.ids;
  247. getDirection(id).then((response) => {
  248. this.form = response.data;
  249. this.open = true;
  250. this.title = "修改学科";
  251. });
  252. },
  253. /** 提交按钮 */
  254. submitForm() {
  255. this.$refs["form"].validate((valid) => {
  256. if (valid) {
  257. if (this.form.id != null) {
  258. updateDirection(this.form).then((response) => {
  259. this.$modal.msgSuccess("修改成功");
  260. this.open = false;
  261. this.getList();
  262. });
  263. } else {
  264. addDirection(this.form).then((response) => {
  265. this.$modal.msgSuccess("新增成功");
  266. this.open = false;
  267. this.getList();
  268. });
  269. }
  270. }
  271. });
  272. },
  273. /** 删除按钮操作 */
  274. handleDelete(row) {
  275. const ids = row.id || this.ids;
  276. this.$modal
  277. .confirm('是否确认删除学科编号为"' + ids + '"的数据项?')
  278. .then(function () {
  279. return delDirection(ids);
  280. })
  281. .then(() => {
  282. this.getList();
  283. this.$modal.msgSuccess("删除成功");
  284. })
  285. .catch(() => {});
  286. },
  287. /** 导出按钮操作 */
  288. handleExport() {
  289. this.download(
  290. "eas/direction/export",
  291. {
  292. ...this.queryParams,
  293. },
  294. `direction_${new Date().getTime()}.xlsx`
  295. );
  296. },
  297. },
  298. };
  299. </script>