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 7.6 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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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. $('.ui.info.message').text(res.Message).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. // $('.ui.positive.message').text('提交镜像成功').show().delay(1500).fadeOut();
  84. // }
  85. if(location.href.indexOf('imageAdmin')!==-1){
  86. location.href = `${window.config.AppSubUrl}/admin/images`
  87. }else{
  88. location.href = `${window.config.AppSubUrl}/explore/images?type=myimage`
  89. }
  90. }
  91. },
  92. error: function(xhr){
  93. // 隐藏 loading
  94. // 只有请求不正常(状态码不为200)才会执行
  95. // $('.ui.error.message').text(xhr.responseText)
  96. // $('.ui.error.message').css('display','block')
  97. $('.ui.negative.message').html(xhr.responseText).show().delay(1500).fadeOut();
  98. },
  99. complete:function(xhr){
  100. $("#mask").css({"display":"none","z-index":"1"})
  101. }
  102. })
  103. }
  104. $('.ui.create_image.green.button').click(()=>{
  105. let pattenTag = new RegExp(/^[A-Za-z0-9_.-]{1,100}[A-Za-z0-9_.]$/)
  106. if(!pattenTag.test($("input[name='tag']").val())){
  107. $("input[name='tag']").parent().addClass('error')
  108. return false
  109. }
  110. if(!$("textarea[name='description']").val()){
  111. $("textarea[name='description']").parent().addClass('error')
  112. return false
  113. }
  114. const postData = {
  115. _csrf:$("input[name='_csrf']").val(),
  116. tag:$("input[name='tag']").val(),
  117. description:$("textarea[name='description']").val(),
  118. type:$("input[name='type']").val(),
  119. isPrivate:$("input[name='isPrivate']:checked").val(),
  120. topics:$("input[name='topics']").val(),
  121. id:$("input[name='id']").val()
  122. }
  123. console.log(postData)
  124. let formData = $params(postData)
  125. console.log(formData)
  126. console.log()
  127. if($("input[name='edit']").val()=="edit"){
  128. postImage(formData)
  129. }
  130. else{
  131. $.ajax({
  132. url:link+'/check',
  133. type:'POST',
  134. data:formData,
  135. success:function(res){
  136. console.log("res",res)
  137. if(res.Code===1){
  138. $('.ui.modal.image_confirm_submit')
  139. .modal({
  140. onApprove: function() {
  141. postImage(formData)
  142. },
  143. })
  144. .modal('show')
  145. }else if(res.Code==0){
  146. postImage(formData)
  147. }
  148. },
  149. error: function(xhr){
  150. $('.ui.negative.message').text(xhr.responseText).show().delay(1500).fadeOut();
  151. }
  152. })
  153. }
  154. })
  155. $('#cancel_submit_image').click(()=>{
  156. if(link.includes('cloudbrain')){
  157. let repoLink = link.split('cloudbrain')[0]
  158. location.href = `${window.config.AppSubUrl}${repoLink}debugjob?debugListType=all`
  159. }else if(pageform=='imageSquare'){
  160. location.href = `${window.config.AppSubUrl}/explore/images?type=myimage`
  161. }else if(pageform=='imageAdmin'){
  162. location.href = `${window.config.AppSubUrl}/admin/images`
  163. }
  164. })
  165. console.log("initImage")
  166. function initVueImages() {
  167. const el = document.getElementById('images');
  168. console.log(el)
  169. if (!el) {
  170. return;
  171. }
  172. new Vue({
  173. el:el,
  174. render: h => h(Images)
  175. });
  176. }
  177. function initVueAdminImages() {
  178. const el = document.getElementById('images-admin');
  179. console.log(el)
  180. if (!el) {
  181. return;
  182. }
  183. new Vue({
  184. el:el,
  185. render: h => h(adminImages)
  186. });
  187. }
  188. function initVueselectImages() {
  189. const el = document.getElementById('images-new-cb');
  190. console.log(el)
  191. if (!el) {
  192. return;
  193. }
  194. new Vue({
  195. el:el,
  196. render: h => h(selectImages)
  197. });
  198. }
  199. initVueImages()
  200. initVueAdminImages()
  201. initVueselectImages()
  202. }