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