index.vue 9.6 KB

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