inleft
2022-03-02 34223b096cf6ad9d92c3702bb9529e764f523b11
_web/src/views/main/blogarticle/editForm.vue
@@ -1,113 +1,58 @@
<template>
  <a-modal
    title="编辑blog文章"
    :width="900"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleSubmit"
    @cancel="handleCancel"
  >
  <a-modal title="编辑blog文章" :width="900" :visible="visible" :confirmLoading="confirmLoading" @ok="handleSubmit"
    @cancel="handleCancel">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-form-item v-show="false"><a-input v-decorator="['id']" /></a-form-item>
        <a-form-item
          label="文章标题"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          has-feedback
        >
        <a-form-item v-show="false">
          <a-input v-decorator="['id']" />
        </a-form-item>
        <a-form-item label="文章标题" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入文章标题" v-decorator="['title', {rules: [{required: true, message: '请输入文章标题!'}]}]" />
        </a-form-item>
        <a-form-item
          label="文章文件id"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          has-feedback
        >
          <a-input placeholder="请输入文章文件id" v-decorator="['articleFileId', {rules: [{required: true, message: '请输入文章文件id!'}]}]" />
        <a-form-item label="文章文件id" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入文章文件id"
            v-decorator="['articleFileId', {rules: [{required: true, message: '请输入文章文件id!'}]}]" />
        </a-form-item>
        <a-form-item
          label="文件类型"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
        >
          <a-radio-group placeholder="请选择文件类型" v-decorator="['articleFileType']" >
            <a-radio v-for="(item,index) in articleFileTypeData" :key="index" :value="item.code">{{ item.name }}</a-radio>
        <a-form-item label="文件类型" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-radio-group placeholder="请选择文件类型" v-decorator="['articleFileType']">
            <a-radio v-for="(item,index) in articleFileTypeData" :key="index" :value="item.code">{{ item.name }}
            </a-radio>
          </a-radio-group>
        </a-form-item>
        <a-form-item
          label="文章分类"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          has-feedback
        >
          <a-input placeholder="请输入文章分类" v-decorator="['articleTypeId', {rules: [{required: true, message: '请输入文章分类!'}]}]" />
        <a-form-item label="文章分类" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入文章分类"
            v-decorator="['articleTypeId', {rules: [{required: true, message: '请输入文章分类!'}]}]" />
        </a-form-item>
        <a-form-item
          label="文章引言"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          has-feedback
        >
          <a-textarea placeholder="请输入文章引言" v-decorator="['introduce']" :auto-size="{ minRows: 3, maxRows: 6 }"/>
        <a-form-item label="文章引言" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-textarea placeholder="请输入文章引言" v-decorator="['introduce']" :auto-size="{ minRows: 3, maxRows: 6 }" />
        </a-form-item>
        <a-form-item
          label="封面文件"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          has-feedback
        >
        <a-form-item label="封面文件" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入封面文件" v-decorator="['coverFileId']" />
        </a-form-item>
        <a-form-item
          label="是否置顶"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
        >
          <a-select style="width: 100%" placeholder="请选择是否置顶" v-decorator="['isTop', {rules: [{ required: true, message: '请选择是否置顶!' }]}]">
            <a-select-option v-for="(item,index) in isTopData" :key="index" :value="item.code">{{ item.name }}</a-select-option>
        <a-form-item label="是否置顶" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-select style="width: 100%" placeholder="请选择是否置顶"
            v-decorator="['isTop', {rules: [{ required: true, message: '请选择是否置顶!' }]}]">
            <a-select-option v-for="(item,index) in isTopData" :key="index" :value="item.code">{{ item.name }}
            </a-select-option>
          </a-select>
        </a-form-item>
        <a-form-item
          label="置顶值"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          has-feedback
        >
        <a-form-item label="置顶值" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入置顶值" v-decorator="['topValue']" />
        </a-form-item>
        <a-form-item
          label="公开状态"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
        >
          <a-radio-group placeholder="请选择公开状态" v-decorator="['authStatus']" >
        <a-form-item label="公开状态" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-radio-group placeholder="请选择公开状态" v-decorator="['authStatus']">
            <a-radio v-for="(item,index) in authStatusData" :key="index" :value="item.code">{{ item.name }}</a-radio>
          </a-radio-group>
        </a-form-item>
        <a-form-item
          label="授权密码"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          has-feedback
        >
        <a-form-item label="授权密码" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入授权密码" v-decorator="['authPassword']" />
        </a-form-item>
        <a-form-item
          label="编辑状态"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
        >
          <a-radio-group placeholder="请选择编辑状态" v-decorator="['editorStatus']" >
        <a-form-item label="编辑状态" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-radio-group placeholder="请选择编辑状态" v-decorator="['editorStatus']">
            <a-radio v-for="(item,index) in editorStatusData" :key="index" :value="item.code">{{ item.name }}</a-radio>
          </a-radio-group>
        </a-form-item>
        <a-form-item
          label="是否启用"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          has-feedback
        >
        <a-form-item label="是否启用" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入是否启用" v-decorator="['isEnable']" />
        </a-form-item>
      </a-form>
