index.vue 8.5 KB

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