index.vue 9.9 KB

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