作者 刘晓艳

打印首页

  1 +//app.js
  2 +App({
  3 + onLaunch: function () {
  4 + // 展示本地存储能力
  5 + var logs = wx.getStorageSync('logs') || []
  6 + logs.unshift(Date.now())
  7 + wx.setStorageSync('logs', logs)
  8 +
  9 + // 登录
  10 + wx.login({
  11 + success: res => {
  12 + // 发送 res.code 到后台换取 openId, sessionKey, unionId
  13 + }
  14 + })
  15 + // 获取用户信息
  16 + wx.getSetting({
  17 + success: res => {
  18 + if (res.authSetting['scope.userInfo']) {
  19 + // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
  20 + wx.getUserInfo({
  21 + success: res => {
  22 + // 可以将 res 发送给后台解码出 unionId
  23 + this.globalData.userInfo = res.userInfo
  24 +
  25 + // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
  26 + // 所以此处加入 callback 以防止这种情况
  27 + if (this.userInfoReadyCallback) {
  28 + this.userInfoReadyCallback(res)
  29 + }
  30 + }
  31 + })
  32 + }
  33 + }
  34 + })
  35 + },
  36 + globalData: {
  37 + userInfo: null
  38 + }
  39 +})
  1 +{
  2 + "pages":[
  3 + "pages/index/index",
  4 + "pages/logs/logs"
  5 + ],
  6 + "window":{
  7 + "backgroundTextStyle":"light",
  8 + "navigationBarBackgroundColor": "#fff",
  9 + "navigationBarTitleText": "快印帮",
  10 + "navigationBarTextStyle":"black"
  11 + }
  12 +}
  1 +/**app.wxss**/
  2 +@font-face {
  3 + font-family: 'iconfont'; /* project id 1056878 */
  4 + src: url('//at.alicdn.com/t/font_1056878_ji4zh6otyns.eot');
  5 + src: url('//at.alicdn.com/t/font_1056878_ji4zh6otyns.eot?#iefix') format('embedded-opentype'),
  6 + url('//at.alicdn.com/t/font_1056878_ji4zh6otyns.woff2') format('woff2'),
  7 + url('//at.alicdn.com/t/font_1056878_ji4zh6otyns.woff') format('woff'),
  8 + url('//at.alicdn.com/t/font_1056878_ji4zh6otyns.ttf') format('truetype'),
  9 + url('//at.alicdn.com/t/font_1056878_ji4zh6otyns.svg#iconfont') format('svg');
  10 +}
  11 +
  12 +
  13 +.iconfont {
  14 + font-family: "iconfont" !important;
  15 + font-size: 16px;
  16 + font-style: normal;
  17 + -webkit-font-smoothing: antialiased;
  18 + -moz-osx-font-smoothing: grayscale;
  19 +}
  20 +
  21 +.icon-xuanze:before {
  22 + content: "\e621";
  23 +}
  24 +
  25 +.icon-lanmangouwuche:before {
  26 + content: "\e60a";
  27 +}
  28 +
  29 +.icon-shangsanjiao:before {
  30 + content: "\e66e";
  31 +}
  32 +
  33 +.icon-xuanze1:before {
  34 + content: "\e623";
  35 +}
  36 +
  37 +.icon-erji:before {
  38 + content: "\e65a";
  39 +}
  40 +
  41 +.icon-erji1:before {
  42 + content: "\e608";
  43 +}
  44 +
  45 +.icon-sousuo:before {
  46 + content: "\e60d";
  47 +}
  48 +
  49 +.icon-fenxiang:before {
  50 + content: "\e61a";
  51 +}
  52 +
  53 +.icon-kefu:before {
  54 + content: "\e674";
  55 +}
  56 +
  57 +.icon-xuanze2:before {
  58 + content: "\e600";
  59 +}
  60 +
  61 +.icon-bianji:before {
  62 + content: "\e60e";
  63 +}
  64 +
  65 +.icon-laba:before {
  66 + content: "\e645";
  67 +}
  68 +
  69 +.icon-xuanze3:before {
  70 + content: "\e605";
  71 +}
  72 +
  73 +.icon-xiala:before {
  74 + content: "\e61f";
  75 +}
  76 +
  77 +.icon-shanchu:before {
  78 + content: "\e604";
  79 +}
  80 +
  81 +.icon-ditu:before {
  82 + content: "\e656";
  83 +}
  84 +
  85 +.icon-xiayibu:before {
  86 + content: "\e64a";
  87 +}
  88 +
  89 +.icon-xiala1:before {
  90 + content: "\e624";
  91 +}
  92 +
  93 +.icon-erji2:before {
  94 + content: "\e601";
  95 +}
  96 +
  97 +.icon-gouwuche:before {
  98 + content: "\e677";
  99 +}
  100 +
  101 +.icon-shanchu1:before {
  102 + content: "\e602";
  103 +}
  1 +//index.js
  2 +//获取应用实例
  3 +const app = getApp()
  4 +
  5 +Page({
  6 + data: {
  7 + classify: [{
  8 + img: '/images/icon_03@2x.png',
  9 + text: '111'
  10 + }, {
  11 + img: '/images/icon_03@2x.png',
  12 + text: '22'
  13 + }],
  14 + imgsUrl: ['/images/icon_11@2x.png', '/images/icon_11@2x.png'],
  15 + current_page:0
  16 + },
  17 + swiperCharge(e){
  18 + this.setData({
  19 + current_page: e.detail.current
  20 + })
  21 + },
  22 + onLoad: function() {
  23 +
  24 + },
  25 +
  26 +})
  1 +{
  2 + "usingComponents": {}
  3 +}
  1 +<!--index.wxml-->
  2 +
  3 +<view class='top_box'>
  4 + <view class='search_box'>
  5 + <view class='iconfont icon-sousuo'></view>
  6 + <view>搜索</view>
  7 + </view>
  8 + <view class='banner_box'>
  9 + <view class='banner_label'>
  10 + <text class='iconfont icon-laba'></text>
  11 + <text>快印帮搞活动啦,广告印刷样样有!</text>
  12 + </view>
  13 + <view class='swiper_content'>
  14 + <swiper class='swiper_box' bindchange='swiperCharge'>
  15 + <block wx:for='{{imgsUrl}}' wx:key>
  16 + <swiper-item>
  17 + <image src='{{item}}'></image>
  18 + </swiper-item>
  19 + </block>
  20 + </swiper>
  21 + <view class='dot_box'>
  22 + <block wx:for='{{imgsUrl}}' wx:key>
  23 + <view class="dot_item {{current_page==index?'dot_active':''}}"></view>
  24 + </block>
  25 + </view>
  26 + </view>
  27 + <view class='classify_box'>
  28 + <view class='classify_item' wx:for='{{[1,2,3,4]}}' wx:key>
  29 + <image src='/images/icon_03@2x.png'></image>
  30 + <view>网上打印</view>
  31 + </view>
  32 + </view>
  33 + </view>
  34 +</view>
  35 +<view class='content_box'>
  36 + <view class='title'>热门推荐</view>
  37 + <view class='list_box'>
  38 + <view class='item_list' wx:for='{{[1,2,3,4]}}' wx:key>
  39 + <image src='/images/icon_08@2x.png'></image>
  40 + <view class='list_content'>彩色喷墨一体机...</view>
  41 + <view class='list_price'>¥ 85.00</view>
  42 + </view>
  43 + </view>
  44 +</view>
  45 +<view class='img_box'>
  46 + <image src='/images/icon_10@2x.png'></image>
  47 +</view>
  1 +/**index.wxss**/
  2 +
  3 +page {
  4 + background: #f0f0f0;
  5 +}
  6 +
  7 +.top_box {
  8 + background: #fff;
  9 + padding: 20rpx 30rpx;
  10 +}
  11 +
  12 +.search_box {
  13 + width: 100%;
  14 + height: 59rpx;
  15 + background: rgba(255, 255, 255, 1);
  16 + border: 1rpx solid #a0a0a0;
  17 + border-radius: 12rpx;
  18 + display: flex;
  19 + align-items: center;
  20 + justify-content: center;
  21 + font-size: 28rpx;
  22 + color: #000;
  23 +}
  24 +
  25 +.icon-sousuo {
  26 + font-size: 32rpx;
  27 + color: #ff5922;
  28 + margin-right: 10rpx;
  29 +}
  30 +
  31 +.banner_box {
  32 + margin-top: 16rpx;
  33 + position: relative;
  34 +}
  35 +
  36 +.swiper_box {
  37 + width: 100%;
  38 + height: 320rpx;
  39 + position: relative;
  40 +}
  41 +
  42 +.swiper_box image {
  43 + width: 100%;
  44 + height: 320rpx;
  45 +}
  46 +
  47 +.banner_label {
  48 + width: 100%;
  49 + height: 60rpx;
  50 + display: flex;
  51 + align-items: center;
  52 + justify-content: center;
  53 + background: rgba(255, 255, 255, 0.6);
  54 + font-size: 28rpx;
  55 + color: #000;
  56 + position: absolute;
  57 + top: 0;
  58 + left: 0;
  59 + z-index: 100;
  60 +}
  61 +
  62 +.icon-laba {
  63 + font-size: 34rpx;
  64 + margin-right: 10rpx;
  65 +}
  66 +
  67 +.swiper_content {
  68 + position: relative;
  69 +}
  70 +
  71 +.dot_box {
  72 + position: absolute;
  73 + bottom: 15rpx;
  74 + left: 0;
  75 + display: flex;
  76 + align-items: center;
  77 +}
  78 +
  79 +.dot_item {
  80 + width: 11rpx;
  81 + height: 11rpx;
  82 + border: 1rpx solid rgba(255, 255, 255, 0.6);
  83 + border-radius: 50%;
  84 + margin-left: 20rpx;
  85 +}
  86 +
  87 +.dot_active {
  88 + width: 11rpx;
  89 + height: 11rpx;
  90 + background: rgba(255, 255, 255, 1);
  91 + border-radius: 50%;
  92 +}
  93 +
  94 +.classify_box {
  95 + display: flex;
  96 + align-items: center;
  97 + justify-content: space-around;
  98 + margin: 40rpx 0 20rpx 0;
  99 +}
  100 +
  101 +.classify_item {
  102 + font-size: 26rpx;
  103 + text-align: center;
  104 +}
  105 +
  106 +.classify_item image {
  107 + width: 60rpx;
  108 + height: 60rpx;
  109 +}
  110 +
  111 +.content_box {
  112 + background: #fff;
  113 + padding: 30rpx;
  114 + margin-top: 16rpx;
  115 +}
  116 +
  117 +.title {
  118 + font-size: 30rpx;
  119 + font-weight: bold;
  120 + color: #000;
  121 + text-align: center;
  122 +}
  123 +
  124 +.list_box {
  125 + display: flex;
  126 + align-items: center;
  127 + justify-content: space-between;
  128 + flex-wrap: wrap;
  129 +}
  130 +
  131 +.item_list {
  132 + width: 30%;
  133 + margin-bottom: 20rpx;
  134 +}
  135 +
  136 +.item_list image {
  137 + width: 205rpx;
  138 + height: 212rpx;
  139 +}
  140 +
  141 +.list_content {
  142 + font-size: 24rpx;
  143 + color: #000;
  144 + display: -webkit-box;
  145 + -webkit-box-orient: vertical;
  146 + -webkit-line-clamp: 1;
  147 + overflow: hidden;
  148 + text-overflow: ellipsis;
  149 +}
  150 +
  151 +.list_price {
  152 + font-size: 24rpx;
  153 + font-weight: bold;
  154 + color: #ff5922;
  155 +}
  156 +.img_box{
  157 + position: fixed;
  158 + top: 50%;
  159 + left: 45rpx;
  160 + transform: translateY(-50%);
  161 +}
  162 +.img_box image{
  163 + width: 94rpx;
  164 + height: 114rpx;
  165 +}
  1 +//logs.js
  2 +const util = require('../../utils/util.js')
  3 +
  4 +Page({
  5 + data: {
  6 + logs: []
  7 + },
  8 + onLoad: function () {
  9 + this.setData({
  10 + logs: (wx.getStorageSync('logs') || []).map(log => {
  11 + return util.formatTime(new Date(log))
  12 + })
  13 + })
  14 + }
  15 +})
  1 +{
  2 + "navigationBarTitleText": "查看启动日志",
  3 + "usingComponents": {}
  4 +}
  1 +<!--logs.wxml-->
  2 +<view class="container log-list">
  3 + <block wx:for="{{logs}}" wx:for-item="log">
  4 + <text class="log-item">{{index + 1}}. {{log}}</text>
  5 + </block>
  6 +</view>
  1 +.log-list {
  2 + display: flex;
  3 + flex-direction: column;
  4 + padding: 40rpx;
  5 +}
  6 +.log-item {
  7 + margin: 10rpx;
  8 +}
  1 +{
  2 + "description": "项目配置文件",
  3 + "packOptions": {
  4 + "ignore": []
  5 + },
  6 + "setting": {
  7 + "urlCheck": true,
  8 + "es6": true,
  9 + "postcss": true,
  10 + "minified": true,
  11 + "newFeature": true,
  12 + "autoAudits": false
  13 + },
  14 + "compileType": "miniprogram",
  15 + "libVersion": "2.6.0",
  16 + "appid": "wxdf7ee45f1c64c486",
  17 + "projectname": "dayin",
  18 + "debugOptions": {
  19 + "hidedInDevtools": []
  20 + },
  21 + "isGameTourist": false,
  22 + "condition": {
  23 + "search": {
  24 + "current": -1,
  25 + "list": []
  26 + },
  27 + "conversation": {
  28 + "current": -1,
  29 + "list": []
  30 + },
  31 + "game": {
  32 + "currentL": -1,
  33 + "list": []
  34 + },
  35 + "miniprogram": {
  36 + "current": -1,
  37 + "list": []
  38 + }
  39 + }
  40 +}
  1 +const formatTime = date => {
  2 + const year = date.getFullYear()
  3 + const month = date.getMonth() + 1
  4 + const day = date.getDate()
  5 + const hour = date.getHours()
  6 + const minute = date.getMinutes()
  7 + const second = date.getSeconds()
  8 +
  9 + return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
  10 +}
  11 +
  12 +const formatNumber = n => {
  13 + n = n.toString()
  14 + return n[1] ? n : '0' + n
  15 +}
  16 +
  17 +module.exports = {
  18 + formatTime: formatTime
  19 +}