index.vue 10 KB

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