index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  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="$t('公告标题')" prop="noticeTitle">
  5. <el-input
  6. v-model="queryParams.noticeTitle"
  7. :placeholder="$t('请输入') + $t('公告标题')"
  8. clearable
  9. size="small"
  10. @keyup.enter.native="handleQuery"
  11. />
  12. </el-form-item>
  13. <el-form-item :label="$t('操作人员')" prop="createBy">
  14. <el-input
  15. v-model="queryParams.createBy"
  16. :placeholder="$t('请输入') + $t('操作人员')"
  17. clearable
  18. size="small"
  19. @keyup.enter.native="handleQuery"
  20. />
  21. </el-form-item>
  22. <el-form-item :label="$t('类型')" prop="noticeType">
  23. <el-select v-model="queryParams.noticeType" :placeholder="$t('公告类型')" 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="cyan" icon="el-icon-search" size="mini" @click="handleQuery">{{ $t('搜索') }}</el-button>
  34. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t('重置') }}</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. icon="el-icon-plus"
  42. size="mini"
  43. @click="handleAdd"
  44. v-hasPermi="['system:notice:add']"
  45. >{{ $t('新增') }}</el-button>
  46. </el-col>
  47. <el-col :span="1.5">
  48. <el-button
  49. type="success"
  50. icon="el-icon-edit"
  51. size="mini"
  52. :disabled="single"
  53. @click="handleUpdate"
  54. v-hasPermi="['system:notice:edit']"
  55. >{{ $t('修改') }}</el-button>
  56. </el-col>
  57. <el-col :span="1.5">
  58. <el-button
  59. type="danger"
  60. icon="el-icon-delete"
  61. size="mini"
  62. :disabled="multiple"
  63. @click="handleDelete"
  64. v-hasPermi="['system:notice:remove']"
  65. >{{ $t('删除') }}</el-button>
  66. </el-col>
  67. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  68. </el-row>
  69. <el-table v-loading="loading" :data="noticeList" @selection-change="handleSelectionChange">
  70. <el-table-column type="selection" width="55" align="center" />
  71. <el-table-column :label="$t('序号')" align="center" prop="noticeId" width="100" />
  72. <el-table-column
  73. :label="$t('公告标题')"
  74. align="center"
  75. prop="noticeTitle"
  76. :show-overflow-tooltip="true"
  77. />
  78. <el-table-column
  79. :label="$t('公告类型')"
  80. align="center"
  81. prop="noticeType"
  82. :formatter="typeFormat"
  83. width="100"
  84. />
  85. <el-table-column
  86. :label="$t('状态')"
  87. align="center"
  88. prop="status"
  89. :formatter="statusFormat"
  90. width="100"
  91. />
  92. <el-table-column :label="$t('阅览状态')" align="center" prop="" width="100" />
  93. <el-table-column :label="$t('创建人')" align="center" prop="createBy" width="100" />
  94. <el-table-column :label="$t('创建时间')" align="center" prop="createTime" width="100">
  95. <template slot-scope="scope">
  96. <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
  97. </template>
  98. </el-table-column>
  99. <el-table-column :label="$t('操作')" align="center" class-name="small-padding fixed-width">
  100. <template slot-scope="scope">
  101. <el-button
  102. size="mini"
  103. type="text"
  104. icon="el-icon-select"
  105. @click="handleSelect (scope.row)"
  106. v-hasPermi="['system:notice:select']"
  107. >{{ $t('查看') }}</el-button>
  108. <el-button
  109. size="mini"
  110. type="text"
  111. icon="el-icon-edit"
  112. @click="handleUpdate(scope.row)"
  113. v-hasPermi="['system:notice:edit']"
  114. >{{ $t('修改') }}</el-button>
  115. <el-button
  116. size="mini"
  117. type="text"
  118. icon="el-icon-delete"
  119. @click="handleDelete(scope.row)"
  120. v-hasPermi="['system:notice:remove']"
  121. >{{ $t('删除') }}</el-button>
  122. </template>
  123. </el-table-column>
  124. </el-table>
  125. <pagination
  126. v-show="total>0"
  127. :total="total"
  128. :page.sync="queryParams.pageNum"
  129. :limit.sync="queryParams.pageSize"
  130. @pagination="getList"
  131. />
  132. <!-- 添加或修改公告对话框 -->
  133. <el-dialog v-dialogDrag :title="title" :visible.sync="open" width="780px" append-to-body>
  134. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  135. <el-row>
  136. <el-col :span="12">
  137. <el-form-item :label="$t('公告标题')" prop="noticeTitle">
  138. <el-input v-model="form.noticeTitle" :placeholder="$t('请输入') + $t('公告标题')"/>
  139. </el-form-item>
  140. </el-col>
  141. <el-col :span="12">
  142. <el-form-item :label="$t('公告类型')" prop="noticeType">
  143. <el-select v-model="form.noticeType" :placeholder="$t('请选择') + $t('公告类型')">
  144. <el-option
  145. v-for="dict in typeOptions"
  146. :key="dict.dictValue"
  147. :label="dict.dictLabel"
  148. :value="dict.dictValue"
  149. ></el-option>
  150. </el-select>
  151. </el-form-item>
  152. </el-col>
  153. <el-col :span="24">
  154. <el-form-item :label="$t('状态')">
  155. <el-radio-group v-model="form.status">
  156. <el-radio
  157. v-for="dict in statusOptions"
  158. :key="dict.dictValue"
  159. :label="dict.dictValue"
  160. >{{dict.dictLabel}}</el-radio>
  161. </el-radio-group>
  162. </el-form-item>
  163. </el-col>
  164. <el-col :span="24" >
  165. <el-form-item :label="$t('内容')">
  166. <editor v-model="form.noticeContent" :min-height="192" />
  167. </el-form-item>
  168. </el-col>
  169. </el-row>
  170. </el-form>
  171. <div slot="footer" class="dialog-footer">
  172. <el-button type="primary" @click="submitForm">{{ $t('确 定') }}</el-button>
  173. <el-button @click="cancel">{{ $t('取 消') }}</el-button>
  174. </div>
  175. </el-dialog>
  176. <el-dialog v-dialogDrag :title="title" :visible.sync="checkView" width="780px" append-to-body>
  177. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  178. <el-row>
  179. <el-col :span="12">
  180. <el-form-item :label="$t('公告标题')" prop="noticeTitle">
  181. <el-input v-model="form.noticeTitle" :placeholder="$t('请输入') + $t('公告标题')" v-bind:disabled="check"/>
  182. </el-form-item>
  183. </el-col>
  184. <el-col :span="12">
  185. <el-form-item :label="$t('公告类型')" prop="noticeType">
  186. <el-select v-model="form.noticeType" :placeholder="$t('请选择') + $t('公告类型')" v-bind:disabled="check">
  187. <el-option
  188. v-for="dict in typeOptions"
  189. :key="dict.dictValue"
  190. :label="dict.dictLabel"
  191. :value="dict.dictValue"
  192. ></el-option>
  193. </el-select>
  194. </el-form-item>
  195. </el-col>
  196. <el-col :span="24">
  197. <el-form-item :label="$t('状态')">
  198. <el-radio-group v-model="form.status">
  199. <el-radio
  200. v-for="dict in statusOptions"
  201. :key="dict.dictValue"
  202. :label="dict.dictValue"
  203. v-bind:disabled="check"
  204. >{{dict.dictLabel}}</el-radio>
  205. </el-radio-group>
  206. </el-form-item>
  207. </el-col>
  208. <el-col :span="24" v-if="check">
  209. <el-form-item :label="$t('内容')">
  210. <p v-html="form.noticeContent" />
  211. </el-form-item>
  212. </el-col>
  213. </el-row>
  214. </el-form>
  215. </el-dialog>
  216. </div>
  217. </template>
  218. <script>
  219. import {
  220. listNotice,
  221. getNotice,
  222. delNotice,
  223. addNotice,
  224. updateNotice,
  225. insertReadHis,
  226. listByUserId
  227. } from "@/api/system/notice";
  228. import Editor from '@/components/Editor';
  229. export default {
  230. name: "Notice",
  231. components: {
  232. Editor
  233. },
  234. data() {
  235. return {
  236. checkView: false,
  237. check: false,
  238. // 遮罩层
  239. loading: true,
  240. // 选中数组
  241. ids: [],
  242. // 非单个禁用
  243. single: true,
  244. // 非多个禁用
  245. multiple: true,
  246. // 显示搜索条件
  247. showSearch: true,
  248. // 总条数
  249. total: 0,
  250. // 公告表格数据
  251. noticeList: [],
  252. // 弹出层标题
  253. title: "",
  254. // 是否显示弹出层
  255. open: false,
  256. detailsView: false,
  257. // 类型数据字典
  258. statusOptions: [],
  259. // 状态数据字典
  260. typeOptions: [],
  261. // 查询参数
  262. queryParams: {
  263. pageNum: 1,
  264. pageSize: 10,
  265. noticeTitle: undefined,
  266. createBy: undefined,
  267. status: undefined
  268. },
  269. // 弹出层数据
  270. detailList: {},
  271. // 表单参数
  272. form: {},
  273. // 表单校验
  274. rules: {
  275. noticeTitle: [
  276. { required: true, message: this.$t('公告标题') + this.$t('不能为空'), trigger: "blur" }
  277. ],
  278. noticeType: [
  279. { required: true, message: this.$t('公告类型') + this.$t('不能为空'), trigger: "change" }
  280. ]
  281. },
  282. };
  283. },
  284. created() {
  285. this.getList();
  286. this.getDicts("sys_notice_status").then(response => {
  287. this.statusOptions = response.data;
  288. });
  289. this.getDicts("sys_notice_type").then(response => {
  290. this.typeOptions = response.data;
  291. });
  292. },
  293. methods: {
  294. //查询公告是否已读
  295. /** 查询公告列表 */
  296. getList() {
  297. this.loading = true;
  298. listNotice(this.queryParams).then(response => {
  299. this.noticeList = response.rows;
  300. this.total = response.total;
  301. this.loading = false;
  302. });
  303. },
  304. // 公告状态字典翻译
  305. statusFormat(row, column) {
  306. return this.selectDictLabel(this.statusOptions, row.status);
  307. },
  308. // 公告状态字典翻译
  309. typeFormat(row, column) {
  310. return this.selectDictLabel(this.typeOptions, row.noticeType);
  311. },
  312. // 取消按钮
  313. cancel() {
  314. this.open = false;
  315. this.reset();
  316. },
  317. // 表单重置
  318. reset() {
  319. this.form = {
  320. noticeId: undefined,
  321. noticeTitle: undefined,
  322. noticeType: undefined,
  323. noticeContent: undefined,
  324. status: "0",
  325. };
  326. this.check = false;
  327. this.resetForm("form");
  328. },
  329. /** 搜索按钮操作 */
  330. handleQuery() {
  331. this.queryParams.pageNum = 1;
  332. this.getList();
  333. },
  334. /** 重置按钮操作 */
  335. resetQuery() {
  336. this.resetForm("queryForm");
  337. this.handleQuery();
  338. },
  339. // 多选框选中数据
  340. handleSelectionChange(selection) {
  341. this.ids = selection.map(item => item.noticeId)
  342. this.single = selection.length!=1
  343. this.multiple = !selection.length
  344. },
  345. /** 新增按钮操作 */
  346. handleAdd() {
  347. this.reset();
  348. this.open = true;
  349. this.title = this.$t('新增') + " " + this.$t('公告');
  350. },
  351. /** 修改按钮操作 */
  352. handleUpdate(row) {
  353. this.check = false,
  354. this.reset();
  355. const noticeId = row.noticeId || this.ids
  356. getNotice(noticeId).then(response => {
  357. this.form = response.data;
  358. this.open = true;
  359. this.title = this.$t('修改') + " " + this.$t('公告');
  360. });
  361. },
  362. /** 查看 **/
  363. handleSelect(row) {
  364. debugger;
  365. this.reset();
  366. const noticeId = row.noticeId || this.ids
  367. getNotice(noticeId).then(response => {
  368. this.form = response.data;
  369. this.checkView = true;
  370. this.check= true;
  371. this.title = this.$t('查看') + " " + this.$t('公告');
  372. });
  373. //点击查询,判断是否已有该条数据若已有则不添加,没有则向关联表添加一条数据
  374. insertReadHis(row.noticeId).then(response => {
  375. this.msgSuccess(this.$t('已读'));
  376. this.getList();
  377. });
  378. },
  379. /** 提交按钮 */
  380. submitForm: function() {
  381. this.$refs["form"].validate(valid => {
  382. if (valid) {
  383. if (this.form.noticeId != undefined) {
  384. updateNotice(this.form).then(response => {
  385. this.msgSuccess(this.$t('修改成功'));
  386. this.open = false;
  387. this.getList();
  388. });
  389. } else {
  390. addNotice(this.form).then(response => {
  391. this.msgSuccess(this.$t('新增成功'));
  392. this.open = false;
  393. this.getList();
  394. });
  395. }
  396. }
  397. });
  398. },
  399. /** 删除按钮操作 */
  400. handleDelete(row) {
  401. const noticeIds = row.noticeId || this.ids
  402. this.$confirm(this.$t('是否确认删除公告编号为"')+ ' '+noticeIds+ this.$t('"的数据项?'), this.$t('警告'), {
  403. confirmButtonText: this.$t('确定'),
  404. cancelButtonText: this.$t('取消'),
  405. type: "warning"
  406. }).then(function() {
  407. return delNotice(noticeIds);
  408. }).then(() => {
  409. this.getList();
  410. this.msgSuccess(this.$t('删除成功'));
  411. })
  412. }
  413. }
  414. };
  415. </script>