noticebar.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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
  9. type="textarea"
  10. :rows="6"
  11. placeholder="请输入通告内容"
  12. v-model="mainData.noticeContent">
  13. </el-input>
  14. </el-form-item>
  15. <el-form-item label="通告状态">
  16. <el-switch
  17. v-model="mainData.status"
  18. active-text="启用"
  19. inactive-text="禁用">
  20. </el-switch>
  21. </el-form-item>
  22. </el-form>
  23. </div>
  24. <div class="page-footer">
  25. <div class="footer" :class="classObj">
  26. <el-button type="primary" @click="submitMainForm">保存</el-button>
  27. </div>
  28. </div>
  29. </div>
  30. </template>
  31. <script>
  32. import { mapGetters } from 'vuex'
  33. import { getNotice, addNotice, editNotice } from '@/api/setting'
  34. export default {
  35. data() {
  36. return {
  37. mainData: {
  38. noticeContent: '',
  39. status: false,
  40. },
  41. canClickSave: true,
  42. }
  43. },
  44. computed: {
  45. ...mapGetters([
  46. 'userid'
  47. ]),
  48. sidebar() {
  49. return this.$store.state.app.sidebar
  50. },
  51. classObj() {
  52. return {
  53. hideSidebar: !this.sidebar.opened,
  54. openSidebar: this.sidebar.opened
  55. }
  56. },
  57. },
  58. created() {
  59. this.getNotice();
  60. },
  61. methods: {
  62. // 查询按钮权限
  63. checkBtnRole(value) {
  64. // let btnRole = this.$route.meta.roles;
  65. // if(!btnRole) {return true}
  66. // let index = btnRole.indexOf(value);
  67. // return index >= 0 ? true : false;
  68. return true;
  69. },
  70. // 获取详情
  71. getNotice() {
  72. getNotice().then(res => {
  73. this.mainData = res.data && res.data.length > 0 ? res.data[0] : {
  74. noticeContent: '',
  75. status: false,
  76. };
  77. })
  78. },
  79. // 提交表单
  80. submitMainForm() {
  81. if(this.mainData.status && !this.mainData.noticeContent) {
  82. return this.$errorMsg('启用状态时,内容不能为空');
  83. }
  84. // 编辑
  85. if(this.mainData.noticeId) {
  86. editNotice({
  87. noticeId: this.mainData.noticeId,
  88. noticeContent: this.mainData.noticeContent,
  89. status: this.mainData.status,
  90. }).then(res => {
  91. this.getNotice();
  92. this.$successMsg();
  93. })
  94. }
  95. // 新增
  96. else {
  97. addNotice({
  98. noticeContent: this.mainData.noticeContent,
  99. status: this.mainData.status,
  100. }).then(res => {
  101. this.getNotice();
  102. this.$successMsg();
  103. })
  104. }
  105. },
  106. }
  107. }
  108. </script>
  109. <style scoped lang="scss">
  110. .page-footer {
  111. height: 70px;
  112. }
  113. .footer {
  114. position: fixed;
  115. bottom: 0;
  116. left: 0;
  117. z-index: 1;
  118. width: 100%;
  119. background: #fff;
  120. padding: 15px 40px;
  121. box-sizing: border-box;
  122. transition: all 0.28s;
  123. text-align: right;
  124. box-shadow: 0 2px 5px 0 rgb(0 0 0 / 50%), 0 2px 5px 0 rgb(0 0 0 / 10%);
  125. &.hideSidebar {
  126. margin-left: 54px;
  127. width: calc(100vw - 54px);
  128. }
  129. &.openSidebar {
  130. margin-left: 210px;
  131. width: calc(100vw - 210px);
  132. }
  133. .tips {
  134. font-size: 12px;
  135. color: red;
  136. margin-top: 10px;
  137. }
  138. }
  139. </style>