123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- var type = ''; //1下款爆料/2口子测评
- var qs = parseQueryString(window.location.href);
- $().ready(function() {
- if(qs.type) {
- type = qs.type;
- }
- // login();//登录获取权限
-
- //返回上一页
- $("#back").click(function(){
- history.go(-1)
- })
-
- //发布点击事件
- $('#release').click(function(){
- var title = $('.title').val();
- var content = $('.content').val();
- if(title == '' && content == '' ){
- showMsg('请输入标题和内容再发布')
- return;
- }else if(title == ''){
- showMsg('请输入标题再发布')
- return;
- }else if(content == ''){
- showMsg('请输入内容再发布')
- return;
- }
- releas(title,content,type)
- })
-
- // $("#image").change(function () {
- // console.log($("#image")[0].files);
- // $(".img").attr('src',($("#image")[0].files)[0].name)
- // });
- })
- //登录获取权限
- function login(){
- $.ajax({
- type: "post",
- url: "/user/user/login",
- data:{
- phone : '13612345678',
- password : '123456'
- },
- success:function(res){
- console.log(res)
- console.log('登录成功')
- },
- error:function(err){
- console.log(err)
- }
- })
- }
- //发布内容
- function releas(title,content,type){
- $.ajax({
- type: "post",
- url: "/user/huaJiangHu/addPost",
- data:{
- type : type,
- title : title,
- content : content
- },
- success:function(res){
- if(res.rst && res.errno == '0'){
- showMsg('发布成功已提交后台审核')
- setTimeout(function() {
- if(type == 1){
- window.location.href ="burst.html?title=下款爆料"
- }else if(type == 2){
- window.location.href ="burst.html?title=口子测评"
- }
- }, 2000);
- }else{
- showMsg('发布失败')
- }
-
- },
- error:function(err){
- console.log(err)
- }
- })
- }
- //获取地址栏参数
- function parseQueryString(url) {
- var urlObj = {};
- var reg = /([^?=&]+)=([^?=&]+)/g;
- url.replace(reg, ($0, $1, $2) => {
- urlObj[$1] = decodeURIComponent($2);
- })
- return urlObj;
- }
- //提示信息
- function showMsg(msg) {
- var msg = msg;
- var msgBox = $('.alert-info');
- msgBox.children('p').text(msg);
- msgBox.show();
- // setTimeout(function() {
- // msgBox.hide();
- // }, 2000);
- }
- //读取文件
- function loadImg(){
- //获取文件
- var file = $("#image").find("input")[0].files[0];
-
- //创建读取文件的对象
- var reader = new FileReader();
-
- //创建文件读取相关的变量
- var imgFile;
-
- //为文件读取成功设置事件
- reader.onload=function(e) {
- alert('文件读取完成');
- imgFile = e.target.result;
- console.log(imgFile);
- $("#imgContent").attr('src', imgFile);
- };
-
- //正式读取文件
- reader.readAsDataURL(file);
- }
|