index.html 7.4 KB

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