index.vue 8.4 KB

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