index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  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. import Editor from '@/components/Editor';
  176. export default {
  177. name: "Notice",
  178. components: {
  179. Editor
  180. },
  181. data() {
  182. return {
  183. // 遮罩层
  184. loading: true,
  185. // 选中数组
  186. ids: [],
  187. // 非单个禁用
  188. single: true,
  189. // 非多个禁用
  190. multiple: true,
  191. // 显示搜索条件
  192. showSearch: true,
  193. // 总条数
  194. total: 0,
  195. // 公告表格数据
  196. noticeList: [],
  197. // 弹出层标题
  198. title: "",
  199. // 是否显示弹出层
  200. open: false,
  201. // 类型数据字典
  202. statusOptions: [],
  203. // 状态数据字典
  204. typeOptions: [],
  205. // 查询参数
  206. queryParams: {
  207. pageNum: 1,
  208. pageSize: 10,
  209. noticeTitle: undefined,
  210. createBy: undefined,
  211. status: undefined
  212. },
  213. // 表单参数
  214. form: {},
  215. // 表单校验
  216. rules: {
  217. noticeTitle: [
  218. { required: true, message: "公告标题不能为空", trigger: "blur" }
  219. ],
  220. noticeType: [
  221. { required: true, message: "公告类型不能为空", trigger: "change" }
  222. ]
  223. }
  224. };
  225. },
  226. created() {
  227. this.getList();
  228. this.getDicts("sys_notice_status").then(response => {
  229. this.statusOptions = response.data;
  230. });
  231. this.getDicts("sys_notice_type").then(response => {
  232. this.typeOptions = response.data;
  233. });
  234. },
  235. methods: {
  236. /** 查询公告列表 */
  237. getList() {
  238. this.loading = true;
  239. listNotice(this.queryParams).then(response => {
  240. this.noticeList = response.rows;
  241. this.total = response.total;
  242. this.loading = false;
  243. });
  244. },
  245. // 公告状态字典翻译
  246. statusFormat(row, column) {
  247. return this.selectDictLabel(this.statusOptions, row.status);
  248. },
  249. // 公告状态字典翻译
  250. typeFormat(row, column) {
  251. return this.selectDictLabel(this.typeOptions, row.noticeType);
  252. },
  253. // 取消按钮
  254. cancel() {
  255. this.open = false;
  256. this.reset();
  257. },
  258. // 表单重置
  259. reset() {
  260. this.form = {
  261. noticeId: undefined,
  262. noticeTitle: undefined,
  263. noticeType: undefined,
  264. noticeContent: undefined,
  265. status: "0"
  266. };
  267. this.resetForm("form");
  268. },
  269. /** 搜索按钮操作 */
  270. handleQuery() {
  271. this.queryParams.pageNum = 1;
  272. this.getList();
  273. },
  274. /** 重置按钮操作 */
  275. resetQuery() {
  276. this.resetForm("queryForm");
  277. this.handleQuery();
  278. },
  279. // 多选框选中数据
  280. handleSelectionChange(selection) {
  281. this.ids = selection.map(item => item.noticeId)
  282. this.single = selection.length!=1
  283. this.multiple = !selection.length
  284. },
  285. /** 新增按钮操作 */
  286. handleAdd() {
  287. this.reset();
  288. this.open = true;
  289. this.title = "添加公告";
  290. },
  291. /** 修改按钮操作 */
  292. handleUpdate(row) {
  293. this.reset();
  294. const noticeId = row.noticeId || this.ids
  295. getNotice(noticeId).then(response => {
  296. this.form = response.data;
  297. this.open = true;
  298. this.title = "修改公告";
  299. });
  300. },
  301. /** 提交按钮 */
  302. submitForm: function() {
  303. this.$refs["form"].validate(valid => {
  304. if (valid) {
  305. if (this.form.noticeId != undefined) {
  306. updateNotice(this.form).then(response => {
  307. this.msgSuccess("修改成功");
  308. this.open = false;
  309. this.getList();
  310. });
  311. } else {
  312. addNotice(this.form).then(response => {
  313. this.msgSuccess("新增成功");
  314. this.open = false;
  315. this.getList();
  316. });
  317. }
  318. }
  319. });
  320. },
  321. /** 删除按钮操作 */
  322. handleDelete(row) {
  323. const noticeIds = row.noticeId || this.ids
  324. this.$confirm('是否确认删除公告编号为"' + noticeIds + '"的数据项?', "警告", {
  325. confirmButtonText: "确定",
  326. cancelButtonText: "取消",
  327. type: "warning"
  328. }).then(function() {
  329. return delNotice(noticeIds);
  330. }).then(() => {
  331. this.getList();
  332. this.msgSuccess("删除成功");
  333. }).catch(() => {});
  334. }
  335. }
  336. };
  337. </script>