110 lines
		
	
	
		
			3.1 KiB
		
	
	
	
		
			Vue
		
	
	
	
	
	
			
		
		
	
	
			110 lines
		
	
	
		
			3.1 KiB
		
	
	
	
		
			Vue
		
	
	
	
	
	
| <template>
 | |
|   <ai-detail class="AppQuestionBank-add" v-loading="isLoading">
 | |
|     <template slot="title">
 | |
|       <ai-title :title="params.id ? '编辑' + '试题库' : '添加' + '试题库'" isShowBack isShowBottomBorder @onBackClick="cancel(false)"></ai-title>
 | |
|     </template>
 | |
|     <template slot="content">
 | |
|       <ai-card title="基本信息">
 | |
|         <template #content>
 | |
|           <el-form class="ai-form" :model="form" label-width="120px" ref="form">
 | |
|             <el-form-item label="标题" style="width: 100%;" prop="title" :rules="[{required: true, message: '请输入标题', trigger: 'blur'}]">
 | |
|               <el-input size="small" v-model="form.title" clearable placeholder="请输入..." :maxlength="50" :show-word-limit="true"></el-input>
 | |
|             </el-form-item>
 | |
|             <el-form-item prop="showIndex" label="排序" :rules="[{required: true, message: '请选择文章类型', trigger: 'change'}]">
 | |
|               <el-input-number size="small" v-model="form.showIndex" :min="0"></el-input-number>
 | |
|             </el-form-item>
 | |
|             <el-form-item label="正文" prop="content" style="width: 100%;" :rules="[{required: true, message: '请输入内容', trigger: 'change'}]">
 | |
|               <ai-editor v-model="form.content" :instance="instance"/>
 | |
|             </el-form-item>
 | |
|           </el-form>
 | |
|         </template>
 | |
|       </ai-card>
 | |
|     </template>
 | |
|     <template #footer>
 | |
|       <el-button @click="cancel">取消</el-button>
 | |
|       <el-button type="primary" :loading="isLoading" @click="confirm">提交</el-button>
 | |
|     </template>
 | |
|   </ai-detail>
 | |
| </template>
 | |
| 
 | |
| <script>
 | |
|   import { mapState } from 'vuex'
 | |
|   export default {
 | |
|     name: 'Add',
 | |
| 
 | |
|     props: {
 | |
|       instance: Function,
 | |
|       dict: Object,
 | |
|       params: Object,
 | |
|       areaId: String
 | |
|     },
 | |
|     data () {
 | |
|       return {
 | |
|         info: {},
 | |
|         form: {
 | |
|           title: '',
 | |
|           content: '',
 | |
|           showIndex: ''
 | |
|         },
 | |
|         isLoading: false,
 | |
|         id: ''
 | |
|       }
 | |
|     },
 | |
| 
 | |
|     computed: {
 | |
|       ...mapState(['user'])
 | |
|     },
 | |
| 
 | |
|     created () {
 | |
|       if (this.params && this.params.id) {
 | |
|         this.id = this.params.id
 | |
|         this.getInfo(this.params.id)
 | |
|       }
 | |
|     },
 | |
| 
 | |
|     methods: {
 | |
|       getInfo (id) {
 | |
|         this.instance.post(`/app/appcontentinfo/queryDetailById?id=${id}`).then(res => {
 | |
|           if (res.code === 0) {
 | |
|             this.form = res.data
 | |
|           }
 | |
|         })
 | |
|       },
 | |
| 
 | |
|       confirm () {
 | |
|         this.$refs.form.validate((valid) => {
 | |
|           if (valid) {
 | |
|             this.isLoading = true
 | |
|             this.instance.post(`/app/appcontentinfo/addOrUpdate`, {
 | |
|               ...this.form
 | |
|             }).then(res => {
 | |
|               if (res.code == 0) {
 | |
|                 this.$message.success('提交成功')
 | |
|                 setTimeout(() => {
 | |
|                   this.cancel(true)
 | |
|                 }, 600)
 | |
|               } else {
 | |
|                 this.isLoading = false
 | |
|               }
 | |
|             }).catch(() => {
 | |
|               this.isLoading = false
 | |
|             })
 | |
|           }
 | |
|         })
 | |
|       },
 | |
| 
 | |
|       cancel (isRefresh) {
 | |
|         this.$emit('change', {
 | |
|           type: 'List',
 | |
|           isRefresh: !!isRefresh
 | |
|         })
 | |
|       }
 | |
|     }
 | |
|   }
 | |
| </script>
 | |
| 
 | |
| <style scoped lang="scss">
 | |
|   .AppQuestionBank-add {
 | |
|   }
 | |
| </style>
 |