index.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <template>
  2. <div class="app-container">
  3. <div class="setting_title">通告管理</div>
  4. <el-divider></el-divider>
  5. <div style="margin-top: 20px;">
  6. <el-form label-position="left" label-width="80px">
  7. <el-form-item label="通告内容">
  8. <el-input type="textarea" :rows="6" placeholder="请输入通告内容" v-model="mainData.noticeContent">
  9. </el-input>
  10. </el-form-item>
  11. <el-form-item label="通告状态">
  12. <el-switch v-model="mainData.status" active-text="启用" inactive-text="禁用">
  13. </el-switch>
  14. </el-form-item>
  15. </el-form>
  16. </div>
  17. <div class="page-footer">
  18. <div class="footer" :class="classObj">
  19. <el-button v-if="$restrict('save')" type="primary" @click="submitMainForm">保存</el-button>
  20. </div>
  21. </div>
  22. </div>
  23. </template>
  24. <script>
  25. import { mapGetters } from 'vuex'
  26. import { getNotice, addNotice, editNotice } from '@/api/setting'
  27. import operation_mixin from '@/components/template/operation_mixin.js'
  28. export default {
  29. mixins: [operation_mixin],
  30. data() {
  31. return {
  32. mainData: {
  33. noticeContent: '',
  34. status: false,
  35. },
  36. canClickSave: true,
  37. }
  38. },
  39. computed: {
  40. ...mapGetters([
  41. 'userid'
  42. ]),
  43. sidebar() {
  44. return this.$store.state.app.sidebar
  45. },
  46. classObj() {
  47. return {
  48. hideSidebar: !this.sidebar.opened,
  49. openSidebar: this.sidebar.opened
  50. }
  51. },
  52. },
  53. created() {
  54. this.getNotice();
  55. },
  56. methods: {
  57. // 获取详情
  58. getNotice() {
  59. getNotice().then(res => {
  60. this.mainData = res.data && res.data.length > 0 ? res.data[0] : {
  61. noticeContent: '',
  62. status: false,
  63. };
  64. })
  65. },
  66. // 提交表单
  67. submitMainForm() {
  68. if (this.mainData.status && !this.mainData.noticeContent) {
  69. return this.$errorMsg('启用状态时,内容不能为空');
  70. }
  71. // 编辑
  72. if (this.mainData.noticeId) {
  73. editNotice({
  74. noticeId: this.mainData.noticeId,
  75. noticeContent: this.mainData.noticeContent,
  76. status: this.mainData.status,
  77. }).then(res => {
  78. this.getNotice();
  79. this.$successMsg();
  80. })
  81. }
  82. // 新增
  83. else {
  84. addNotice({
  85. noticeContent: this.mainData.noticeContent,
  86. status: this.mainData.status,
  87. }).then(res => {
  88. this.getNotice();
  89. this.$successMsg();
  90. })
  91. }
  92. },
  93. }
  94. }
  95. </script>
  96. <style scoped lang="scss"></style>