index0.html 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. <!DOCTYPE html>
  2. <html lang="zh">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  7. <script src="https://unpkg.com/vue@2.6.14/dist/vue.js"></script>
  8. <script type="text/javascript" async
  9. src="https://mingxuejingbang.oss-cn-beijing.aliyuncs.com/MathJaxFiles/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML"></script>
  10. <script type="text/javascript" async src="js/globalVariable.js"></script>
  11. <script type="text/javascript" async src="js/html2canvas.min.js"></script>
  12. <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
  13. <script src="https://unpkg.com/element-ui/lib/index.js"></script>
  14. <script src="https://cdn.staticfile.org/axios/0.18.0/axios.min.js"></script>
  15. <title></title>
  16. <style>
  17. html, body {
  18. margin: 0;
  19. padding: 0
  20. }
  21. .el-radio--medium.is-bordered {
  22. height: auto;
  23. padding-bottom: 8px;
  24. }
  25. #title::after {
  26. display: table;
  27. content: "";
  28. clear: both;
  29. }
  30. </style>
  31. </head>
  32. <body>
  33. <div id="app">
  34. <div style="min-height:300px;">
  35. <div id="title" style="background:#fff; max-width:1024px">
  36. <div style=";padding-top:10px;padding-left:10px">
  37. <div style="padding-bottom: 15px" v-html="data.title"></div>
  38. <div v-for="(itemOpt, idx) in data.options" :key="idx">
  39. <el-radio
  40. style="margin-bottom: 15px"
  41. :label="selectOpt[idx]"
  42. border
  43. size="medium">
  44. {{ selectOpt[idx] + ' 、 ' }}<span style="white-space: normal" v-html="itemOpt"></span>
  45. </el-radio>
  46. </div>
  47. <div style="height:15px"></div>
  48. </div>
  49. </div>
  50. </div>
  51. <div style="margin-bottom:20px;padding: 15px;background: rgb(255, 255, 255); max-width: 1024px;">
  52. <el-input v-model="questionId" style="width: 150px;" placeholder="请输入题目编号"></el-input>
  53. <el-button type="primary" :disabled="isAuto" @click="search">搜索</el-button>
  54. <el-button type="primary" :disabled="isAuto" @click="upLoad">手动上传</el-button>
  55. <el-button type="primary" @click="auto">{{ isAuto ? '暂停' : '自动运行' }}</el-button>
  56. </div>
  57. <div v-if="imgUri" style="margin-top:30px;padding: 15px;background: rgb(255, 255, 255); max-width: 1024px;">
  58. 图片展示:
  59. <img :src="imgUri" alt="" crossorigin="anonymous">
  60. </div>
  61. </div>
  62. <script>
  63. var exampleData = {
  64. selectOpt: ['A', 'B', 'C', 'D', 'E', 'F', 'G'],
  65. data: {},
  66. time: null,
  67. domain: '',
  68. isAuto: false,
  69. questionId: '',
  70. imgUri: ''
  71. }
  72. // window.onload = function(){
  73. new Vue({
  74. el: '#app',
  75. data: exampleData,
  76. created() {
  77. // if(this.domain == 'localhost:9800'){
  78. this.domain = 'https://front.mingxuejinbang.com'
  79. window.myVue = this
  80. // }
  81. // this.getData()
  82. },
  83. methods: {
  84. search() {
  85. if (this.questionId) {
  86. this.getData(this.questionId)
  87. } else {
  88. this.$message({
  89. message: '请输入题目编号',
  90. type: 'warning'
  91. })
  92. }
  93. },
  94. auto() {
  95. this.isAuto = !this.isAuto
  96. if (this.isAuto) {
  97. this.getData()
  98. }
  99. },
  100. upLoad() {
  101. if (this.questionId && this.imgUri) {
  102. this.uploadQuestionImage(this.imgUri, 1)
  103. } else {
  104. this.$message({
  105. message: '请先搜索题目',
  106. type: 'warning'
  107. })
  108. }
  109. },
  110. getData(questionId) {
  111. axios.defaults.withCredentials = true
  112. let str = ''
  113. if (questionId) {
  114. str = '?questionId=' + questionId
  115. }
  116. axios.get(this.domain + '/prod-api/front/questionCollection/getNextQuestionForImageGenerate' + str).then(response => {
  117. if (response.data.code == 200) {
  118. this.data = response.data.data
  119. this.$nextTick(() => {
  120. this.MathQueueTitle(str)
  121. })
  122. } else {
  123. this.isAuto = false
  124. this.$message({
  125. message: '获取题目信息失败',
  126. type: 'warning'
  127. })
  128. }
  129. }).catch(function(error) { // 请求失败处理
  130. this.isAuto = false
  131. this.$message.error('网络请求异常!')
  132. })
  133. },
  134. uploadQuestionImage(src, type) {
  135. axios.defaults.withCredentials = true
  136. var formData = new FormData()
  137. formData.append('questionId', this.data.questionId)
  138. formData.append('imageBase64', src)
  139. if (this.isAuto == false) {
  140. formData.append('manual', true)
  141. }
  142. axios.post(this.domain + '/prod-api/front/questionCollection/uploadQuestionImage', formData).then(response => {
  143. console.log(response)
  144. if (response.data.code == 200) {
  145. if (this.isAuto) {
  146. this.getData()
  147. }
  148. if (type) {
  149. this.$message({
  150. message: '上传题目信息成功!',
  151. type: 'success'
  152. })
  153. }
  154. } else {
  155. this.isAuto = false
  156. this.$message({
  157. message: '上传题目信息失败!',
  158. type: 'warning'
  159. })
  160. }
  161. }).catch(function(error) { // 请求失败处理
  162. this.isAuto = false
  163. this.$message.error('网络请求异常!')
  164. })
  165. },
  166. getCookie(str) {//获取cookie
  167. let cookie = document.cookie.split('; ')
  168. let cookies = {}
  169. cookie.forEach(item => {
  170. cookies[item.split('=')[0]] = item.split('=')[1]
  171. })
  172. return cookies[str]
  173. },
  174. MathQueueTitle(str) {//初始化公式
  175. if (MathQueue) {
  176. clearInterval(this.time)
  177. MathQueue('title')
  178. setTimeout(() => { //
  179. this.$nextTick(() => {
  180. this.downLoad(str)
  181. })
  182. }, 1000)
  183. } else {
  184. this.time = setInterval(() => {
  185. this.MathQueueTitle()
  186. }, 5)
  187. }
  188. },
  189. downLoad(type) {
  190. if (!this.data.questionId) {
  191. this.$message({
  192. message: '请先搜索题目!',
  193. type: 'warning'
  194. })
  195. return
  196. }
  197. this.questionId=this.data.questionId
  198. const times = 2 // 图片放大倍数,能提升清晰度
  199. let _this = this
  200. _this.imgUri = ''
  201. let canvas2 = document.createElement('canvas')
  202. let _canvas = document.getElementById('title')
  203. let w = parseInt(window.getComputedStyle(_canvas).width)
  204. let h = parseInt(window.getComputedStyle(_canvas).height)
  205. canvas2.width = times * w
  206. canvas2.height = times * h
  207. canvas2.style.width = times * w + 'px'
  208. canvas2.style.height = times * h + 'px'
  209. let context = canvas2.getContext('2d')
  210. context.scale(times, times) ///缩放等级
  211. html2canvas(document.getElementById('title'), {
  212. canvas: canvas2,
  213. useCORS: true
  214. //allowTaint: false,
  215. }).then(function(canvas) {
  216. let imgUri = canvas.toDataURL('image/jpeg', 2) // 获取生成的图片的url
  217. _this.imgUri = imgUri
  218. // if (!type) {
  219. _this.uploadQuestionImage(imgUri)
  220. // }
  221. })
  222. }
  223. }
  224. })
  225. // }
  226. </script>
  227. </body>
  228. </html>