UploadControl.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. <!-- -->
  2. <template>
  3. <div class="Big-Book-prev-Textdes Tinydemo" v-if="curQue">
  4. <template v-if="type == 'upload_control_preview_chs'">
  5. <UploadView
  6. :changeFillId="changeFillId"
  7. :accept="accept"
  8. :filleNumber="1"
  9. :fileList="curQue.fileList"
  10. :type="type"
  11. />
  12. </template>
  13. <div v-else>
  14. <div class="uploadBtn">
  15. <img
  16. style="width: 24px; height: 24px"
  17. src="../../../assets/adult/uploadview.png"
  18. alt=""
  19. />
  20. 上传文件
  21. </div>
  22. </div>
  23. <div class="dv" v-loading="loading" v-if="type == 'upload_control_chs'">
  24. <div class="main">
  25. <div class="content">
  26. <template v-if="curQue.data">
  27. <template
  28. v-if="
  29. curQue.data.file_name.indexOf('png') != -1 ||
  30. curQue.data.file_name.indexOf('jpg') != -1
  31. "
  32. >
  33. <img :src="curQue.data.file_url" alt="" />
  34. </template>
  35. <template v-else-if="curQue.data.file_name.indexOf('pdf') != -1">
  36. <pdf
  37. ref="pdf"
  38. :src="curQue.data.fileRelativePath"
  39. v-for="i in curQue.data.numPages"
  40. :key="i"
  41. :page="i"
  42. >
  43. </pdf>
  44. </template>
  45. </template>
  46. </div>
  47. </div>
  48. <div class="remove" @click="remove">
  49. <img src="../../../assets/adult/red_remove.png" alt="" />
  50. </div>
  51. </div>
  52. <template v-if="type == 'upload_control_preview_chs'">
  53. <div class="adult-book-input-item">
  54. <span class="adult-book-lable">下载:</span>
  55. <el-radio-group v-model="curQue.is_upload" @change="forupdata">
  56. <el-radio :label="true">需要</el-radio>
  57. <el-radio :label="false">不需要</el-radio>
  58. </el-radio-group>
  59. </div>
  60. </template>
  61. <!-- <div class="adult-book-input-item" v-if="curQue.is_upload">
  62. <span class="adult-book-lable">上传:</span>
  63. <Upload
  64. :changeFillId="changeuploda"
  65. :datafileList="curQue.upload_list"
  66. :accept="accept"
  67. :filleNumber="1"
  68. />
  69. </div> -->
  70. </div>
  71. </template>
  72. <script>
  73. import UploadView from "../common/UploadView.vue";
  74. import Upload from "../common/Upload.vue";
  75. import pdf from "vue-pdf";
  76. export default {
  77. components: {
  78. UploadView,
  79. pdf,
  80. Upload,
  81. },
  82. props: ["curQue", "changeCurQue", "type"],
  83. data() {
  84. return {
  85. uploadType: "",
  86. fileList: [],
  87. data: null,
  88. numPages: null,
  89. accept: ".png,.jpg,.pdf",
  90. data_structure: {
  91. type: "upload_control_chs",
  92. name: "上传控件",
  93. title: "",
  94. fileList: [],
  95. is_upload: false,
  96. upload_list: [],
  97. },
  98. data_structure2: {
  99. type: "upload_control_preview_chs",
  100. name: "上传控件预览查看",
  101. title: "",
  102. fileList: [],
  103. is_upload: false,
  104. },
  105. loading: false,
  106. };
  107. },
  108. computed: {},
  109. watch: {},
  110. //方法集合
  111. methods: {
  112. forupdata() {
  113. this.$forceUpdate();
  114. },
  115. remove() {
  116. // this.data = null;
  117. // this.curQue.data = null;
  118. // this.curQue.fileList = [];
  119. // this.$message.success("删除成功");
  120. },
  121. changeuploda(fileList, item) {
  122. const articleImgList = JSON.parse(JSON.stringify(fileList));
  123. const articleImgRes = [];
  124. articleImgList.forEach((item) => {
  125. if (item.response) {
  126. const obj = {
  127. name: item.name,
  128. url: item.response.file_info_list[0].file_url,
  129. id: "[FID##" + item.response.file_info_list[0].file_id + "##FID]",
  130. fileID: item.response.file_info_list[0].file_id,
  131. };
  132. articleImgRes.push(obj);
  133. }
  134. });
  135. this.curQue.upload_list = JSON.parse(JSON.stringify(articleImgRes));
  136. },
  137. changeFillId(fileList, item, index) {
  138. const articleImgList = JSON.parse(JSON.stringify(fileList));
  139. const articleImgRes = [];
  140. articleImgList.forEach((item) => {
  141. if (item.response) {
  142. const obj = {
  143. file_name: item.response.file_info_list[0].file_name,
  144. url: item.response.file_info_list[0].file_url,
  145. id: "[FID##" + item.response.file_info_list[0].file_id + "##FID]",
  146. fileID: item.response.file_info_list[0].file_id,
  147. file_relative_path: item.response.file_info_list[0].file_relative_path
  148. };
  149. articleImgRes.push(obj);
  150. }
  151. });
  152. this.curQue.fileList = JSON.parse(JSON.stringify(articleImgRes));
  153. if (fileList.length > 0) {
  154. this.curQue.data = fileList[0]?articleImgRes[0]:fileList[0].file_info_list[0];
  155. if (this.curQue.data?.file_name.indexOf("pdf") != -1) {
  156. this.curQue.data.fileRelativePath =
  157. process.env.VUE_APP_BASE_API + this.curQue.data.file_relative_path;
  158. this.getNumPages();
  159. }
  160. }
  161. },
  162. // 获取pdf的页数
  163. getNumPages() {
  164. let _this = this;
  165. let loadingTask = pdf.createLoadingTask(
  166. _this.curQue.data.fileRelativePath
  167. );
  168. loadingTask.promise
  169. .then((pdff) => {
  170. _this.numPages = pdff.numPages;
  171. _this.curQue.data.numPages = pdff.numPages;
  172. this.$forceUpdate();
  173. })
  174. .catch((err) => {
  175. this.$message.success("pdf 加载失败", err);
  176. this.data = null;
  177. this.curQue.data = null;
  178. this.curQue.fileList = [];
  179. });
  180. },
  181. initcurQue() {
  182. let data;
  183. if (this.type == "upload_control_chs") {
  184. data = JSON.parse(JSON.stringify(this.data_structure));
  185. } else {
  186. data = JSON.parse(JSON.stringify(this.data_structure2));
  187. }
  188. this.changeCurQue(data);
  189. },
  190. },
  191. //生命周期 - 创建完成(可以访问当前this实例)
  192. created() {
  193. if (!this.curQue) {
  194. this.initcurQue();
  195. } else {
  196. if (!this.curQue.is_upload) {
  197. this.curQue.is_upload = false;
  198. }
  199. if (this.type == "upload_control_chs") {
  200. if (!this.curQue.upload_list) {
  201. this.curQue.upload_list = [];
  202. }
  203. }
  204. }
  205. },
  206. //生命周期 - 挂载完成(可以访问DOM元素)
  207. mounted() {},
  208. beforeCreate() {}, //生命周期 - 创建之前
  209. beforeMount() {}, //生命周期 - 挂载之前
  210. beforeUpdate() {}, //生命周期 - 更新之前
  211. updated() {}, //生命周期 - 更新之后
  212. beforeDestroy() {}, //生命周期 - 销毁之前
  213. destroyed() {}, //生命周期 - 销毁完成
  214. activated() {}, //如果页面有keep-alive缓存功能,这个函数会触发
  215. };
  216. </script>
  217. <style lang='scss' scoped>
  218. //@import url(); 引入公共css类
  219. .Big-Book-prev-Textdes {
  220. padding: 24px 0 24px 24px;
  221. background: #f7f7f7;
  222. border: 1px solid rgba(0, 0, 0, 0.1);
  223. .dv {
  224. display: flex;
  225. align-items: center;
  226. .remove {
  227. width: 40px;
  228. height: 39px;
  229. background: #ffffff;
  230. border: 1px solid rgba(0, 0, 0, 0.1);
  231. box-sizing: border-box;
  232. border-radius: 8px;
  233. display: flex;
  234. align-items: center;
  235. justify-content: center;
  236. margin-left: 32px;
  237. cursor: pointer;
  238. img {
  239. width: 24px;
  240. height: 24px;
  241. }
  242. }
  243. }
  244. .uploadBtn {
  245. width: 141px;
  246. height: 39px;
  247. background: #ffffff;
  248. border: 1px solid rgba(0, 0, 0, 0.1);
  249. box-sizing: border-box;
  250. box-shadow: 0px 2px 6px rgba(0, 0, 0, 0.1);
  251. border-radius: 4px;
  252. display: flex;
  253. justify-content: center;
  254. align-items: center;
  255. font-size: 16px;
  256. line-height: 150%;
  257. color: #000000;
  258. img {
  259. margin-right: 13px;
  260. }
  261. }
  262. .main {
  263. margin-top: 23px;
  264. width: 477px;
  265. height: 292px;
  266. background: #ffffff;
  267. border: 1px solid rgba(0, 0, 0, 0.1);
  268. box-sizing: border-box;
  269. border-radius: 8px;
  270. display: flex;
  271. align-items: center;
  272. justify-content: center;
  273. .content {
  274. width: 445px;
  275. height: 260px;
  276. border-radius: 4px;
  277. box-sizing: border-box;
  278. background: linear-gradient(0deg, #ebebeb, #ebebeb);
  279. overflow-y: scroll;
  280. img {
  281. max-width: 100%;
  282. max-height: 100%;
  283. }
  284. }
  285. }
  286. }
  287. </style>