You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

images.js 8.0 kB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. import Images from '../components/images/Images.vue';
  2. import adminImages from '../components/images/adminImages.vue';
  3. import selectImages from '../components/images/selectImages.vue';
  4. import Vue from 'vue';
  5. export default async function initImage(){
  6. function validate() {
  7. $("#form_image")
  8. .form({
  9. on: 'blur',
  10. // inline:true,
  11. fields: {
  12. tag: {
  13. identifier : 'tag',
  14. rules: [
  15. {
  16. type: 'regExp[/^[A-Za-z0-9_.-]{1,100}[A-Za-z0-9_.]$/]',
  17. }
  18. ]
  19. },
  20. description:{
  21. identifier : 'description',
  22. rules: [
  23. {
  24. type: 'empty',
  25. }
  26. ]
  27. },
  28. }
  29. })
  30. }
  31. function $params(obj) {
  32. var str = [];
  33. for (var p in obj) {
  34. str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
  35. }
  36. return str.join("&");
  37. }
  38. function initDropdown(){
  39. $('#dropdown_image')
  40. .dropdown({
  41. allowAdditions: true,
  42. onChange: function(value, text, $selectedItem) {
  43. $('#course_label_item').empty()
  44. }
  45. })
  46. $('#dropdown_image input.search').bind('input propertychange', function (event) {
  47. // $("#dropdown_container").removeAttr("style");
  48. const query = $('input.search').val()
  49. if(!query){
  50. $('#course_label_item').empty()
  51. }else{
  52. $.get(`/api/v1/image/topics/search?q=${query}`,(data)=>{
  53. if(data.topics.length!==0){
  54. let html=''
  55. $('#course_label_item').empty()
  56. data.topics.forEach(element => {
  57. html += `<div class="item" data-value="${element.topic_name}">${element.topic_name}</div>`
  58. });
  59. $('#course_label_item').append(html)
  60. }
  61. })
  62. }
  63. });
  64. }
  65. validate()
  66. initDropdown()
  67. let link = $('.submit-image-tmplvalue').data('link')
  68. let pageform = $('.submit-image-tmplvalue').data('edit-page') || ''
  69. function postImage(formData) {
  70. $("#mask").css({"display":"block","z-index":"999"})
  71. $.ajax({
  72. url:link,
  73. type:'POST',
  74. data:formData,
  75. success:function(res){
  76. console.log("res",res)
  77. if(res.Code===1){
  78. $('.alert').html(res.Message).removeClass('alert-success').addClass('alert-danger').show().delay(1500).fadeOut();
  79. }else if(res.Code==0){
  80. if(link.indexOf('commit_image')===1){
  81. $('.ui.positive.message').text('保存镜像成功').show().delay(1500).fadeOut();
  82. }else{
  83. $('body')
  84. .toast({
  85. class: 'success',
  86. message: 'Did you notice any difference ?',
  87. transition: {
  88. showMethod : 'zoom',
  89. showDuration : 10000,
  90. hideMethod : 'fade',
  91. hideDuration : 10000
  92. }
  93. })
  94. }
  95. if(location.href.indexOf('imageAdmin')!==-1){
  96. location.href = `${window.config.AppSubUrl}/admin/images`
  97. }else{
  98. location.href = `${window.config.AppSubUrl}/explore/images?type=myimage`
  99. }
  100. }
  101. },
  102. error: function(xhr){
  103. // 隐藏 loading
  104. // 只有请求不正常(状态码不为200)才会执行
  105. // $('.ui.error.message').text(xhr.responseText)
  106. // $('.ui.error.message').css('display','block')
  107. $('.ui.positive.message').html(xhr.responseText).show().delay(1500).fadeOut();
  108. },
  109. complete:function(xhr){
  110. $("#mask").css({"display":"none","z-index":"1"})
  111. }
  112. })
  113. }
  114. $('.ui.create_image.green.button').click(()=>{
  115. let pattenTag = new RegExp(/^[A-Za-z0-9_.-]{1,100}[A-Za-z0-9_.]$/)
  116. if(!pattenTag.test($("input[name='tag']").val())){
  117. $("input[name='tag']").parent().addClass('error')
  118. return false
  119. }
  120. if(!$("textarea[name='description']").val()){
  121. $("textarea[name='description']").parent().addClass('error')
  122. return false
  123. }
  124. const postData = {
  125. _csrf:$("input[name='_csrf']").val(),
  126. tag:$("input[name='tag']").val(),
  127. description:$("textarea[name='description']").val(),
  128. type:$("input[name='type']").val(),
  129. isPrivate:$("input[name='isPrivate']:checked").val(),
  130. topics:$("input[name='topics']").val(),
  131. id:$("input[name='id']").val()
  132. }
  133. console.log(postData)
  134. let formData = $params(postData)
  135. console.log(formData)
  136. console.log()
  137. if($("input[name='edit']").val()=="edit"){
  138. postImage(formData)
  139. }
  140. else{
  141. $.ajax({
  142. url:link+'/check',
  143. type:'POST',
  144. data:formData,
  145. success:function(res){
  146. console.log("res",res)
  147. if(res.Code===1){
  148. $('.ui.modal.image_confirm_submit')
  149. .modal({
  150. onApprove: function() {
  151. postImage(formData)
  152. },
  153. })
  154. .modal('show')
  155. }else if(res.Code==0){
  156. postImage(formData)
  157. }
  158. },
  159. error: function(xhr){
  160. $('.ui.positive.message').text(xhr.responseText).show().delay(1500).fadeOut();
  161. }
  162. })
  163. }
  164. })
  165. $('#cancel_submit_image').click(()=>{
  166. if(link.includes('cloudbrain')){
  167. let repoLink = link.split('cloudbrain')[0]
  168. location.href = `${window.config.AppSubUrl}${repoLink}debugjob?debugListType=all`
  169. }else if(pageform=='imageSquare'){
  170. location.href = `${window.config.AppSubUrl}/explore/images?type=myimage`
  171. }else if(pageform=='imageAdmin'){
  172. location.href = `${window.config.AppSubUrl}/admin/images`
  173. }
  174. })
  175. console.log("initImage")
  176. function initVueImages() {
  177. const el = document.getElementById('images');
  178. console.log(el)
  179. if (!el) {
  180. return;
  181. }
  182. new Vue({
  183. el:el,
  184. render: h => h(Images)
  185. });
  186. }
  187. function initVueAdminImages() {
  188. const el = document.getElementById('images-admin');
  189. console.log(el)
  190. if (!el) {
  191. return;
  192. }
  193. new Vue({
  194. el:el,
  195. render: h => h(adminImages)
  196. });
  197. }
  198. function initVueselectImages() {
  199. const el = document.getElementById('images-new-cb');
  200. console.log(el)
  201. if (!el) {
  202. return;
  203. }
  204. new Vue({
  205. el:el,
  206. render: h => h(selectImages)
  207. });
  208. }
  209. initVueImages()
  210. initVueAdminImages()
  211. initVueselectImages()
  212. }