index.vue 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <template>
  2. <div id="index">
  3. <el-row>
  4. <el-col :span="24" class="top">
  5. <topInfo :topTitle="topTitle"></topInfo>
  6. </el-col>
  7. <el-col :span="24" class="main">
  8. <siteMain :form="form" @submitDate="submit" :loading="loading"></siteMain>
  9. </el-col>
  10. </el-row>
  11. </div>
  12. </template>
  13. <script>
  14. import topInfo from '@/layout/public/top.vue';
  15. import siteMain from '@/layout/site/siteMain.vue';
  16. import { createNamespacedHelpers } from 'vuex';
  17. const { mapActions } = createNamespacedHelpers('site');
  18. export default {
  19. name: 'index',
  20. props: {},
  21. components: {
  22. topInfo, //头部信息
  23. siteMain, //站点信息
  24. },
  25. data: () => ({
  26. topTitle: '站点信息管理',
  27. form: {},
  28. loading: false,
  29. }),
  30. created() {
  31. this.search();
  32. },
  33. computed: {
  34. keyWord() {
  35. let meta = this.$route.meta;
  36. let main = meta.title || '';
  37. return main;
  38. },
  39. },
  40. methods: {
  41. ...mapActions(['showInfo', 'create', 'update']),
  42. async search() {
  43. let res = await this.showInfo();
  44. let object = JSON.parse(JSON.stringify(res.data));
  45. if (object) {
  46. this.$set(this, `form`, res.data);
  47. }
  48. this.$set(this, `loading`, true);
  49. },
  50. async submit({ id, data }) {
  51. let res;
  52. let msg;
  53. if (id) {
  54. res = await this.update(data);
  55. msg = `${this.keyWord}修改成功`;
  56. } else {
  57. res = await this.create(data);
  58. msg = `${this.keyWord}添加成功`;
  59. }
  60. this.$checkRes(res, msg);
  61. },
  62. },
  63. };
  64. </script>
  65. <style lang="less" scoped>
  66. .main {
  67. padding: 20px;
  68. margin: 10px 20px;
  69. border: 1px solid #ccc;
  70. width: 96%;
  71. }
  72. </style>