加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 资源网站 > 资源 > 正文

微信小程序项目-你是什么垃圾?

发布时间:2020-12-14 19:09:13 所属栏目:资源 来源:网络整理
导读:垃圾分类特别火也不知道北京什么时候也开始执行,看见之前上海市民被灵魂拷问了以后垃圾真的不知道如何丢了,作为程序员就做一个小程序造福人类吧。 效果图: 一、全局的app.json和app.wxss加入了一点东西 App.json { "pages" : [ "pages/index/index" , "pa

垃圾分类特别火也不知道北京什么时候也开始执行,看见之前上海市民被灵魂拷问了以后垃圾真的不知道如何丢了,作为程序员就做一个小程序造福人类吧。

效果图:

一、全局的app.json和app.wxss加入了一点东西

App.json

{
  "pages": [
    "pages/index/index","pages/details/details",0);">"pages/logs/logs"
    
  ],"window": {
    "backgroundTextStyle": "light","navigationBarBackgroundColor": "#fff","navigationBarTitleText": "WeChat","navigationBarTextStyle": "white","navigationStyle": "custom"
  },"sitemapLocation": "sitemap.json"
  
}

App.wxss

.bg{
  position: absolute;
  left:0;
  top:width:100%;
  height: 100%;
}

二、下面就是首页的index.wxml、index.js、 index.wxss

index.wxml

<image class='bg' src='../img/bg.png'></image>

<view class='container'>
    <'top'>
        <text class='top-title'>你是什么垃圾</text>
        <'top-more'>一键查询免烦恼,从我做起爱环保</text>
    </view> 

    <'search'>
       <'search-main'>
         <icon type='search' size='16'></icon>
         <input 
         placeholder="请输入查询的垃圾名称"
         bindinput='iptDetails'
         bindconfirm="search"
         ></input>
       </view>

        <'search-end' wx:if='{{searchResultDatas.length > 0}}'>
          <text 
          wx:for={{searchResultDatas}}'
          wx:key={{index}}'
          bindtap='toDetails'
          data-title={{item.itemName}}'
          >{{item.itemName}}</text>
        </view>
    </view>

    <'hot'>
        <'hot-main'>
          <'hot-title'>热门搜索:</view>
          <'hot-item'>

              <text 
                wx:for={{hotSearch}}'
                wx:key=}'
                bindtap='toDetails'
                data-title=}'
              >text>
             
          </view>
        </view>

</view>

index.js

Page({

  /**
   * 页面的初始数据
   */
  data: {
    hotSearch:[],searchResultDatas:[]
  },/**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
      let That = this;
      wx.request({
        url: 'http://apis.juhe.cn/rubbish/hotSearch',data:{
          key: 'ae200d60495f41dfb86da332dc059214',},success(res){
          That.setData({
            hotSearch: res.data.result
          })
        }
      })
    
  },toDetails(e){
    let title = e.currentTarget.dataset.title;
    wx.navigateTo({
      url: `../details/details?id=${title}`
    })
  },iptDetails(e){
    this;
    let val = e.detail.value;
    if(val.length == 0){
      this.setData({
        searchResultDatas: []
      })
      return;
    }
    
    wx.request({
      url: 'http://apis.juhe.cn/rubbish/search',data:{
        key:"ae200d60495f41dfb86da332dc059214",q: val
      },success(res){
        That.setData({
          searchResultDatas: res.data.result
        })
      }
    })
  },136);">/**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },136);">/**
   * 生命周期函数--监听页面显示
   */
  onShow: /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    
  }
})

index.wxss

三、下面就是详情页details.wxml、details.js、details.wxss

details.wxml

>
    <"end">
       <'name'>text>
       <'attr'>属性“{{item.itemCategory}}”</'details-more'>

       <'more-title'>
        {{item.itemCategory}}投放指导
       </view>

       <'more-title'>
           <text>·尽量沥干水分</text>
           <text>·难以辨别的生活垃圾应投入垃圾容器内</text>·餐巾纸、纸巾、纸尿裤等其他垃圾</text>
       </view>

    </button bindtap='toHome'>关闭</button>
    
</// pages/details/details.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    item:[]
  },51); font-weight: 700;">function (options) {
    let itemName = options.id;
    this;
    wx.request({
      url: data:{
        key: q: itemName,type:2
      },success(res){
        That.setData({
          item: res.data.result[0]
        })
      }
    })
  },toHome(){
    // wx.navigateTo({
    //   url: '../index/index',
    // })
    wx.navigateBack()
  },51); font-weight: 700;">function () {

  },51); font-weight: 700;">function () {

  }
})