Commit 4828263e authored by dongjie's avatar dongjie

这是我小程序demo编写

parent d15084d2
# interview
自助面试
\ No newline at end of file
//app.js
App({
onLaunch: function () {
// 展示本地存储能力
var logs = wx.getStorageSync('logs') || []
logs.unshift(Date.now())
wx.setStorageSync('logs', logs)
// 登录
wx.login({
success: res => {
// 发送 res.code 到后台换取 openId, sessionKey, unionId
}
})
// 获取用户信息
wx.getSetting({
success: res => {
if (res.authSetting['scope.userInfo']) {
// 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
wx.getUserInfo({
success: res => {
// 可以将 res 发送给后台解码出 unionId
this.globalData.userInfo = res.userInfo
// 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
// 所以此处加入 callback 以防止这种情况
if (this.userInfoReadyCallback) {
this.userInfoReadyCallback(res)
}
}
})
}
}
})
},
globalData: {
userInfo: null
}
})
\ No newline at end of file
{
"pages": [
"pages/list/list",
"pages/shuju/shuju",
"pages/news/news",
"pages/index/index",
"pages/logs/logs",
"pages/inland/inland",
"pages/international/international",
"pages/history/history",
"pages/demo/demo"
],
"window": {
"backgroundTextStyle": "light",
"navigationBarBackgroundColor": "#fff",
"navigationBarTitleText": "今日头条",
"navigationBarTextStyle": "black"
},
"style": "v2",
"sitemapLocation": "sitemap.json",
"tabBar": {
"list": [
{
"pagePath": "pages/index/index",
"iconPath": "/pages/images/index.png",
"selectedIconPath": "/pages/images/index-S.png",
"text": "首页"
},
{
"pagePath": "pages/news/news",
"iconPath": "/pages/images/news.png",
"selectedIconPath": "/pages/images/news-S.png",
"text": "消息"
},
{
"pagePath": "pages/shuju/shuju",
"iconPath": "/pages/images/shuju.png",
"selectedIconPath": "/pages/images/shuju-S.png",
"text": "数据"
},
{
"pagePath": "pages/list/list",
"iconPath": "/pages/images/list.png",
"selectedIconPath": "/pages/images/list-S.png",
"text": "列表"
}
]
}
}
\ No newline at end of file
/**app.wxss**/
.container {
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-between;
padding: 200rpx 0;
box-sizing: border-box;
}
Page({
/**
* 页面的初始数据
*/
data: {
iconSize: [20, 30, 40, 50, 60, 70],
iconColor: [
'red', 'orange', 'yellow', 'green', 'rgb(0,255,255)', 'blue', 'purple'
],
iconType: [
'success', 'success_no_circle', 'info', 'warn', 'waiting', 'cancel', 'download', 'search', 'clear'
]
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function(options) {
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function() {
}
})
\ No newline at end of file
{
"usingComponents": {}
}
\ No newline at end of file
<view class="progress-box">
<progress percent="20" show-info stroke-width="3"/>
</view>
<view class="progress-box">
<progress percent="40" active stroke-width="3" style="width: 60%;"/>
<icon class="progress-cancel" type="cancel"></icon>
</view>
<view class="progress-box">
<progress percent="60" active stroke-width="3" />
</view>
<view class="progress-box">
<progress percent="80" color="#10AEFF" active stroke-width="3" />
</view>
view {
margin: 10px 0;
}
\ No newline at end of file
// pages/history/history.js
Page({
/**
* 页面的初始数据
*/
data: {
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})
\ No newline at end of file
{
"usingComponents": {}
}
\ No newline at end of file
<!--pages/history/history.wxml-->
<text>pages/history/history.wxml</text>
/* pages/history/history.wxss */
\ No newline at end of file
//index.js
//获取应用实例
const app = getApp()
Page({
data: {
motto: 'Hello World',
userInfo: {},
hasUserInfo: false,
canIUse: wx.canIUse('button.open-type.getUserInfo')
},
//事件处理函数
bindViewTap: function() {
wx.navigateTo({
url: '../logs/logs'
})
},
onLoad: function () {
if (app.globalData.userInfo) {
this.setData({
userInfo: app.globalData.userInfo,
hasUserInfo: true
})
} else if (this.data.canIUse){
// 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
// 所以此处加入 callback 以防止这种情况
app.userInfoReadyCallback = res => {
this.setData({
userInfo: res.userInfo,
hasUserInfo: true
})
}
} else {
// 在没有 open-type=getUserInfo 版本的兼容处理
wx.getUserInfo({
success: res => {
app.globalData.userInfo = res.userInfo
this.setData({
userInfo: res.userInfo,
hasUserInfo: true
})
}
})
}
},
getUserInfo: function(e) {
console.log(e)
app.globalData.userInfo = e.detail.userInfo
this.setData({
userInfo: e.detail.userInfo,
hasUserInfo: true
})
}
})
{
"usingComponents": {}
}
\ No newline at end of file
<!--index.wxml-->
<view class="container">
<view class="userinfo">
<button wx:if="{{!hasUserInfo && canIUse}}" open-type="getUserInfo" bindgetuserinfo="getUserInfo"> 获取头像昵称 </button>
<block wx:else>
<image bindtap="bindViewTap" class="userinfo-avatar" src="{{userInfo.avatarUrl}}" mode="cover"></image>
<text class="userinfo-nickname">{{userInfo.nickName}}</text>
</block>
</view>
<view class="usermotto">
<text class="user-motto">{{motto}}</text>
</view>
</view>
/**index.wxss**/
.userinfo {
display: flex;
flex-direction: column;
align-items: center;
}
.userinfo-avatar {
width: 128rpx;
height: 128rpx;
margin: 20rpx;
border-radius: 50%;
}
.userinfo-nickname {
color: #aaa;
}
.usermotto {
margin-top: 200px;
}
\ No newline at end of file
// pages/inland/inland.js
Page({
/**
* 页面的初始数据
*/
data: {
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})
\ No newline at end of file
{
"usingComponents": {}
}
\ No newline at end of file
<!--pages/inland/inland.wxml-->
<text>pages/inland/inland.wxml</text>
/* pages/inland/inland.wxss */
\ No newline at end of file
// pages/international/international.js
Page({
/**
* 页面的初始数据
*/
data: {
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})
\ No newline at end of file
{
"usingComponents": {}
}
\ No newline at end of file
<!--pages/international/international.wxml-->
<text>pages/international/international.wxml</text>
/* pages/international/international.wxss */
\ No newline at end of file
var mth = 10;
// require只能使用相对路径
var txt = require("./txt.wxs")
module.exports = {
mth: mth,
txt: txt.txt
}
\ No newline at end of file
// pages/list/list.js
Page({
/**
* 页面的初始数据
*/
data: {
current: 0,
nav:[
{
id: 0,
name: '国内',
con: 'guonei'
}, {
id: 1,
name: '国际',
con: 'guoji'
}, {
id: 2,
name: '历史',
con: 'lishi'
}
],
newsobj: {
guoji: [
{
id: 0,
title: '威廉·凯林等3人获诺贝尔生理学或医学奖分享647万',
desTitle: '专题',
desTime: '5小时',
src: 'https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=739779916,2608795784&fm=26&gp=0.jpg'
},
{
id: 1,
title: '威廉·凯林等3人获诺贝尔生理学或医学奖分享647万',
desTitle: '专题',
desTime: '5小时',
src: 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1607830260788&di=9951570100b316ffc84bcb4fcc6868c6&imgtype=0&src=http%3A%2F%2Finews.gtimg.com%2Fnewsapp_match%2F0%2F10618421117%2F0.jpg'
},
{
id: 2,
title: '威廉·凯林等3人获诺贝尔生理学或医学奖分享647万',
desTitle: '专题',
desTime: '5小时',
src: 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1607830290759&di=0cb27aa6b9aea8f5893f7f948f07f3a5&imgtype=0&src=http%3A%2F%2Fimg4.imgtn.bdimg.com%2Fit%2Fu%3D36252859%2C227563765%26fm%3D214%26gp%3D0.jpg'
}
],
guonei: [
{
id: 0,
title: '威廉·凯林等3人获诺贝尔生理学或医学奖分享647万',
desTitle: '专题',
desTime: '5小时',
src: 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1607830260786&di=8458771255ba9b4e3a49d9442be8a91d&imgtype=0&src=http%3A%2F%2Fb-ssl.duitang.com%2Fuploads%2Fitem%2F201602%2F12%2F20160212164547_BzjKv.jpeg'
},
{
id: 1,
title: '威廉·凯林等3人获诺贝尔生理学或医学奖分享647万',
desTitle: '专题',
desTime: '5小时',
src: 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1607830260784&di=6a53b2dbbd51ff0552c078e1bcdd8780&imgtype=0&src=http%3A%2F%2Fb.hiphotos.baidu.com%2Fzhidao%2Fpic%2Fitem%2F203fb80e7bec54e7bf22d925b8389b504fc26a3b.jpg'
},
{
id: 2,
title: '威廉·凯林等3人获诺贝尔生理学或医学奖分享647万',
desTitle: '专题',
desTime: '5小时',
src: 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1607830260783&di=50f747d93d9f4206a81e247398399ca7&imgtype=0&src=http%3A%2F%2Fc-ssl.duitang.com%2Fuploads%2Fitem%2F201611%2F30%2F20161130181234_PzFN8.jpeg'
}
],
lishi: [
{
id: 0,
title: '威廉·凯林等3人获诺贝尔生理学或医学奖分享647万',
desTitle: '专题',
desTime: '5小时',
src: 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1607830260782&di=e54609406db4d3c4f681b252f737d763&imgtype=0&src=http%3A%2F%2Fimages.h128.com%2Fupload%2F201907%2F14%2F201907140015304324.jpg%3Fx-oss-process%3Dimage%2Fresize%2Cm_lfit%2Cw_1421%2Fquality%2Cq_100%2Fformat%2Cjpg'
},
{
id: 1,
title: '威廉·凯林等3人获诺贝尔生理学或医学奖分享647万',
desTitle: '专题',
desTime: '5小时',
src: 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1607830260779&di=a95d1243d091f820eae141cced843b00&imgtype=0&src=http%3A%2F%2Fb-ssl.duitang.com%2Fuploads%2Fitem%2F201805%2F24%2F20180524221828_ofqud.jpg'
},
{
id: 2,
title: '威廉·凯林等3人获诺贝尔生理学或医学奖分享647万',
desTitle: '专题',
desTime: '5小时',
src: 'https://pic2.zhimg.com/v2-87498c75c1d2917a391bfb6af70357fb_1440w.jpg'
}
],
},
list: [],
task: [
{
id: 10,
course: "微信小程序开发"
}, {
id: 11,
course: "uni-app框架跨平台开发"
}, {
id: 12,
course: "flutter双平台开发框架"
}
],
learn: {}
},
handleClick: function(e) {
const {currenttab, con} = e.currentTarget.dataset;
const {newsobj} = this.data;
this.setData({
current: currenttab,
list: newsobj[con]
})
},
learn(n = 10) {
const {task} = this.data;
return task.find(item => item.id == n)
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
const { newsobj } = this.data;
const learn = this.learn();
this.setData({
list: newsobj['guonei'],
learn: learn
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})
\ No newline at end of file
{
"usingComponents": {}
}
\ No newline at end of file
<!--pages/list/list.wxml-->
<view class="nav">
<view wx:for="{{nav}}" wx:key="*this" class="{{current == index ? 'handleStyle' : ''}}" bindtap="handleClick" data-currentTab="{{index}}" data-con="{{item.con}}">{{item.name}}</view>
</view>
<import src="/template/template.wxml" />
<view>
<template is="tpl" data="{{news: list}}"></template>
</view>
<view>学习目标有:</view>
<view class="course">
<text wx:for="{{task}}" wx:key="*this">{{item.course}}</text>
</view>
<view>十二月份学习: {{learn.course}}</view>
<wxs module="learning">
var task = [{
id: 10,
course: "微信小程序开发"
}, {
id: 11,
course: "uni-app框架跨平台开发"
}, {
id: 12,
course: "flutter双平台开发框架"
}]
var learn = function(n) {
var course = "";
task.forEach(function(item,index) {
if( item.id == n) {
course = item.course;
}
})
return course
}
module.exports = {
abc: 123
xyz: 456
learn: learn
}
</wxs>
<view class="green">十二月份学习: {{learning.learn(12)}}</view>
<wxs src="data.wxs" module="abc"/>
<view>{{abc.mth}}{{abc.txt}}: {{learning.learn(12)}}</view>
\ No newline at end of file
/* pages/list/list.wxss */
@import '/template/template.wxss';
.nav {
display: flex;
justify-content: space-around;
line-height: 50rpx;
}
.banner .img {
width: 100%;
}
.list .item {
display: flex;
justify-content: space-around;
padding: 15rpx 0;
border-bottom: 1px solid #ccc;
}
.list .item .text {
width: 440rpx;
}
.list .item .text .title{
font-weight: bold;
}
.list .item .text .time{
margin-top: 24rpx;
color: #ccc;
font-size: 24rpx;
}
.list .item image {
width: 234rpx;
height: 140rpx;
}
.handleStyle {
color: pink;
padding-bottom: 10rpx;
border-bottom: 1px solid #ccc;
transition: color 0.5s;
}
.course {
display: flex;
justify-content: space-between;
color: #666;
}
.course text {
color: pink;
}
\ No newline at end of file
var txt = "月份学习"
module.exports = {
txt: txt
}
\ No newline at end of file
//logs.js
const util = require('../../utils/util.js')
Page({
data: {
logs: []
},
onLoad: function () {
this.setData({
logs: (wx.getStorageSync('logs') || []).map(log => {
return util.formatTime(new Date(log))
})
})
}
})
{
"navigationBarTitleText": "查看启动日志",
"usingComponents": {}
}
\ No newline at end of file
<!--logs.wxml-->
<view class="container log-list">
<block wx:for="{{logs}}" wx:for-item="log" wx:key="*this">
<text class="log-item">{{index + 1}}. {{log}}</text>
</block>
</view>
.log-list {
display: flex;
flex-direction: column;
padding: 40rpx;
}
.log-item {
margin: 10rpx;
}
// pages/news/news.js
Page({
/**
* 页面的初始数据
*/
data: {
news: [
{
title: '威廉·凯林等3人获诺贝尔生理学或医学奖分享647万',
desTitle: '专题',
desTime: '5小时',
src: 'https://pic2.zhimg.com/v2-87498c75c1d2917a391bfb6af70357fb_1440w.jpg'
},
{
title: '威廉·凯林等3人获诺贝尔生理学或医学奖分享647万',
desTitle: '专题',
desTime: '5小时',
src: 'https://pic2.zhimg.com/v2-87498c75c1d2917a391bfb6af70357fb_1440w.jpg'
},
{
title: '威廉·凯林等3人获诺贝尔生理学或医学奖分享647万',
desTitle: '专题',
desTime: '5小时',
src: 'https://pic2.zhimg.com/v2-87498c75c1d2917a391bfb6af70357fb_1440w.jpg'
}
],
title: '今天是我系统的学习微信小程序的第三天',
msg: 'used',
onoff: true,
price: 99,
obj: {
name: '小飞飞',
age: 21,
sex: '男',
num:35313387
},
arr: ['这是一段话', '这是第二段话', '这是第三段话'],
temperature: 30,
week: "周末",
list: [1,2,3,4]
},
handleAdd() {
let list = this.data.list;
// list.push("这个是新增的一段话")
list.splice(0,0,5)
this.setData({
list: list
})
},
handleSub() {
let list = this.data.list;
// list.push("这个是新增的一段话")
list.pop()
this.setData({
list: list
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})
\ No newline at end of file
{
"usingComponents": {},
"navigationBarBackgroundColor": "#ffffff",
"navigationBarTextStyle": "black",
"navigationBarTitleText": "新闻页面",
"backgroundColor": "#eeeeee",
"backgroundTextStyle": "light",
"enablePullDownRefresh": true
}
\ No newline at end of file
<view class="wrap" wx:for="{{news}}" wx:key="*this">
<view class="text">
<text class="title">{{item.title}}</text>
<view class="time">
<text>{{item.desTitle}}</text>
<text>{{item.desTime}}</text>
</view>
</view>
<image src="{{item.src}}"></image>
</view>
<!-- <view wx:for="{{news}}" wx:for-index="sncbasiucb" wx:for-item="bsdiaicbasc">
{{sncbasiucb}}: {{bsdiaicbasc.title}}
</view> -->
<checkbox class='{{msg}}'>比赛吧办事处</checkbox>
<view class="{{onoff?view:text}}">这是一段将要隐藏的代码</view>
<view wx:if="{{false}}">这是一个用于判断的语句</view>
<text>{{'$' + price + 'yuan'}}</text>
<!-- 对象取值 -->
<view class="message">
<text>{{obj.name}}</text>
<text>{{obj.age}}</text>
<text>{{obj.sex}}</text>
<text>{{obj.num}}</text>
</view>
<!-- 数组取值 -->
<text>{{arr[1]}}</text>
<!-- if-else条件判断 -->
<view wx:if='{{week === "周一"}}'>吃饭</view>
<view wx:elif='{{week === "周二"}}'>睡觉</view>
<view wx:else='{{week === "周三"}}'>打豆豆</view>
<!-- 三元表达式 -->
<view>{{(temperature >= 30) ? "穿短袖" : "穿外套"}}</view>
<!-- 九九乘法表 -->
<view wx:for="{{[1,2,3,4,5,6,7,8,9]}}" wx:for-item="i" wx:key="*this" class="row">
<view wx:for="{{[1,2,3,4,5,6,7,8,9]}}" wx:for-item="j" wx:key="*this" class="col">
<view wx:if="{{i>=j}}">
{{i}}*{{j}}={{i*j}}
</view>
</view>
</view>
<!-- 滑块展示 -->
<switch wx:for="{{list}}" wx:key="*this">{{index}}</switch>
<button bindtap="handleAdd">新增一项</button>
<button bindtap="handleSub">减少一项</button>
\ No newline at end of file
/* pages/news/news.wxss */
.wrap {
display: flex;
padding: 20rpx;
background-color: #eee;
justify-content: space-around;
}
.wrap .text {
flex: 7;
}
.wrap .text .time{
margin-top: 14rpx;
color: skyblue;
font-size: 20rpx;
}
.wrap .text .time text:last-child{
margin-left: 15rpx;
color: pink;
}
.wrap image {
width: 234rpx;
height: 145rpx;
flex: 3;
}
.used{
color: red;
}
.row {
display: flex;
}
.col {
padding-right: 10rpx;
}
\ No newline at end of file
// pages/shuju/shuju.js
Page({
/**
* 页面的初始数据
*/
data: {
logo: "https://u.geelg.com/i/fQURmKSsbnUyTx.png",
temperature: 15,
currentTab: 0,
banner: [
{
id: 1,
img: 'https://5b0988e595225.cdn.sohucs.com/images/20191006/ec09d870392d4dbfb92df1710b2b9868.jpeg',
title: '这是林允儿第一张照片'
}, {
id: 2,
img: "https://pic3.zhimg.com/80/v2-7367aec7bac3bc6157c5f729099a331a_1440w.jpg",
title: '这是林允儿第二张照片'
}
],
navList: [
{
id: 0,
name: "国际",
con: "guoji"
}, {
id: 1,
name: "国内",
con: "guonei"
}, {
id: 2,
name: "历史",
con: "lishi"
}
],
newsobj: {
guoji: [
{
id: 0,
title: '威廉·凯林等3人获诺贝尔生理学或医学奖分享647万',
desTitle: '专题',
desTime: '5小时',
src: 'https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=739779916,2608795784&fm=26&gp=0.jpg'
},
{
id: 1,
title: '威廉·凯林等3人获诺贝尔生理学或医学奖分享647万',
desTitle: '专题',
desTime: '5小时',
src: 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1607830260788&di=9951570100b316ffc84bcb4fcc6868c6&imgtype=0&src=http%3A%2F%2Finews.gtimg.com%2Fnewsapp_match%2F0%2F10618421117%2F0.jpg'
},
{
id: 2,
title: '威廉·凯林等3人获诺贝尔生理学或医学奖分享647万',
desTitle: '专题',
desTime: '5小时',
src: 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1607830290759&di=0cb27aa6b9aea8f5893f7f948f07f3a5&imgtype=0&src=http%3A%2F%2Fimg4.imgtn.bdimg.com%2Fit%2Fu%3D36252859%2C227563765%26fm%3D214%26gp%3D0.jpg'
}
],
guonei: [
{
id: 0,
title: '威廉·凯林等3人获诺贝尔生理学或医学奖分享647万',
desTitle: '专题',
desTime: '5小时',
src: 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1607830260786&di=8458771255ba9b4e3a49d9442be8a91d&imgtype=0&src=http%3A%2F%2Fb-ssl.duitang.com%2Fuploads%2Fitem%2F201602%2F12%2F20160212164547_BzjKv.jpeg'
},
{
id: 1,
title: '威廉·凯林等3人获诺贝尔生理学或医学奖分享647万',
desTitle: '专题',
desTime: '5小时',
src: 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1607830260784&di=6a53b2dbbd51ff0552c078e1bcdd8780&imgtype=0&src=http%3A%2F%2Fb.hiphotos.baidu.com%2Fzhidao%2Fpic%2Fitem%2F203fb80e7bec54e7bf22d925b8389b504fc26a3b.jpg'
},
{
id: 2,
title: '威廉·凯林等3人获诺贝尔生理学或医学奖分享647万',
desTitle: '专题',
desTime: '5小时',
src: 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1607830260783&di=50f747d93d9f4206a81e247398399ca7&imgtype=0&src=http%3A%2F%2Fc-ssl.duitang.com%2Fuploads%2Fitem%2F201611%2F30%2F20161130181234_PzFN8.jpeg'
}
],
lishi: [
{
id: 0,
title: '威廉·凯林等3人获诺贝尔生理学或医学奖分享647万',
desTitle: '专题',
desTime: '5小时',
src: 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1607830260782&di=e54609406db4d3c4f681b252f737d763&imgtype=0&src=http%3A%2F%2Fimages.h128.com%2Fupload%2F201907%2F14%2F201907140015304324.jpg%3Fx-oss-process%3Dimage%2Fresize%2Cm_lfit%2Cw_1421%2Fquality%2Cq_100%2Fformat%2Cjpg'
},
{
id: 1,
title: '威廉·凯林等3人获诺贝尔生理学或医学奖分享647万',
desTitle: '专题',
desTime: '5小时',
src: 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1607830260779&di=a95d1243d091f820eae141cced843b00&imgtype=0&src=http%3A%2F%2Fb-ssl.duitang.com%2Fuploads%2Fitem%2F201805%2F24%2F20180524221828_ofqud.jpg'
},
{
id: 2,
title: '威廉·凯林等3人获诺贝尔生理学或医学奖分享647万',
desTitle: '专题',
desTime: '5小时',
src: 'https://pic2.zhimg.com/v2-87498c75c1d2917a391bfb6af70357fb_1440w.jpg'
}
],
},
list: []
},
click:function(e) {
const {newsobj} = this.data
const {currenttab, con} = e.currentTarget.dataset;
this.setData({
currentTab: currenttab,
list: newsobj[con]
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
const { newsobj } = this.data;
this.setData({
list: newsobj['guoji'],
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})
\ No newline at end of file
{
"usingComponents": {}
}
\ No newline at end of file
<!--pages/shuju/shuju.wxml-->
<view class="title">
<view>
今天最高温度{{temperature}}℃
<text
wx:if="{{temperature >= 30}}"
>防止中暑</text>
<text
wx:elif="{{temperature >= 15}}"
>温度适宜</text>
<text
wx:else
>添衣保暖</text>
</view>
</view>
<view
class="nav"
>
<view
wx:for="{{navList}}"
wx:key="item"
>
<view
class="{{currentTab == item.id ? 'navStyle' : ''}}"
data-currentTab = "{{index}}"
data-con = "{{item.con}}"
bindtap="click"
>{{item.name}}</view>
</view>
</view>
<import src="/template/template.wxml" />
<view class="container">
<template is="tpl" data="{{news: list}}"></template>
</view>
<!-- <view
class="image"
>
<view
class="item"
wx:for="{{banner}}"
wx:key="*this"
>
<image
src="{{item.img}}"
></image>
<text>{{item.title}}</text>
</view>
</view> -->
\ No newline at end of file
This diff is collapsed.
{
"description": "项目配置文件",
"packOptions": {
"ignore": []
},
"setting": {
"urlCheck": true,
"es6": true,
"postcss": true,
"minified": true,
"newFeature": true,
"autoAudits": false,
"coverView": true,
"showShadowRootInWxmlPanel": true,
"scopeDataCheck": false
},
"compileType": "miniprogram",
"libVersion": "2.13.0",
"appid": "wx8138379e2e1faf10",
"projectname": "demo1",
"debugOptions": {
"hidedInDevtools": []
},
"isGameTourist": false,
"simulatorType": "wechat",
"simulatorPluginLibVersion": {},
"condition": {
"search": {
"current": -1,
"list": []
},
"conversation": {
"current": -1,
"list": []
},
"game": {
"currentL": -1,
"list": []
},
"miniprogram": {
"current": -1,
"list": []
}
}
}
\ No newline at end of file
{
"desc": "关于本文件的更多信息,请参考文档 https://developers.weixin.qq.com/miniprogram/dev/framework/sitemap.html",
"rules": [{
"action": "allow",
"page": "*"
}]
}
\ No newline at end of file
<template name="tpl">
<view class="wrap" wx:for="{{news}}" wx:key="*this">
<view class="text">
<text class="title1">{{item.title}}</text>
<view class="time">
<text>{{item.desTitle}}</text>
<text>{{item.desTime}}</text>
</view>
</view>
<image src="{{item.src}}"></image>
</view>
</template>
\ No newline at end of file
.wrap {
display: flex;
padding: 20rpx;
background-color: #eee;
justify-content: space-around;
}
.wrap .text {
flex: 7;
}
.wrap .text .time{
margin-top: 14rpx;
color: skyblue;
font-size: 20rpx;
}
.wrap .text .time text:last-child{
margin-left: 15rpx;
color: pink;
}
.wrap image {
width: 234rpx;
height: 145rpx;
flex: 3;
}
\ No newline at end of file
const formatTime = date => {
const year = date.getFullYear()
const month = date.getMonth() + 1
const day = date.getDate()
const hour = date.getHours()
const minute = date.getMinutes()
const second = date.getSeconds()
return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}
const formatNumber = n => {
n = n.toString()
return n[1] ? n : '0' + n
}
module.exports = {
formatTime: formatTime
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment