issueSubDia.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  1. <template>
  2. <div class="issueDia">
  3. <div style="width: 100%;height: 35px;margin-bottom: 20px;display: flex;justify-content: center">
  4. <img src="../../../assets/zhang/engineer/issueTitle.png">
  5. <div class="myTitle">问题上报</div>
  6. <div style=""></div>
  7. <div style="width: 20px;height: 20px;position: absolute;top: 5px;right: 15px" @click="close">
  8. <img src="../../../assets/zhang/engineer/ownCloseBtn.png">
  9. </div>
  10. </div>
  11. <div v-if="dialogVisible" style="z-index: 10000;display: flex;justify-content: center;align-items: center;background-color: transparent;position: absolute;width: 100%;height: 100%" @click="handleCloseView">
  12. <img width="600px" :src="dialogImageUrl" alt="">
  13. </div>
  14. <div class="me">
  15. <div style="width: 35%;color: #00ffff;">
  16. <!-- <div style="text-align: right;margin-bottom: 10px;height: 32px;line-height: 32px">时间:</div>-->
  17. <div style="text-align: right;margin-bottom: 20px;height: 32px;line-height: 32px">标题:</div>
  18. <div style="text-align: right;margin-bottom: 25px;height: 32px;line-height: 32px">发起人:</div>
  19. <div style="text-align: right;margin-bottom: 125px;">内容:</div>
  20. <div style="text-align: right;margin-bottom: 125px;">整改要求:</div>
  21. <div style="text-align: right">截图附件:</div>
  22. </div>
  23. <div style="width: 65%;">
  24. <!-- <el-date-picker
  25. style="margin-bottom: 10px"
  26. v-model="value"
  27. type="date"
  28. placeholder="选择日期">
  29. </el-date-picker>-->
  30. <div>
  31. <el-input v-model="title" placeholder="请输入标题" style="margin-bottom: 20px;width: 220px"></el-input>
  32. </div>
  33. <div>
  34. <el-input v-model="person" placeholder="请输入发起人" style="margin-bottom: 20px;width: 220px"></el-input>
  35. </div>
  36. <el-input v-model="description" type="textarea" :rows=6 placeholder="请输入内容" resize="none" style="margin-bottom: 20px;width: 350px"></el-input>
  37. <el-input v-model="need" type="textarea" :rows=6 placeholder="请输入整改要求" resize="none" style="margin-bottom: 20px;width: 350px"></el-input>
  38. <div style="width: 130px;height: 130px;background: rgba(15, 86, 86, 0.54);margin-bottom: 10px;mborder-radius: 4px;color: #00ffff;position: relative;font-size: 45px;display: flex;align-items: center">
  39. <i v-if="!fileFlag" class="el-icon-plus" style="position: absolute;top: 50%;left: 50%;transform: translate(-50%, -50%);"></i>
  40. <input v-if="!fileFlag" type="file" ref="fileInput" accept=".png, .jpg" @change="handleFileChange" style="display: none;position: absolute;left: -1000px"/>
  41. <div v-if="!fileFlag" @click="triggerFileInput" style="width: 100%;height: 100%;cursor: pointer;position: absolute;"></div>
  42. <div class="sth" v-if="fileFlag">
  43. <div style="width: 0;height: 0;border-left: 30px solid transparent;border-top: 30px solid #000000;position: absolute;top: 0;right: 0">
  44. </div>
  45. <div class="close-icon" @click="handleRemove"></div>
  46. <div style="width: 100%;height: 50%">
  47. <div style="width: 100%;height: 50%;display: flex;justify-content: center;align-items: start">
  48. <i class="el-icon-view" @click="handlePictureCardPreview"></i>
  49. </div>
  50. <div style="width: 100%;height: 50%;display: flex;justify-content: center;color: #00FFFF;font-size: 14px;align-items: end">预览</div>
  51. </div>
  52. </div>
  53. <img width="100%" :src="dialogImageUrl" v-if="fileFlag" style="height: 100%;object-fit: cover;">
  54. </div>
  55. <el-button style="width: 100px;margin-top: 10px;margin-right: 10px;border: 1px solid #00FFFF;border-radius: 2px;" @click="add">提交</el-button>
  56. <el-button style="width: 100px;margin-top: 10px;background: rgba(15, 86, 86, 0.54);color: #00ffff;border: 1px solid #00FFFF;border-radius: 2px;" @click="close">取消</el-button>
  57. </div>
  58. </div>
  59. </div>
  60. </template>
  61. <script>
  62. import { add } from "@/api/screen/service";
  63. import pinyin from "../data/pinyin.js";
  64. import PizZip from 'pizzip'
  65. import Docxtemplater from 'docxtemplater'
  66. import ImageModule from 'docxtemplater-image-module-free'
  67. export default {
  68. name: "IssueSubDia",
  69. props: {
  70. projectName:{
  71. type: String,
  72. default: ''
  73. },
  74. constructionUnit:{
  75. type: String,
  76. default: ''
  77. },
  78. supervisionUnit:{
  79. type: String,
  80. default: ''
  81. },
  82. projectId:{
  83. type: Number,
  84. default: null
  85. },
  86. imgUrl: {
  87. type: String,
  88. default: ''
  89. }
  90. },
  91. data() {
  92. return {
  93. imageSrc: null,
  94. file:null,
  95. title:'',
  96. person:null,
  97. description:'',
  98. need:'',
  99. fileFlag: false,
  100. fileList: [],
  101. dialogImageUrl: '',
  102. dialogVisible: false,
  103. disabled: false,
  104. value:"2020-01-01",
  105. check:false,
  106. checked:false
  107. };
  108. },
  109. mounted() {
  110. this.dialogImageUrl = this.imgUrl
  111. },
  112. methods: {
  113. loadTemplate() {
  114. return fetch("/template.docx")
  115. .then(response => response.arrayBuffer())
  116. .then(buffer => {
  117. return buffer;
  118. });
  119. },
  120. generateWord() {
  121. this.loadTemplate()
  122. .then((buffer) => {
  123. const imageOptions = {
  124. centered: false,
  125. getImage: (tagValue) => this.base64ToArrayBuffer(tagValue),
  126. getSize: () => [150, 100],
  127. };
  128. const today = new Date();
  129. const formattedDate = `${today.getFullYear()}.${today.getMonth() + 1}.${today.getDate()}`;
  130. // 加载 Word 模板和图片插件模块
  131. const zip = new PizZip(buffer);
  132. const doc = new Docxtemplater(zip, { modules: [new ImageModule(imageOptions)] });
  133. // 设置填充模板的数据
  134. const templateData = {
  135. createTime: formattedDate,
  136. projectName: this.projectName,
  137. constructionUnit: this.constructionUnit,
  138. supervisionUnit: this.supervisionUnit,
  139. description: this.description,
  140. need: this.need,
  141. image: this.imageSrc,
  142. };
  143. doc.setData(templateData);
  144. try {
  145. doc.render();
  146. const out = doc.getZip().generate({ type: "blob" });
  147. saveAs(out, "generated-file.docx");
  148. console.log("Word文档已生成并下载!");
  149. } catch (error) {
  150. console.error("生成 Word 文件时出错:", error);
  151. }
  152. })
  153. .catch((error) => {
  154. console.error("加载模板文件时出错:", error);
  155. });
  156. },
  157. base64ToArrayBuffer(base64) {
  158. const binaryString = atob(base64.split(",")[1]);
  159. const len = binaryString.length;
  160. const bytes = new Uint8Array(len);
  161. for (let i = 0; i < len; i++) {
  162. bytes[i] = binaryString.charCodeAt(i);
  163. }
  164. return bytes.buffer;
  165. },
  166. triggerFileInput(){
  167. this.$refs.fileInput.click();
  168. },
  169. add() {
  170. if (this.file == null){
  171. return
  172. }
  173. const issueData = {
  174. title:this.title,
  175. description:this.description,
  176. need:this.need,
  177. projectId: this.projectId,
  178. person: this.person,
  179. delFlag: 0,
  180. status: 0,
  181. };
  182. const formData = new FormData();
  183. formData.append("file", this.file);
  184. formData.append("issue", new Blob([JSON.stringify(issueData)], { type: "application/json" }));
  185. this.generateWord();
  186. add(formData).then((res) => {
  187. if (Number(res.code) === 200) {
  188. this.close();
  189. }
  190. }).catch((err) => {
  191. console.error("提交失败:", err);
  192. });
  193. },
  194. handleFileChange(event) {
  195. const file = event.target.files[0];
  196. if (file) {
  197. this.file = file
  198. this.fileFlag = true
  199. this.dialogImageUrl = URL.createObjectURL(file)
  200. const reader = new FileReader();
  201. reader.onload = (e) => {
  202. const base64String = e.target.result;
  203. this.imageSrc = base64String;
  204. };
  205. reader.readAsDataURL(file);
  206. }
  207. },
  208. handleRemove() {
  209. this.fileFlag = false
  210. this.dialogImageUrl = ''
  211. },
  212. handlePictureCardPreview() {
  213. this.dialogVisible = true;
  214. },
  215. handleCloseView() {
  216. this.dialogVisible = false;
  217. },
  218. change(){
  219. this.checked = !this.check
  220. },
  221. changed(){
  222. this.check = !this.checked
  223. },
  224. choose(){
  225. this.$emit("choose");
  226. },
  227. close() {
  228. this.$emit("close");
  229. },
  230. },
  231. };
  232. </script>
  233. <style lang="scss" scoped>
  234. .close-icon {
  235. position: absolute;
  236. right: 2px;
  237. top: 3px;
  238. width: 15px;
  239. height: 15px;
  240. cursor: pointer;
  241. }
  242. .close-icon::before,
  243. .close-icon::after {
  244. content: '';
  245. position: absolute;
  246. top: 50%;
  247. left: 50%;
  248. width: 10px;
  249. height: 1px;
  250. background-color: #00FFFF;
  251. transform-origin: center;
  252. transform: translate(-50%, -50%);
  253. }
  254. .close-icon::before {
  255. transform: translate(-50%, -50%) rotate(45deg); /* 旋转 45 度 */
  256. }
  257. .close-icon::after {
  258. transform: translate(-50%, -50%) rotate(-45deg); /* 旋转 -45 度 */
  259. }
  260. .myTitle{
  261. color: #00F6EC;
  262. font-size: 16px;
  263. position: absolute;
  264. left: 40px;
  265. top: 6px;
  266. }
  267. .me{
  268. display: flex;flex-wrap: wrap;justify-content: space-around;height: 100%;overflow: auto;
  269. }
  270. .me::-webkit-scrollbar {
  271. display: none;
  272. }
  273. .sth{
  274. width: 100%;
  275. height: 100%;
  276. position: absolute;
  277. font-size: 22px;
  278. cursor: pointer;
  279. opacity: 0;
  280. display: flex;
  281. justify-content: center;
  282. align-items: center;
  283. flex-wrap: wrap;
  284. transition: background-color 0.5s ease;
  285. }
  286. .sth:hover{
  287. opacity: 1;
  288. background: rgba(5, 28, 38, 0.58);
  289. }
  290. .el-scrollbar {
  291. background: #15696b;
  292. border: 1px solid #00ffff;
  293. ul {
  294. li {
  295. color: #fff;
  296. }
  297. }
  298. }
  299. .el-select-dropdown__item.hover,
  300. .el-select-dropdown__item:hover {
  301. background: #15696b;
  302. color: #00ffff;
  303. }
  304. .el-select-dropdown__item.selected {
  305. color: #00ffff;
  306. }
  307. .el-select .el-input .el-select__caret {
  308. display: none;
  309. }
  310. .issueDia {
  311. position: relative;
  312. width: 640px;
  313. height: 708px;
  314. background-size: cover;
  315. background-image: radial-gradient(circle at 50% 50%, #031417b3 0%, #0C1A1A 84%);
  316. }
  317. ::v-deep .el-input__inner{
  318. color: #00ffff;
  319. background-color: rgba(15, 86, 86, 0.54);
  320. border: 1px solid #00ffff4d;
  321. }
  322. ::v-deep .el-textarea__inner{
  323. color: #00ffff;
  324. background-color: rgba(15, 86, 86, 0.54);
  325. border: 1px solid #00ffff4d;
  326. }
  327. ::v-deep .el-button{
  328. font-weight: bold;
  329. color: rgba(2, 24, 24, 0.71);
  330. background-color: #00ffff;
  331. }
  332. ::v-deep .el-checkbox__inner{
  333. background-color: #15696b;
  334. }
  335. ::v-deep .is-checked .el-checkbox__inner{
  336. color: #00ffff;
  337. background-color: #00ffff;
  338. }
  339. ::v-deep .el-checkbox__inner::after{
  340. border-color: rgba(2, 24, 24, 0.71);
  341. border-width: 2px;
  342. }
  343. ::v-deep .el-checkbox__label{
  344. color: #15696b;
  345. }
  346. ::v-deep .is-checked .el-checkbox__label{
  347. color: #00ffff;
  348. }
  349. ::v-deep .el-input__prefix{
  350. color: #00F6EC;
  351. }
  352. ::v-deep .el-input__inner::placeholder{
  353. color: #199294;
  354. }
  355. ::v-deep .el-textarea__inner::placeholder{
  356. color: #199294;
  357. }
  358. </style>