1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- <template>
- <div id="detail">
- <el-row>
- <el-col :span="24" class="main animate__animated animate__backInRight">
- <el-col :span="24" class="one">
- <data-form :fields="fields" :data="form" @save="toSave" returns="/adminCenter/test/index"> </data-form>
- </el-col>
- </el-col>
- </el-row>
- </div>
- </template>
- <script>
- import { mapState, createNamespacedHelpers } from 'vuex';
- const { mapActions: maptest } = createNamespacedHelpers('test');
- export default {
- name: 'detail',
- props: {},
- components: {},
- data: function () {
- return {
- form: {
- img_url: [],
- },
- fields: [
- { label: '标题', model: 'title' },
- { label: '内容', model: 'content', type: 'editor', url: '/files/study/news_editor/upload' },
- ],
- };
- },
- created() {
- if (this.id) this.search();
- },
- methods: {
- ...maptest(['fetch', 'create', 'update']),
- async search() {
- let res = await this.fetch(this.id);
- if (this.$checkRes(res)) {
- this.$set(this, `form`, res.data);
- }
- },
- async toSave({ data }) {
- let dup = _.cloneDeep(data);
- let res;
- if (_.get(dup, 'id')) {
- res = await this.update(dup);
- } else {
- res = await this.create(dup);
- }
- if (this.$checkRes(res, '保存成功', '保存失败')) {
- if (this.$dev_mode) this.$router.push('/adminCenter/test/index');
- }
- },
- },
- computed: {
- ...mapState(['user']),
- id() {
- return this.$route.query.id;
- },
- },
- metaInfo() {
- return { title: this.$route.meta.title };
- },
- watch: {
- test: {
- deep: true,
- immediate: true,
- handler(val) {},
- },
- },
- };
- </script>
- <style lang="less" scoped></style>
|