public.jsvargraceJS=require('../../utils/grace.js');import{config}from'../../config.js'Page({/***页面初始数据*/data:{imglist:[],title:'',content:'',},delImg(e){letindex=e.currentTarget.dataset.index;letarray=[];console.log(index);for(vari=0;i=0){graceJS.msg(res.data);}else{graceJS.msg("上传成功");vararray=that.data.imglist.concat(res.data)that.setData({imglist:array,})}}}})}})},zf_title:function(e){this.setData({title:e.detail.value})},zf_content:function(e){this.setData({content:e.detail.value})},tj_info:function(event){varthat=this;console.log("event",event)vartitle=this.data.title;varcontent=this.data.content;console.log(标题)console.log(内容)varimglist=that.data.imglist;varuid=wx.getStorageSync('user').idif(!title&&!content){graceJS.msg("请填写完整");}else{//写入数据库if(uid!=undefined){graceJS.post(config.api_base_url+'tiezi_add',{title:title,content:content,uid:uid,imglist:imglist},'json',{},//这里的{}表示不设置头数据function(res){if(res.result==1){graceJS.msg(res.msg);setTimeout(()=>{graceJS.navigate('../discover/discover','switchTab');},2000)}else{graceJS.msg(res.msg);}});}else{graceJS.msg("用户ID获取失败");}}},/***生命周期函数--监听页面加载*/onLoad:function(options){},/***生命周期函数--监听页面第一次渲染完成*/onReady:function(){},/***生命周期函数--监控页面显示*/onShow:function(){},/***生命周期函数--监控页面隐藏*/onHide:function(){},/***生命周期函数--监控页面卸载*/onUnload:function(){},/***页面相关事件处理函数--监听用户下拉动作*/onPullDownRefresh:function(){},/***页面下拉的处理函数event*/onReachBottom:function(){},/***用户点击右上角分享*/onShareAppMessage:function(){}})publish.wxmlX发布帖子publish.wxss/*pages/publish/publish.wxss*/page{padding-bottom:120rpx;}.publish_a{padding:20rpx;}.publish_a1{background-颜色:#f5f2f4;填充:20rpx;}.publish_a1_a输入{宽度:100%;高度:80rpx;行高:80rpx;字体大小:28rpx;字体粗细:粗体;}.publish_a1_btextarea{宽度:100%;font-size:28rpx;}.publish_a1_c1{margin-bottom:20rpx;}.publish_a1_c1image{显示:块;宽度:200rpx;高度:200rpx;}.publish_a1_c2{显示:flex;flex-wrap:wrap;}.publish_a1_c2view{position:relative;宽度:200rpx;高度:200rpx;右边距:20rpx;margin-bottom:20rpx;}.publish_a1_c2image{显示:块;宽度:100%;高度:100%;}.publish_a1_c2文本{显示:块;位置:绝对;右:0;顶部:0;宽度:40rpx;高度:40rpx;文本对齐:居中;行高:40rpx;字体大小:26rpx;颜色:#fff;背景颜色:rgba(0,0,0,0.3);}.zf_btn{宽度:500px;}.publish_b{位置:固定;左:0;底部:0;/*宽度:100%;*/背景颜色:#a67f4a;行高:100rpx;文本对齐:居中;颜色:#fff;字体大小:30rpx;最小宽度:380px;宽度:100%;填充:0;margin:0;}tp引入useEasyWeChat\Factory;publicfunction__construct(Request$request=null){$this->config=['app_id'=>'wx4**********fd45a65','secret'=>'082dec1****5b93d286c093e01','response_type'=>'array','log'=>['level'=>'调试','文件'=>__DIR__.'/log/wechat.log',],];$this->uid='';}publicfunctiontiezi_add(){$data=input('post.');if($data['imglist']!=[]){foreach($data['imglist']as$k=>$vo){$data['imglist'][$k]=trim($vo);}$data['album']=trim(内爆(',',$data['imglist']));}未设置($data['imglist']);$数据['cid']=17;$数据['状态']=1;$数据['排序']=0;$data['ctime']=时间();if(!isset($data['album'])){returnjserror('至少上传一张图片');}//验证$miniProgram=Factory::miniProgram($this->config);$result=$miniProgram->content_security->checkText($data['content']);$result2=$miniProgram->content_security->checkText($data['title']);if($result['errcode']!='0'){returnjserror('包含非法关键字');}if($result2['errcode']!='0'){returnjserror('包含非法关键字');}//保存$res=Db::name('post')->insert($data);if($res){returnjssuccess('发布成功');}else{returnjserror('发布失败');}}publicfunctionupload_pic(){$file=request()->file('file');$info=$file->validate(['ext'=>config()['web']['file_ext']])->move('./public/upload/admin/file');$getSaveName=str_replace('\\','/',$info->getSaveName());//把win下的反斜杠换成斜杠$msg='http://'.$_SERVER['SERVER_NAME'].'/public/upload/admin/file/'.$getSaveName;if(is_file('./public/upload/admin/file/'.$getSaveName)){//验证图片$miniProgram=Factory::miniProgram($this->config);$result=$miniProgram->content_security->checkImage('./public/upload/admin/file/'.$getSaveName);if($result['errcode']!='0'){return'非法图片';}else{返回$msg;}#################}else{返回'0';价值后台管理系统免费使用###紫峰后台管理系统###,可直接在宝塔面板安装欢迎关注公众号:紫峰的精彩世界,获取独家学习资源和每日干货推送如果您对我的其他专题内容感兴趣,请直接访问我的个人博客:www.wangmingchang.com。