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