onlineWrite.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  1. <template>
  2. <div class="engBox">
  3. <div class="engTitle">
  4. <div>作文题目:</div>
  5. <div>{{ englishList.engTitle }}</div>
  6. </div>
  7. <div class="engText">
  8. <div>作文内容:</div>
  9. <div class="cont" v-html="englishList.englishText"></div>
  10. </div>
  11. <div
  12. v-for="(item, index) in myAnswerList.imgList"
  13. :key="index"
  14. class="imgListCss"
  15. >
  16. <div class="itemImg">
  17. <img :src="item.url" alt="" />
  18. <div class="itemDeleteImg" @click="deleteImgList">
  19. <img src="../../../assets/icon/english/delete.png" alt="" />
  20. </div>
  21. </div>
  22. </div>
  23. <div class="chooseUpload" @click="type = 1" v-if="type == 0">+在线编写</div>
  24. <div
  25. class="chooseUpload"
  26. @click="uploadDialogVisible = true"
  27. v-if="type == 0"
  28. >
  29. +图片上传
  30. </div>
  31. <div v-if="type == 1">
  32. <div class="ftypeBox">
  33. <div class="ftypeTitle">
  34. <div>标题:</div>
  35. <div>
  36. <el-input
  37. v-model="myAnswerList.engTitle"
  38. placeholder="请填写你的作文题目"
  39. ></el-input>
  40. </div>
  41. </div>
  42. <div class="ftypeText">
  43. <div>正文:</div>
  44. <div>
  45. <el-input
  46. type="textarea"
  47. :rows="20"
  48. resize="none"
  49. v-model="myAnswerList.engText"
  50. ></el-input>
  51. </div>
  52. </div>
  53. <div class="upImg" @click="uploadDialogVisible = true">
  54. <img src="../../../assets/icon/english/uploadImg.png" alt="" />
  55. </div>
  56. </div>
  57. </div>
  58. <el-dialog
  59. title="图片上传"
  60. :visible.sync="uploadDialogVisible"
  61. :append-to-body="true"
  62. width="30%"
  63. :before-close="handleClose"
  64. class="dialog_diy"
  65. >
  66. <div
  67. class="chapter_add"
  68. @click="addImg($event)"
  69. v-if="myAnswerList.imgList.length == 0"
  70. >
  71. <div class="up_photo2">
  72. <img src="../../../assets/icon/plwork1.png" alt />
  73. <span>点击上传文件</span>
  74. </div>
  75. <input
  76. type="file"
  77. accept="video/mp4, video/quicktime, video/x-msvideo,application/pdf, application/.ppt, .pptx, .xlsx, .xls, application/msword, application/vnd.openxmlformats-officedocument.wordprocessingml.document, image/*"
  78. multiple="multiple"
  79. style="display: none"
  80. @change="beforeUpload($event)"
  81. />
  82. </div>
  83. <div class="chapter_add" v-else>
  84. <div class="isUpImg">
  85. <img :src="myAnswerList.imgList[0].url" alt="" />
  86. </div>
  87. <div class="deleteImg" @click="deleteImgList">
  88. <img src="../../../assets/icon/english/delete.png" alt="" />
  89. </div>
  90. </div>
  91. <div style="text-align: center">如已进行填写,确认后讲清空内容噢。</div>
  92. <span slot="footer" class="dialog-footer">
  93. <el-button @click="uploadDialogVisible = false">取 消</el-button>
  94. <el-button type="primary" @click="uploadIsType">确定</el-button>
  95. </span>
  96. </el-dialog>
  97. </div>
  98. </template>
  99. <script>
  100. export default {
  101. props: ["englishList", "myAnswerList1"],
  102. data() {
  103. return {
  104. type: 0,
  105. myAnswerList: {
  106. engTitle: "",
  107. engText: "",
  108. imgList: [],
  109. },
  110. uploadDialogVisible: false,
  111. noneBtnImg: false,
  112. };
  113. },
  114. watch: {
  115. myAnswerList1: {
  116. handler(newVal) {
  117. if (
  118. !this.myAnswerList1.engTitle &&
  119. !this.myAnswerList1.engText &&
  120. !this.myAnswerList1.imgList.length
  121. ) {
  122. this.myAnswerList = {
  123. engTitle: "",
  124. engText: "",
  125. imgList: [],
  126. };
  127. this.type = 0;
  128. } else {
  129. this.myAnswerList = newVal;
  130. this.type = 1;
  131. }
  132. },
  133. deep: true,
  134. },
  135. },
  136. methods: {
  137. handleClose(done) {
  138. done();
  139. },
  140. imgChange() {
  141. var _tmp = this.myAnswerList.imgList;
  142. this.noneBtnImg = _tmp.length >= 1;
  143. },
  144. addImg(e) {
  145. var el = e.currentTarget;
  146. el.getElementsByTagName("input")[0].click();
  147. e.target.value = "";
  148. },
  149. deleteImgList() {
  150. this.myAnswerList.imgList = [];
  151. },
  152. uploadIsType() {
  153. if (this.type == 2) {
  154. this.type = 1;
  155. }
  156. this.uploadDialogVisible = false;
  157. },
  158. async beforeUpload(event) {
  159. // this.$message.success('进入上传')
  160. var file = event.target.files[0];
  161. var credentials = {
  162. accessKeyId: "AKIATLPEDU37QV5CHLMH",
  163. secretAccessKey: "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",
  164. }; //秘钥形式的登录上传
  165. window.AWS.config.update(credentials);
  166. window.AWS.config.region = "cn-northwest-1"; //设置区域
  167. var bucket = new window.AWS.S3({ params: { Bucket: "ccrb" } }); //选择桶
  168. var _this = this;
  169. // _this.progress = 0;
  170. var photoA = [
  171. "BMP",
  172. "GIF",
  173. "PNG",
  174. "JPGE",
  175. "JPG",
  176. "TIF",
  177. "PCX",
  178. "TGA",
  179. "EXIF",
  180. "FPX",
  181. "SVG",
  182. "APNG",
  183. ];
  184. if (
  185. photoA.indexOf(
  186. file.name
  187. .split(".")
  188. [file.name.split(".").length - 1].toLocaleUpperCase()
  189. ) == -1
  190. ) {
  191. _this.$message.error("请上传图片!");
  192. return;
  193. }
  194. if (file) {
  195. var params = {
  196. Key:
  197. file.name.split(".")[0] +
  198. new Date().getTime() +
  199. "." +
  200. file.name.split(".")[file.name.split(".").length - 1],
  201. ContentType: file.type,
  202. Body: file,
  203. "Access-Control-Allow-Credentials": "*",
  204. ACL: "public-read",
  205. }; //key可以设置为桶的相抵路径,Body为文件, ACL最好要设置
  206. var options = {
  207. // partSize: 2048 * 1024 * 1024,
  208. partSize: 1024 * 1024 * 1024,
  209. queueSize: 2,
  210. leavePartsOnError: true,
  211. };
  212. bucket
  213. .upload(params, options)
  214. .on("httpUploadProgress", function (evt) {
  215. //这里可以写进度条
  216. // console.log("Uploaded : " + parseInt((evt.loaded * 80) / evt.total) + '%');
  217. // _this.progress = parseInt((evt.loaded * 80) / evt.total);
  218. })
  219. .send(function (err, data) {
  220. // _this.progress = 100;
  221. if (err) {
  222. var a = _this.$refs.upload1.uploadFiles;
  223. a.splice(a.length - 1, a.length);
  224. _this.$message.error("上传失败");
  225. } else {
  226. // _this.$message.success('上传成功')
  227. _this.myAnswerList.imgList.push({
  228. name: file.name,
  229. url: data.Location,
  230. });
  231. _this.imgChange();
  232. console.log(data.Location);
  233. // _this.$message.success('上传成功'+data.Location)
  234. }
  235. });
  236. }
  237. },
  238. },
  239. mounted() {
  240. if (
  241. !this.myAnswerList1.engTitle &&
  242. !this.myAnswerList1.engText &&
  243. !this.myAnswerList1.imgList.length
  244. ) {
  245. this.myAnswerList = {
  246. engTitle: "",
  247. engText: "",
  248. imgList: [],
  249. };
  250. this.type = 0;
  251. } else {
  252. this.myAnswerList = JSON.parse(JSON.stringify(this.myAnswerList1));
  253. this.type = 1;
  254. }
  255. },
  256. };
  257. </script>
  258. <style scoped>
  259. .engBox {
  260. width: 90%;
  261. margin: 0 auto;
  262. }
  263. .engTitle,
  264. .engText {
  265. display: flex;
  266. flex-direction: row;
  267. flex-wrap: nowrap;
  268. align-items: flex-start;
  269. margin-bottom: 20px;
  270. }
  271. .engTitle > .div:first-child,
  272. .engText > div:first-child {
  273. min-width: 75px;
  274. }
  275. .chooseUpload {
  276. width: 100%;
  277. height: 300px;
  278. text-align: center;
  279. line-height: 300px;
  280. border: 1px dashed #c4c4c4;
  281. border-radius: 5px;
  282. margin-bottom: 20px;
  283. cursor: pointer;
  284. }
  285. .ftypeBox {
  286. margin: 20px auto 0;
  287. }
  288. .ftypeTitle {
  289. display: flex;
  290. flex-direction: row;
  291. flex-wrap: nowrap;
  292. align-items: center;
  293. }
  294. .ftypeTitle > div:first-child {
  295. min-width: 42px;
  296. font-weight: bold;
  297. }
  298. .ftypeTitle > div:last-child {
  299. width: calc(100% - 42px);
  300. }
  301. .ftypeText {
  302. display: flex;
  303. flex-direction: row;
  304. flex-wrap: nowrap;
  305. align-items: flex-start;
  306. margin-top: 20px;
  307. }
  308. .ftypeText > div:first-child {
  309. min-width: 42px;
  310. margin-top: 10px;
  311. font-weight: bold;
  312. }
  313. .ftypeText > div:last-child {
  314. width: 100%;
  315. }
  316. .upImg {
  317. width: 30px;
  318. height: 30px;
  319. float: right;
  320. cursor: pointer;
  321. }
  322. .upImg > img,
  323. .isUpImg > img,
  324. .deleteImg > img,
  325. .itemImg > img,
  326. .itemDeleteImg > img {
  327. width: 100%;
  328. height: 100%;
  329. }
  330. .chapter_add {
  331. width: 180px;
  332. margin: 0 auto;
  333. position: relative;
  334. text-align: center;
  335. }
  336. .up_photo2 {
  337. width: 180px;
  338. box-sizing: border-box;
  339. min-width: 180px;
  340. height: 180px;
  341. max-height: 180px;
  342. min-height: 180px;
  343. cursor: pointer;
  344. display: flex;
  345. flex-direction: column;
  346. align-items: center;
  347. justify-content: center;
  348. background: rgb(242, 246, 255);
  349. /* padding: 25px; */
  350. margin-bottom: 10px;
  351. }
  352. .up_photo2 img {
  353. width: 50%;
  354. height: auto;
  355. }
  356. .up_photo2 span {
  357. color: #898989;
  358. }
  359. .isUpImg {
  360. width: 180px;
  361. min-width: 180px;
  362. height: 180px;
  363. max-height: 180px;
  364. min-height: 180px;
  365. }
  366. .deleteImg {
  367. width: 20px;
  368. height: 20px;
  369. cursor: pointer;
  370. position: absolute;
  371. top: 0;
  372. right: 0;
  373. }
  374. .imgListCss {
  375. margin: 10px 0;
  376. }
  377. .itemImg {
  378. width: 50px;
  379. height: 50px;
  380. position: relative;
  381. }
  382. .itemDeleteImg {
  383. width: 15px;
  384. height: 15px;
  385. cursor: pointer;
  386. position: absolute;
  387. top: -5px;
  388. right: -5px;
  389. }
  390. /* table 样式 */
  391. .cont >>> table {
  392. border-top: 1px solid #ccc;
  393. border-left: 1px solid #ccc;
  394. }
  395. .cont >>> table td,
  396. .cont >>> table th {
  397. border-bottom: 1px solid #ccc;
  398. border-right: 1px solid #ccc;
  399. /* padding: 20px 5px; */
  400. padding: 5px 10px;
  401. max-width: 0px;
  402. height: 30px;
  403. vertical-align: baseline;
  404. box-sizing: border-box;
  405. }
  406. .cont >>> table th {
  407. border-bottom: 2px solid #ccc;
  408. text-align: center;
  409. }
  410. /* blockquote 样式 */
  411. .cont >>> blockquote {
  412. display: block;
  413. border-left: 8px solid #d0e5f2;
  414. padding: 5px 10px;
  415. margin: 10px 0;
  416. line-height: 1.4;
  417. font-size: 100%;
  418. background-color: #f1f1f1;
  419. }
  420. /* code 样式 */
  421. .cont >>> code {
  422. display: inline-block;
  423. /* *display: inline; */
  424. zoom: 1;
  425. background-color: #f1f1f1;
  426. border-radius: 3px;
  427. padding: 3px 5px;
  428. margin: 0 3px;
  429. }
  430. .cont >>> pre code {
  431. display: block;
  432. }
  433. /* ul ol 样式 */
  434. .cont >>> ul,
  435. ol {
  436. margin: 10px 0 10px 20px;
  437. }
  438. /* code 样式 */
  439. .cont {
  440. /* -webkit-user-modify: read-write; */
  441. overflow-wrap: break-word;
  442. -webkit-line-break: after-white-space;
  443. }
  444. </style>