上传头像,等待继续封装

This commit is contained in:
qinjie 2021-11-01 21:42:12 +08:00
parent 5f1d4b31fd
commit e03af8e839
1 changed files with 66 additions and 39 deletions

View File

@ -5,10 +5,7 @@
<!-- 课程名称 --> <!-- 课程名称 -->
<a-col :span="18" :offset="3"> <a-col :span="18" :offset="3">
<a-form-model-item label="课程名称" :label-col="{ span: 4 }" :wrapper-col="{ span: 15 }"> <a-form-model-item label="课程名称" :label-col="{ span: 4 }" :wrapper-col="{ span: 15 }">
<a-input <a-input v-model="form.courseName" v-decorator="['courseName', { rules: [{ required: true, message: '请填写课程名称' }] }]" />
v-model="form.courseName"
v-decorator="['courseName', { rules: [{ required: true, message: '请填写课程名称' }] }]"
/>
</a-form-model-item> </a-form-model-item>
</a-col> </a-col>
@ -25,14 +22,7 @@
<!-- 课时 --> <!-- 课时 -->
<a-col :span="9"> <a-col :span="9">
<a-form-item label="课时" :label-col="{ span: 4 }" :wrapper-col="{ span: 10 }"> <a-form-item label="课时" :label-col="{ span: 4 }" :wrapper-col="{ span: 10 }">
<a-input-number <a-input-number id="hour" v-model="dataValue" :min="1" :max="1000" @change="onChange" :style="{ display: 'ln', width: '100%' }" />
id="hour"
v-model="dataValue"
:min="1"
:max="1000"
@change="onChange"
:style="{ display: 'ln', width: '100%' }"
/>
{{ dataValue }}分钟 {{ dataValue }}分钟
</a-form-item> </a-form-item>
</a-col> </a-col>
@ -79,28 +69,32 @@
<a-input v-model="form.remark" type="textarea" /> <a-input v-model="form.remark" type="textarea" />
</a-form-model-item> </a-form-model-item>
</a-col> </a-col>
<a-button @click="save">保存</a-button>
<!-- 上传封面图片 --> <!-- 上传封面图片 -->
<!-- <a-col :span="18" :offset="3"> <a-col :span="18" :offset="3">
<a-form-model-item label="上传封面图片" :label-col="{ span: 4 }" :wrapper-col="{ span: 15 }"> <a-form-model-item label="上传封面图片" :label-col="{ span: 4 }" :wrapper-col="{ span: 15 }">
<a-upload <a-upload action="/dawa/sys/oss/upload?sourceId=course" list-type="picture-card" :file-list="fileList" :headers="getToken()" @change="handleChange" @preview="handlePreview">
name="avatar" <div v-if="fileList.length < 1">
list-type="picture-card" <a-icon type="plus" />
class="avatar-uploader" <div class="ant-upload-text">上传</div>
:show-upload-list="false" </div>
action="https://www.mocky.io/v2/5cc8019d300000980a055e76" </a-upload>
:before-upload="beforeUpload" <a-modal :visible="previewVisible" :footer="null" @cancel="handleCancel">
@change="handleChange" <img alt="example" style="width: 100%" :src="previewImage" />
> </a-modal>
<!-- <a-upload name="file" list-type="picture-card" class="avatar-uploader" :show-upload-list="false" action="" :headers="getToken()" :change="onSuccess">
<img v-if="imageUrl" :src="imageUrl" alt="avatar" /> <img v-if="imageUrl" :src="imageUrl" alt="avatar" />
<div v-else> <div v-else>
<a-icon :type="loading ? 'loading' : 'plus'" /> <a-icon :type="loading ? 'loading' : 'plus'" />
<div class="ant-upload-text">封面图片</div> <div class="ant-upload-text">封面图片</div>
</div> </div>
</a-upload> </a-upload> -->
</a-form-model-item> </a-form-model-item>
</a-col> --> </a-col>
</a-row>
<a-row :span="18" :offset="3">
<a-button @click="save">保存</a-button>
</a-row> </a-row>
</a-form-model> </a-form-model>
</a-card> </a-card>
@ -109,7 +103,9 @@
<script> <script>
import { courseAdd, getCourseDetails} from '@/api/course/course' import { courseAdd, getCourseDetails } from '@/api/course/course'
import storage from 'store'
import { ACCESS_TOKEN } from '@/store/mutation-types'
export default { export default {
name: 'step1', name: 'step1',
@ -122,6 +118,11 @@ export default {
{ id: '2', name: '人员类别2' }, { id: '2', name: '人员类别2' },
{ id: '3', name: '人员类别3' }, { id: '3', name: '人员类别3' },
], ],
previewVisible: false,
fileList: []
} }
}, },
components: { components: {
@ -129,14 +130,16 @@ export default {
getCourseDetails getCourseDetails
}, },
created() { created() {
getCourseDetails({id: this.$route.query.id }).then(res => { if (this.$route.query.id) {
getCourseDetails({ id: this.$route.query.id }).then(res => {
this.form = res.data; this.form = res.data;
this.form.courseType = this.form.courseType+''; this.form.courseType = this.form.courseType + '';
this.form.industryInvolved = this.form.industryInvolved + ''; this.form.industryInvolved = this.form.industryInvolved + '';
this.form.isRequired = this.form.isRequired + ''; this.form.isRequired = this.form.isRequired + '';
}); });
}
}, },
methods: { methods: {
// //
@ -160,6 +163,30 @@ export default {
} }
}) })
}, },
getToken() {
let hreader = {};
hreader[ACCESS_TOKEN] = storage.get(ACCESS_TOKEN);
return hreader;
},
onSuccess(file) {
console.log('1---', file);
},
handleCancel() {
this.previewVisible = false;
},
async handlePreview(file) {
if (!file.url && !file.preview) {
file.preview = await getBase64(file.originFileObj);
}
this.previewImage = file.url || file.preview;
this.previewVisible = true;
},
handleChange({ fileList }) {
this.fileList = fileList;
},
}, },
} }
</script> </script>