index.vue 10 KB

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