index.vue 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <template>
  2. <div id="index">
  3. <el-row>
  4. <el-col :span="24" class="main">
  5. <el-col :span="24" class="one">
  6. <el-col :span="24" class="text"> 基本信息 </el-col>
  7. <el-col :span="24" class="form"> <one :form="form" :rules="rules"></one> </el-col>
  8. <el-col :span="24" class="btn">
  9. <el-button type="primary" @click="onSubmit">保存信息</el-button>
  10. </el-col>
  11. </el-col>
  12. </el-col>
  13. </el-row>
  14. </div>
  15. </template>
  16. <script>
  17. import one from './parts/one.vue';
  18. import { mapState, createNamespacedHelpers } from 'vuex';
  19. const { mapActions: mechanism } = createNamespacedHelpers('mechanism');
  20. export default {
  21. name: 'index',
  22. props: {},
  23. components: {
  24. one,
  25. },
  26. data: function () {
  27. return {
  28. form: {},
  29. rules: {},
  30. };
  31. },
  32. async created() {
  33. await this.search();
  34. },
  35. methods: {
  36. ...mechanism(['fetch', 'update']),
  37. async search() {
  38. if (this.user.id) {
  39. let res = await this.fetch(this.user.id);
  40. if (this.$checkRes(res)) {
  41. this.$set(this, `form`, res.data);
  42. }
  43. }
  44. },
  45. async onSubmit() {
  46. let data = this.form;
  47. let res = await this.update(data);
  48. if (this.$checkRes(res)) {
  49. this.$message({
  50. message: '修改信息成功',
  51. type: 'success',
  52. });
  53. this.search();
  54. }
  55. },
  56. },
  57. computed: {
  58. ...mapState(['user']),
  59. },
  60. metaInfo() {
  61. return { title: this.$route.meta.title };
  62. },
  63. watch: {
  64. test: {
  65. deep: true,
  66. immediate: true,
  67. handler(val) {},
  68. },
  69. },
  70. };
  71. </script>
  72. <style lang="less" scoped>
  73. .main {
  74. border-radius: 10px;
  75. box-shadow: 0 0 5px #cccccc;
  76. padding: 20px;
  77. .one {
  78. .text {
  79. height: 40px;
  80. line-height: 40px;
  81. border-bottom: 1px dashed #000;
  82. margin: 0 0 10px 0;
  83. }
  84. .btn {
  85. text-align: center;
  86. padding: 15px 0;
  87. }
  88. }
  89. }
  90. .main:hover {
  91. box-shadow: 0 0 5px #409eff;
  92. }
  93. </style>