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