|
@@ -8,16 +8,7 @@
|
|
|
<el-col :span="24" class="main">
|
|
|
<el-form ref="form" label-width="80px">
|
|
|
<el-form-item label="文件上传" prop="zynumberfile">
|
|
|
- <upload
|
|
|
- :limit="1"
|
|
|
- :data="pic"
|
|
|
- type="pic"
|
|
|
- listType="text"
|
|
|
- :url="`/files/task/upload`"
|
|
|
- :newspaperdialog="newspaperdialog"
|
|
|
- @upload="uploadSuccess"
|
|
|
- @delete="toDelete"
|
|
|
- ></upload>
|
|
|
+ <van-uploader v-model="files" :after-read="afterRead" preview-size="160px" accept="*" />
|
|
|
</el-form-item>
|
|
|
<div style="margin: 16px;">
|
|
|
<el-form-item>
|
|
@@ -32,35 +23,100 @@
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
-import upload from '@/components/upload-file.vue';
|
|
|
+const _ = require('lodash');
|
|
|
import NavBar from '@/layout/common/topInfo.vue';
|
|
|
import { mapState, createNamespacedHelpers } from 'vuex';
|
|
|
+const { mapActions: classes } = createNamespacedHelpers('classes');
|
|
|
+const { mapActions: util } = createNamespacedHelpers('util');
|
|
|
+const { mapActions: talented } = createNamespacedHelpers('talented');
|
|
|
export default {
|
|
|
name: 'newspaper',
|
|
|
props: {},
|
|
|
components: {
|
|
|
NavBar,
|
|
|
- upload,
|
|
|
},
|
|
|
data: function() {
|
|
|
return {
|
|
|
title: '',
|
|
|
isleftarrow: '',
|
|
|
navShow: true,
|
|
|
- pic: '',
|
|
|
- newspaperdialog: false,
|
|
|
+ files: [],
|
|
|
+ classInfo: {},
|
|
|
+ info: {},
|
|
|
};
|
|
|
},
|
|
|
- created() {},
|
|
|
+ created() {
|
|
|
+ this.toGetClass();
|
|
|
+ this.search();
|
|
|
+ },
|
|
|
methods: {
|
|
|
- onSubmit() {
|
|
|
- console.log(this.pic);
|
|
|
+ ...talented(['create', 'update']),
|
|
|
+ ...util({ modelFetch: 'fetch', upload: 'upload' }),
|
|
|
+ ...classes({ getClass: 'fetch' }),
|
|
|
+ async search() {
|
|
|
+ let res = await this.modelFetch({ model: 'talented', studentid: this.user.userid });
|
|
|
+ if (this.$checkRes(res)) {
|
|
|
+ const { files, ...others } = res.data;
|
|
|
+ this.$set(this, `files`, files);
|
|
|
+ this.$set(this, `info`, others);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ async toGetClass() {
|
|
|
+ const { classid } = this.user;
|
|
|
+ const r = await this.getClass(classid);
|
|
|
+ if (this.$checkRes(r)) this.$set(this, `classInfo`, r.data);
|
|
|
},
|
|
|
- uploadSuccess({ type, data }) {
|
|
|
- this.$set(this, `${type}`, data.uri);
|
|
|
+ async afterRead(data) {
|
|
|
+ // 此时可以自行将文件上传至服务器
|
|
|
+ this.files.splice(this.files.length - 1, 1, { status: 'uploading', message: '上传中...' });
|
|
|
+ try {
|
|
|
+ const { file } = data;
|
|
|
+ let upuri = `/files/talented/`;
|
|
|
+ if (this.classInfo.term) {
|
|
|
+ upuri = `${upuri}${this.classInfo.term}期`;
|
|
|
+ }
|
|
|
+ if (this.classInfo.name) {
|
|
|
+ upuri = `${upuri}_${this.classInfo.name.includes('班') ? this.classInfo.name : `${this.classInfo.name}班`}`;
|
|
|
+ }
|
|
|
+ if (this.user.name) {
|
|
|
+ upuri = `${upuri}/${this.user.name}${new Date().getTime()}`;
|
|
|
+ }
|
|
|
+ if (upuri.endsWith('_')) upuri = _.trimEnd(upuri, '_');
|
|
|
+ upuri = `${upuri}/upload`;
|
|
|
+ const res = await this.upload({ file, uri: upuri });
|
|
|
+ const { uri } = res.data;
|
|
|
+ if (uri) this.files.splice(this.files.length - 1, 1, { url: uri });
|
|
|
+ else this.files.splice(this.files.length - 1, 1, { status: 'failed', message: '上传失败' });
|
|
|
+ } catch (error) {
|
|
|
+ this.files.splice(this.files.length - 1, 1, { status: 'failed', message: '上传失败' });
|
|
|
+ }
|
|
|
},
|
|
|
- toDelete(index) {
|
|
|
- this.pic.splice(index, 1);
|
|
|
+ async onSubmit() {
|
|
|
+ let dup = _.cloneDeep(this.info);
|
|
|
+ let res;
|
|
|
+ dup.files = _.cloneDeep(this.files);
|
|
|
+ if (_.get(dup, `id`)) {
|
|
|
+ res = await this.update(dup);
|
|
|
+ } else {
|
|
|
+ const { planid, termid, batchid, classid, userid: studentid } = this.user;
|
|
|
+ if (planid) dup.planid = planid;
|
|
|
+ if (termid) dup.termid = termid;
|
|
|
+ if (batchid) dup.batchid = batchid;
|
|
|
+ if (classid) dup.classid = classid;
|
|
|
+ if (studentid) dup.studentid = studentid;
|
|
|
+ res = await this.create(dup);
|
|
|
+ }
|
|
|
+ if (this.$checkRes(res)) {
|
|
|
+ this.$notify({
|
|
|
+ message: '提交成功',
|
|
|
+ type: 'success',
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ this.$notify({
|
|
|
+ message: res.errmsg,
|
|
|
+ type: 'danger',
|
|
|
+ });
|
|
|
+ }
|
|
|
},
|
|
|
},
|
|
|
computed: {
|