index.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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="title">
  5. <el-input v-model="queryParams.title" placeholder="请输入公告标题" clearable @keyup.enter.native="handleQuery"/>
  6. </el-form-item>
  7. <el-form-item label="公告状态" prop="status">
  8. <el-select v-model="queryParams.status" placeholder="公告状态" clearable>
  9. <el-option v-for="dict in statusDictDatas" :key="parseInt(dict.value)" :label="dict.label" :value="parseInt(dict.value)"/>
  10. </el-select>
  11. </el-form-item>
  12. <el-form-item>
  13. <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
  14. <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
  15. </el-form-item>
  16. </el-form>
  17. <el-row :gutter="10" class="mb8">
  18. <el-col :span="1.5">
  19. <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
  20. v-hasPermi="['system:notice:create']"s>新增</el-button>
  21. </el-col>
  22. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  23. </el-row>
  24. <el-table v-loading="loading" :data="noticeList">
  25. <el-table-column label="序号" align="center" prop="id" width="100" />
  26. <el-table-column label="公告标题" align="center" prop="title" :show-overflow-tooltip="true"/>
  27. <el-table-column label="公告类型" align="center" prop="type" width="100">
  28. <template v-slot="scope">
  29. <dict-tag :type="DICT_TYPE.SYSTEM_NOTICE_TYPE" :value="scope.row.type"/>
  30. </template>
  31. </el-table-column>
  32. <el-table-column label="状态" align="center" prop="status" width="100">
  33. <template v-slot="scope">
  34. <dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status"/>
  35. </template>
  36. </el-table-column>
  37. <el-table-column label="创建者" align="center" prop="createBy" width="100" />
  38. <el-table-column label="创建时间" align="center" prop="createTime" width="100">
  39. <template v-slot="scope">
  40. <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
  41. </template>
  42. </el-table-column>
  43. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  44. <template v-slot="scope">
  45. <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
  46. v-hasPermi="['system:notice:update']">修改</el-button>
  47. <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
  48. v-hasPermi="['system:notice:delete']">删除</el-button>
  49. </template>
  50. </el-table-column>
  51. </el-table>
  52. <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
  53. @pagination="getList"/>
  54. <!-- 添加或修改公告对话框 -->
  55. <el-dialog :title="title" :visible.sync="open" width="780px" append-to-body>
  56. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  57. <el-row>
  58. <el-col :span="12">
  59. <el-form-item label="公告标题" prop="title">
  60. <el-input v-model="form.title" placeholder="请输入公告标题" />
  61. </el-form-item>
  62. </el-col>
  63. <el-col :span="12">
  64. <el-form-item label="公告类型" prop="type">
  65. <el-select v-model="form.type" placeholder="请选择">
  66. <el-option
  67. v-for="dict in noticeTypeDictDatas"
  68. :key="parseInt(dict.value)"
  69. :label="dict.label"
  70. :value="parseInt(dict.value)"
  71. />
  72. </el-select>
  73. </el-form-item>
  74. </el-col>
  75. <el-col :span="24">
  76. <el-form-item label="状态">
  77. <el-radio-group v-model="form.status">
  78. <el-radio
  79. v-for="dict in statusDictDatas"
  80. :key="parseInt(dict.value)"
  81. :label="parseInt(dict.value)"
  82. >{{dict.label}}</el-radio>
  83. </el-radio-group>
  84. </el-form-item>
  85. </el-col>
  86. <el-col :span="24">
  87. <el-form-item label="内容">
  88. <editor v-model="form.content" :min-height="192"/>
  89. </el-form-item>
  90. </el-col>
  91. </el-row>
  92. </el-form>
  93. <div slot="footer" class="dialog-footer">
  94. <el-button type="primary" @click="submitForm">确 定</el-button>
  95. <el-button @click="cancel">取 消</el-button>
  96. </div>
  97. </el-dialog>
  98. </div>
  99. </template>
  100. <script>
  101. import { listNotice, getNotice, delNotice, addNotice, updateNotice } from "@/api/system/notice";
  102. import Editor from '@/components/Editor';
  103. import {CommonStatusEnum} from '@/utils/constants'
  104. import { getDictDatas, DICT_TYPE } from '@/utils/dict'
  105. export default {
  106. name: "SystemNotice",
  107. components: {
  108. Editor
  109. },
  110. data() {
  111. return {
  112. // 遮罩层
  113. loading: true,
  114. // 显示搜索条件
  115. showSearch: true,
  116. // 总条数
  117. total: 0,
  118. // 公告表格数据
  119. noticeList: [],
  120. // 弹出层标题
  121. title: "",
  122. // 是否显示弹出层
  123. open: false,
  124. // 查询参数
  125. queryParams: {
  126. pageNo: 1,
  127. pageSize: 10,
  128. title: undefined,
  129. status: undefined
  130. },
  131. // 表单参数
  132. form: {},
  133. // 表单校验
  134. rules: {
  135. title: [
  136. { required: true, message: "公告标题不能为空", trigger: "blur" }
  137. ],
  138. type: [
  139. { required: true, message: "公告类型不能为空", trigger: "change" }
  140. ]
  141. },
  142. // 枚举
  143. CommonStatusEnum: CommonStatusEnum,
  144. // 数据字典
  145. noticeTypeDictDatas: getDictDatas(DICT_TYPE.SYSTEM_NOTICE_TYPE),
  146. statusDictDatas: getDictDatas(DICT_TYPE.COMMON_STATUS)
  147. };
  148. },
  149. created() {
  150. this.getList();
  151. },
  152. methods: {
  153. /** 查询公告列表 */
  154. getList() {
  155. this.loading = true;
  156. listNotice(this.queryParams).then(response => {
  157. this.noticeList = response.data.list;
  158. this.total = response.data.total;
  159. this.loading = false;
  160. });
  161. },
  162. // 取消按钮
  163. cancel() {
  164. this.open = false;
  165. this.reset();
  166. },
  167. // 表单重置
  168. reset() {
  169. this.form = {
  170. id: undefined,
  171. title: undefined,
  172. type: undefined,
  173. content: undefined,
  174. status: CommonStatusEnum.ENABLE
  175. };
  176. this.resetForm("form");
  177. },
  178. /** 搜索按钮操作 */
  179. handleQuery() {
  180. this.queryParams.pageNo = 1;
  181. this.getList();
  182. },
  183. /** 重置按钮操作 */
  184. resetQuery() {
  185. this.resetForm("queryForm");
  186. this.handleQuery();
  187. },
  188. /** 新增按钮操作 */
  189. handleAdd() {
  190. this.reset();
  191. this.open = true;
  192. this.title = "添加公告";
  193. },
  194. /** 修改按钮操作 */
  195. handleUpdate(row) {
  196. this.reset();
  197. const id = row.id || this.ids
  198. getNotice(id).then(response => {
  199. this.form = response.data;
  200. this.open = true;
  201. this.title = "修改公告";
  202. });
  203. },
  204. /** 提交按钮 */
  205. submitForm: function() {
  206. this.$refs["form"].validate(valid => {
  207. if (valid) {
  208. if (this.form.id !== undefined) {
  209. updateNotice(this.form).then(response => {
  210. this.$modal.msgSuccess("修改成功");
  211. this.open = false;
  212. this.getList();
  213. });
  214. } else {
  215. addNotice(this.form).then(response => {
  216. this.$modal.msgSuccess("新增成功");
  217. this.open = false;
  218. this.getList();
  219. });
  220. }
  221. }
  222. });
  223. },
  224. /** 删除按钮操作 */
  225. handleDelete(row) {
  226. const ids = row.id || this.ids
  227. this.$modal.confirm('是否确认删除公告编号为"' + ids + '"的数据项?').then(function() {
  228. return delNotice(ids);
  229. }).then(() => {
  230. this.getList();
  231. this.$modal.msgSuccess("删除成功");
  232. }).catch(() => {});
  233. }
  234. }
  235. };
  236. </script>