lrf402788946 4 years ago
parent
commit
10601f0159
4 changed files with 88 additions and 27 deletions
  1. 8 5
      src/layout/user/clickBtn.vue
  2. 2 0
      src/store/index.js
  3. 1 1
      src/views/user/chuanzuoye.vue
  4. 77 21
      src/views/user/newspaper.vue

+ 8 - 5
src/layout/user/clickBtn.vue

@@ -20,8 +20,11 @@
         <el-col :span="24" class="native">
           <van-cell is-link @click="$router.push({ path: '/user/leave' })">请假&退出</van-cell>
         </el-col>
-        <el-col :span="24" class="native">
-          <van-cell is-link @click="$router.push({ path: '/user/afterClass' })">课后答疑</van-cell>
+        <el-col :span="24" class="native" v-if="user.job == '班长' || user.job == '学委'">
+          <van-cell is-link @click="$router.push({ path: '/user/experience' })">培训心得</van-cell>
+        </el-col>
+        <el-col :span="24" class="native" v-if="user.job == '宣传委员'">
+          <van-cell is-link @click="$router.push({ path: '/user/newspaper' })">新人才报</van-cell>
         </el-col>
         <el-col :span="24" class="native">
           <van-cell is-link @click="$router.push({ path: '/user/league' })">积分榜</van-cell>
@@ -30,10 +33,10 @@
           <van-cell is-link @click="$router.push({ path: '/user/live' })">直播</van-cell>
         </el-col>
         <el-col :span="24" class="native">
-          <van-cell is-link @click="$router.push({ path: '/user/trainVidoe' })">课程培训</van-cell>
+          <van-cell is-link @click="$router.push({ path: '/user/afterClass' })">课后答疑</van-cell>
         </el-col>
-        <el-col :span="24" class="native" v-if="user.job == '班长' || user.job == '学委'">
-          <van-cell is-link @click="$router.push({ path: '/user/experience' })">培训心得</van-cell>
+        <el-col :span="24" class="native">
+          <van-cell is-link @click="$router.push({ path: '/user/trainVidoe' })">课程培训</van-cell>
         </el-col>
       </el-col>
     </el-row>

+ 2 - 0
src/store/index.js

@@ -34,6 +34,7 @@ import liveroom from '@frame/store/liveroom';
 import groupscore from '@frame/store/groupscore';
 import trainvideo from '@frame/store/trainvideo';
 import experience from '@frame/store/experience';
+import talented from '@frame/store/talented';
 import * as ustate from './user/state';
 import * as umutations from './user/mutations';
 Vue.use(Vuex);
@@ -78,5 +79,6 @@ export default new Vuex.Store({
     groupscore,
     trainvideo,
     experience,
+    talented,
   },
 });

+ 1 - 1
src/views/user/chuanzuoye.vue

@@ -69,7 +69,7 @@ export default {
     this.search();
   },
   methods: {
-    ...util({ modelFetch: 'fetch', taskUpload: 'taskupload' }),
+    ...util({ modelFetch: 'fetch', taskUpload: 'upload' }),
     ...mapUploadtask({ list: 'query', add: 'create', fet: 'fetch', update: 'update' }),
     // 查找作业
     async search() {

+ 77 - 21
src/views/user/newspaper.vue

@@ -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: {