hejianhao
2025-04-16 dab2d210ca06c1faa514c6388fbd5de1ab355360
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
<template>
  <div class='app_upload_image'>
    <button
      id="video-upload"
      class="dn"
    ></button>
    <div
      class="app_upload_image_cover demo_upload"
      @click="onUpload"
    >
      <i class="el-icon-plus"></i>
      <b>添加视频</b>
      <span
        class="close"
        v-if="pics && close"
        @click.stop="onClose"
      ></span>
      <div
        class="ava"
        v-if="pics"
        @click.stop="onShow"
      ><img
          :src="pics"
          alt=""
        ></div>
    </div>
  </div>
</template>
 
<script>
export default {
  props: {
    size: { type: Number, default: 50 },
    pic: { type: String, default: "" },
    url: { type: String, default: "" },
    close: { type: Boolean, default: true },
    list: {
      type: Object,
      default: () => {
        return {};
      },
    },
  },
  components: {},
  data() {
    return {
      pics: "",
      path: "",
      timeout: "",
    };
  },
  inject: ["appShowVideo"],
  watch: {
    pic(n) {
      this.pics = n;
    },
    url(n) {
      this.path = n;
    },
    list: {
      handler(n) {
        if (n.timeout) {
          this.timeout = n.timeout;
          this.path = n.url;
          this.pics = this.$js.icon.movie;
        }
      },
      deep: true,
    },
  },
  methods: {
    onUpload() {
      demo.js("#video-upload").find("label").click();
    },
    onClose() {
      this.pics = "";
      this.path = "";
      this.$emit("on-delete");
      this.$nextTick(() => {
        this.emit();
      });
    },
    onShow() {
      this.appShowVideo({ url: this.path });
    },
    emit() {
      this.$emit("on-success", {
        path: this.path,
        pic: this.pics,
        timeout: this.timeout,
      });
    },
  },
  mounted() {
    let ts = this;
    ts.pics = ts.pic;
    ts.path = ts.url;
    demo.js("#video-upload").file(
      (e) => {
        let load = demo.loading();
        if (e.file.size / 1024 / 1024 > ts.size) {
          demo.remove(load);
          return demo.toast("视频容量过大,请传入小于" + ts.size + "MB的视频");
        }
        ts.$js.length(e.file, "video", (n) => {
          if (n > 0) {
            if (n > 60) {
              demo.remove(load);
              return demo.toast("视频控制在60秒内");
            }
            ts.$api.upload(
              "common/uploadimage",
              { file: e.file },
              (r) => {
                ts.pics = ts.$js.icon.movie;
                ts.path = r;
                let a = demo._div("video");
                a.setAttribute("src", r);
 
                a.addEventListener("progress", () => {
                  ts.timeout = a.duration;
                  ts.emit();
                });
                a.addEventListener("error", () => {
                  ts.timeout = "";
                  ts.path = "";
                  demo.toast("视频错误");
                });
                demo.remove(load);
                demo.js("#" + e.id).val("");
              },
              () => {
                demo.remove(load);
                demo.js("#" + e.id).val("");
              }
            );
          } else {
            demo.remove(load);
          }
        });
      },
      { type: "other", accept: "video/*" }
    );
  },
};
</script>
<style lang='less' scoped>
.app_upload_image {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  .app_upload_image_cover {
    width: 100px;
    height: 100px;
    position: relative;
    left: 0;
    top: 0;
    text-align: center;
    font-size: 14px;
    color: #999;
    border-radius: 5px;
    border: 1px dashed #ccc;
    box-sizing: border-box;
    padding-top: 20px;
    cursor: pointer;
    i {
      font-size: 33px;
      display: block;
      margin: 0 auto 10px;
    }
  }
  .desc {
    font-size: 15px;
    color: #999;
    box-sizing: border-box;
    line-height: 30px;
    padding-left: 15px;
    height: 100px;
    padding-top: 70px;
  }
  .demo_upload {
    margin: 0 12px 12px 0;
  }
  .ava {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    z-index: 300;
    background-color: #eee;
    img {
      display: block;
      width: 100%;
      height: 100%;
    }
  }
  .close {
    position: absolute;
    right: -10px;
    top: -10px;
    width: 20px;
    height: 20px;
    text-align: center;
    cursor: pointer;
    z-index: 305;
    border-radius: 50%;
    background-color: tomato;
    box-shadow: 0 0 3px red;
    transform: rotate(45deg);
    &::before,
    &::after {
      position: absolute;
      content: "";
      width: 2px;
      height: 12px;
      background-color: #fff;
      top: 0;
      bottom: 0;
      left: 0;
      right: 0;
      margin: auto;
    }
    &::after {
      transform: rotate(90deg);
    }
  }
}
</style>