|
|
@@ -0,0 +1,115 @@
|
|
|
+<style lang="scss">
|
|
|
+ .add{
|
|
|
+ .el-input,button{
|
|
|
+ width: 300px;
|
|
|
+ }
|
|
|
+ }
|
|
|
+</style>
|
|
|
+<template>
|
|
|
+ <section class="add">
|
|
|
+ <p>内容管理 > 资料管理 > 新增资料</p>
|
|
|
+ <div class="content" v-loading.fullscreen.lock="fullscreenLoading">
|
|
|
+ <el-form label-width="80px">
|
|
|
+ <el-form-item label="资料名称">
|
|
|
+ <el-input placeholder="资料名称" v-model="form.name"></el-input>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="资料文件">
|
|
|
+ <a :href="form.url">{{form.url}}</a>
|
|
|
+ <input type="file" @change="upload('url')" id='url'>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label=" ">
|
|
|
+ <el-button @click="save" type="primary">保存</el-button>
|
|
|
+ </el-form-item>
|
|
|
+ </el-form>
|
|
|
+ </div>
|
|
|
+ </section>
|
|
|
+</template>
|
|
|
+<script>
|
|
|
+import Subject from '../../components/Subject';
|
|
|
+export default {
|
|
|
+ components:{
|
|
|
+ Subject
|
|
|
+ },
|
|
|
+ data(){
|
|
|
+ return{
|
|
|
+ fullscreenLoading:false,
|
|
|
+ form:{},
|
|
|
+ id:''
|
|
|
+ }
|
|
|
+ },
|
|
|
+ methods:{
|
|
|
+ subChange(data,id){
|
|
|
+ this.form.subject_id=id
|
|
|
+ this.form.subject_item=data.join('|')
|
|
|
+ },
|
|
|
+ upload(type){
|
|
|
+ var file=document.getElementById(type).files;
|
|
|
+ var data=new FormData();
|
|
|
+ data.append("file",file[0])
|
|
|
+ this.fullscreenLoading=true
|
|
|
+ this.$api.uploadFile(data).then(res=>{
|
|
|
+ this.fullscreenLoading=false
|
|
|
+ if(res.data.code==0){
|
|
|
+ let form=this.form;
|
|
|
+ this.$set(form,type,res.data.data.url)
|
|
|
+ this.$message({message: '上传成功!',type: 'success'});
|
|
|
+ }else{
|
|
|
+ this.$message.error(res.data.message);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ getData(){
|
|
|
+ this.$api.getDocs({id:this.form.id}).then(res=>{
|
|
|
+ this.form=res.data.data
|
|
|
+ })
|
|
|
+ },
|
|
|
+ save(){
|
|
|
+ var parm=this.form;
|
|
|
+ if(parm.id){
|
|
|
+ this.$api.putDocs(parm).then(res=>{
|
|
|
+ if(res.data.code==0){
|
|
|
+ this.$message({message: '修改成功!',type: 'success'});
|
|
|
+ this.$router.push({path:'/docs'})
|
|
|
+ }else{
|
|
|
+ this.$message.error(res.data.message);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }else{
|
|
|
+ this.$api.saveDocs(parm).then(res=>{
|
|
|
+ if(res.data.code==0){
|
|
|
+ this.$message({message: '添加成功!',type: 'success'});
|
|
|
+ this.$router.push({path:'/docs'})
|
|
|
+ }else{
|
|
|
+ this.$message.error(res.data.message);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ },
|
|
|
+ del(id){
|
|
|
+ this.$confirm('确定删除吗', '提示', {
|
|
|
+ type: 'warning'
|
|
|
+ }).then(() => {
|
|
|
+ this.$api.deleteDocs({id:id}).then((res)=>{
|
|
|
+ this.$message({
|
|
|
+ message: '删除成功',
|
|
|
+ type: 'success'
|
|
|
+ })
|
|
|
+ this.getData()
|
|
|
+ })
|
|
|
+ })
|
|
|
+ },
|
|
|
+ },
|
|
|
+ created(){
|
|
|
+ if(this.$route.query.id){
|
|
|
+ this.form.id=this.$route.query.id
|
|
|
+ this.id=this.$route.query.id
|
|
|
+ this.getData()
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+</script>
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|