No Description

release.js 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. var type = ''; //1下款爆料/2口子测评
  2. var qs = parseQueryString(window.location.href);
  3. $().ready(function() {
  4. if(qs.type) {
  5. type = qs.type;
  6. }
  7. // login();//登录获取权限
  8. //返回上一页
  9. $("#back").click(function(){
  10. history.go(-1)
  11. })
  12. //发布点击事件
  13. $('#release').click(function(){
  14. var title = $('.title').val();
  15. var content = $('.content').val();
  16. if(title == '' && content == '' ){
  17. showMsg('请输入标题和内容再发布')
  18. return;
  19. }else if(title == ''){
  20. showMsg('请输入标题再发布')
  21. return;
  22. }else if(content == ''){
  23. showMsg('请输入内容再发布')
  24. return;
  25. }
  26. releas(title,content,type)
  27. })
  28. // $("#image").change(function () {
  29. // console.log($("#image")[0].files);
  30. // $(".img").attr('src',($("#image")[0].files)[0].name)
  31. // });
  32. })
  33. //登录获取权限
  34. function login(){
  35. $.ajax({
  36. type: "post",
  37. url: "/user/user/login",
  38. data:{
  39. phone : '13612345678',
  40. password : '123456'
  41. },
  42. success:function(res){
  43. console.log(res)
  44. console.log('登录成功')
  45. },
  46. error:function(err){
  47. console.log(err)
  48. }
  49. })
  50. }
  51. //发布内容
  52. function releas(title,content,type){
  53. $.ajax({
  54. type: "post",
  55. url: "/user/huaJiangHu/addPost",
  56. data:{
  57. type : type,
  58. title : title,
  59. content : content
  60. },
  61. success:function(res){
  62. if(res.rst && res.errno == '0'){
  63. showMsg('发布成功已提交后台审核')
  64. setTimeout(function() {
  65. if(type == 1){
  66. window.location.href ="burst.html?title=下款爆料"
  67. }else if(type == 2){
  68. window.location.href ="burst.html?title=口子测评"
  69. }
  70. }, 2000);
  71. }else{
  72. showMsg('发布失败')
  73. }
  74. },
  75. error:function(err){
  76. console.log(err)
  77. }
  78. })
  79. }
  80. //获取地址栏参数
  81. function parseQueryString(url) {
  82. var urlObj = {};
  83. var reg = /([^?=&]+)=([^?=&]+)/g;
  84. url.replace(reg, ($0, $1, $2) => {
  85. urlObj[$1] = decodeURIComponent($2);
  86. })
  87. return urlObj;
  88. }
  89. //提示信息
  90. function showMsg(msg) {
  91. var msg = msg;
  92. var msgBox = $('.alert-info');
  93. msgBox.children('p').text(msg);
  94. msgBox.show();
  95. // setTimeout(function() {
  96. // msgBox.hide();
  97. // }, 2000);
  98. }
  99. //读取文件
  100. function loadImg(){
  101. //获取文件
  102. var file = $("#image").find("input")[0].files[0];
  103. //创建读取文件的对象
  104. var reader = new FileReader();
  105. //创建文件读取相关的变量
  106. var imgFile;
  107. //为文件读取成功设置事件
  108. reader.onload=function(e) {
  109. alert('文件读取完成');
  110. imgFile = e.target.result;
  111. console.log(imgFile);
  112. $("#imgContent").attr('src', imgFile);
  113. };
  114. //正式读取文件
  115. reader.readAsDataURL(file);
  116. }