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