Administrator
2022-01-12 21c7375b7b38ebf2c8a2ca8fbf6fe9fb4f28250f
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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
<template>
  <div class="userSManual">
    <!-- {{ form.link }} -->
    <basic-container id="PDFmain">
      <!-- <embed :src="form.link" type="application/pdf" width="800" height="800" /> -->
      <!-- <object
        :data="form.link"
        type="application/pdf"
        width="800"
        height="800"
      ></object> -->
      <iframe
        id="PDFmainIFRAM"
        src="/pfd/build/generic/web/viewer.html"
        width="100%"
        height="100%"
      >
      </iframe>
    </basic-container>
    <div class="userSManual_upBut" :style="{ display: userSManual_upBut }">
      <el-button type="primary" round @click="openUps">上传用户手册</el-button>
    </div>
    <el-dialog
      title="上传用户手册"
      append-to-body
      :visible.sync="openUp"
      width="70%"
    >
      <avue-form
        :option="option"
        v-model="form"
        @submit="handleSubmit"
        :upload-before="uploadBefore"
        :upload-after="uploadAfter"
      ></avue-form>
    </el-dialog>
  </div>
</template>
 
<script>
import { mapGetters } from "vuex";
import { add, getDetails } from "@/api/resource/attach";
export default {
  data() {
    return {
      openUp: false,
      userSManual_upBut: "none",
      index: 0,
      link: "",
      option: {
        tabs: true,
        tabsActive: 1,
        group: [
          {
            label: "上传用户手册",
            prop: "info",
            column: [
              {
                label: "用户手册",
                type: "upload",
                // listType: "picture-img",
                propsHttp: {
                  res: "data",
                  url: "link",
                },
                // canvasOption: {
                //   text: " ",
                //   ratio: 0.1,
                // },
                action: "/api/blade-resource/oss/endpoint/put-file",
                // action: "/api/blade-resource/oss/endpoint/put-file-attach",
                // tip: "只能上传jpg/png用户头像,且不超过500kb",
                span: 24,
                row: true,
                prop: "link",
                labelWidth: 180,
              },
              {
                label: "首次上传时间",
                span: 24,
                row: true,
                prop: "createTime",
                labelWidth: 180,
                type: "datetime",
                disabled: true,
                format: "yyyy-MM-dd HH:mm:ss",
                valueFormat: "yyyy-MM-dd HH:mm:ss",
              },
              {
                label: "上次更新时间",
                span: 24,
                row: true,
                prop: "updateTime",
                labelWidth: 180,
                type: "datetime",
                disabled: true,
                format: "yyyy-MM-dd HH:mm:ss",
                valueFormat: "yyyy-MM-dd HH:mm:ss",
              },
            ],
          },
        ],
      },
      form: {},
      intime: "",
    };
  },
  computed: {
    ...mapGetters(["userInfo"]),
  },
  created() {
    this.handleWitch();
    if (this.userInfo.role_name == "administrator") {
      this.userSManual_upBut = "block";
    } else {
      this.userSManual_upBut = "none";
    }
  },
  methods: {
    openUps() {
      this.openUp = true;
    },
    uploadBefore(file, done, loading, column) {
      this.link = "";
      this.form = {};
      done();
    },
    uploadAfter(res, done, loading, column) {
      this.link = res.link;
      done();
    },
    handleSubmit(form, done) {
      if (!this.link) {
        this.$message({
          message: "请上传后提交",
          type: "warning",
        });
        done();
        return;
      }
      if (this.index === 0) {
        form["type"] = 10;
        form["link"] = this.link;
        // console.log(form);
        // return;
        add(form).then(
          (res) => {
            if (res.data.success) {
              this.handleWitch();
              this.$message({
                type: "success",
                message: "用户手册上传成功!",
              });
            } else {
              this.$message({
                type: "error",
                message: res.data.msg,
              });
            }
            done();
            this.link = "";
            this.form = {};
            this.openUp = false;
          },
          (error) => {
            window.console.log(error);
            done();
          }
        );
      }
    },
    havepdf() {
      var pdf = document.getElementById("PDFmainIFRAM").contentWindow;
      if (pdf.setUrl) {
        return pdf;
      } else {
        return false;
      }
    },
    setUrl(url) {
      this.intime = setInterval(() => {
        let havePdf = this.havepdf();
        if (havePdf) {
          //   console.log("已加载完");
          havePdf.setUrl(url);
          //   console.log(this.intime, 1);
          clearInterval(this.intime);
          //   console.log(this.intime, 2);
          this.intime = "";
          //   console.log(this.intime, 3);
        } else {
          //   console.log("没加载玩");
        }
        // var pdf = document.getElementById("PDFmainIFRAM").contentWindow;
        // pdf.setUrl(url);
      }, 500);
    },
    handleWitch() {
      if (this.index === 0) {
        getDetails(10).then((res) => {
          const att = res.data.data;
          if (this.intime) {
            clearInterval(this.intime);
            this.setUrl(att.link);
          } else {
            this.setUrl(att.link);
          }
          this.form = {
            id: att.id,
            link: att.link,
            createTime: att.createTime,
            updateTime: att.updateTime,
          };
        });
      }
    },
  },
};
</script>
 
<style lang="scss" scoped>
.userSManual {
  width: 100%;
  height: 97%;
  //   border: 1px solid red;
  box-sizing: border-box;
  position: relative;
  .userSManual_upBut {
    position: absolute;
    right: 56px;
    top: 58px;
  }
  #PDFmain {
    width: 100%;
    height: 100%;
    // border: 1px solid red;
  }
  .el-card.basic-container__card.is-always-shadow {
    width: 100%;
    height: 100%;
  }
}
</style>