@@ -116,17 +61,27 @@
</template>
<script>
  import { blogArticleEdit } from '@/api/modular/main/blogarticle/blogArticleManage'
  import {
    blogArticleEdit
  } from '@/api/modular/main/blogarticle/blogArticleManage'
  export default {
    data () {
    data() {
      return {
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 }
          xs: {
            span: 24
          },
          sm: {
            span: 5
          }
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 15 }
          xs: {
            span: 24
          },
          sm: {
            span: 15
          }
        },
        articleFileTypeData: [],
        isTopData: [],
@@ -139,7 +94,7 @@
    },
    methods: {
      // 初始化方法
      edit (record) {
      edit(record) {
        this.visible = true
        const articleFileTypeOption = this.$options
        this.articleFileTypeData = articleFileTypeOption.filters['dictData']('blog_file_type')
@@ -149,33 +104,51 @@
        this.authStatusData = authStatusOption.filters['dictData']('blog_auth_status')
        const editorStatusOption = this.$options
        this.editorStatusData = editorStatusOption.filters['dictData']('blog_editor_status')
        this.form.getFieldDecorator('articleFileType', {
          valuePropName: 'checked',
          initialValue: record.articleFileType.toString()
        })
        this.form.getFieldDecorator('authStatus', {
          valuePropName: 'checked',
          initialValue: record.authStatus.toString()
        })
        this.form.getFieldDecorator('editorStatus', {
          valuePropName: 'checked',
          initialValue: record.editorStatus.toString()
        })
        setTimeout(() => {
          this.form.setFieldsValue(
            {
              id: record.id,
              title: record.title,
              articleFileId: record.articleFileId,
              articleFileType: record.articleFileType,
              articleTypeId: record.articleTypeId,
              introduce: record.introduce,
              coverFileId: record.coverFileId,
              isTop: record.isTop,
              topValue: record.topValue,
              authStatus: record.authStatus,
              authPassword: record.authPassword,
              editorStatus: record.editorStatus,
              isEnable: record.isEnable
            }
          )
          this.form.setFieldsValue({
            id: record.id,
            title: record.title,
            articleFileId: record.articleFileId,
            // articleFileType: record.articleFileType,
            articleTypeId: record.articleTypeId,
            introduce: record.introduce,
            coverFileId: record.coverFileId,
            isTop: record.isTop,
            topValue: record.topValue,
            // authStatus: record.authStatus,
            authPassword: record.authPassword,
            // editorStatus: record.editorStatus,
            isEnable: record.isEnable
          })
        }, 100)
      },
      handleSubmit () {
        const { form: { validateFields } } = this
      handleSubmit() {
        const {
          form: {
            validateFields
          }
        } = this
        this.confirmLoading = true
        validateFields((errors, values) => {
          if (!errors) {
            for (const key in values) {
              if (typeof (values[key]) === 'object' && values[key] != null) {
              if (typeof(values[key]) === 'object' && values[key] != null) {
                values[key] = JSON.stringify(values[key])
              }
            }
@@ -186,7 +159,7 @@
                this.$emit('ok', values)
                this.handleCancel()
              } else {
                this.$message.error('编辑失败')//  + res.message
                this.$message.error('编辑失败') //  + res.message
              }
            }).finally((res) => {
              this.confirmLoading = false
@@ -196,7 +169,7 @@
          }
        })
      },
      handleCancel () {
      handleCancel() {
        this.form.resetFields()
        this.visible = false
      }