大侠 2 лет назад
Родитель
Сommit
a0b7a8c653

+ 31 - 0
16_miniapp/day-1/code/douniwan/.eslintrc.js

@@ -0,0 +1,31 @@
+/*
+ * Eslint config file
+ * Documentation: https://eslint.org/docs/user-guide/configuring/
+ * Install the Eslint extension before using this feature.
+ */
+module.exports = {
+  env: {
+    es6: true,
+    browser: true,
+    node: true,
+  },
+  ecmaFeatures: {
+    modules: true,
+  },
+  parserOptions: {
+    ecmaVersion: 2018,
+    sourceType: 'module',
+  },
+  globals: {
+    wx: true,
+    App: true,
+    Page: true,
+    getCurrentPages: true,
+    getApp: true,
+    Component: true,
+    requirePlugin: true,
+    requireMiniProgram: true,
+  },
+  // extends: 'eslint:recommended',
+  rules: {},
+}

+ 20 - 0
16_miniapp/day-1/code/douniwan/app.js

@@ -0,0 +1,20 @@
+// app.js
+App({
+  onLaunch() {
+    // 展示本地存储能力
+    const logs = wx.getStorageSync('logs') || []
+    logs.unshift(Date.now())
+    wx.setStorageSync('logs', logs)
+
+    // 登录
+    wx.login({
+      success: res => {
+        // 发送 res.code 到后台换取 openId, sessionKey, unionId
+      }
+    })
+  },
+  // 全局共享数据
+  globalData: {
+    userInfo: null
+  }
+})

+ 15 - 0
16_miniapp/day-1/code/douniwan/app.json

@@ -0,0 +1,15 @@
+{
+  "pages":[
+    "pages/index/index",
+    "pages/logs/logs"
+  ],
+  "window":{
+    "backgroundTextStyle":"dark",
+    "navigationBarBackgroundColor": "#008B45",
+    "navigationBarTitleText": "微信小程序",
+    "navigationBarTextStyle":"white",
+    "enablePullDownRefresh": true
+  },
+  "style": "v2",
+  "sitemapLocation": "sitemap.json"
+}

+ 10 - 0
16_miniapp/day-1/code/douniwan/app.wxss

@@ -0,0 +1,10 @@
+/**app.wxss**/
+.container {
+  height: 100%;
+  display: flex;
+  flex-direction: column;
+  align-items: center;
+  justify-content: space-between;
+  padding: 200rpx 0;
+  box-sizing: border-box;
+} 

+ 21 - 0
16_miniapp/day-1/code/douniwan/pages/index/index.js

@@ -0,0 +1,21 @@
+
+
+Page({
+  // 页面的数据,数据一旦变化 会引发页面重新渲染
+  data: {
+    msg: '你好,世界。',
+    id: 1,
+    test: '测试',
+    length: 3,
+    show: true,
+    list: [1,2,3],
+    subList: [4,5],
+    message: {
+      id: 1,
+      msg: '该吃药大朗',
+      // time: new Date()
+      time: new Date().toLocaleString()
+    }
+  },
+  
+})

+ 3 - 0
16_miniapp/day-1/code/douniwan/pages/index/index.json

@@ -0,0 +1,3 @@
+{
+  "usingComponents": {}
+}

+ 48 - 0
16_miniapp/day-1/code/douniwan/pages/index/index.wxml

@@ -0,0 +1,48 @@
+<view>
+  <text class="title">我是一个主页页面</text>
+ <view>
+  <text>{{ msg }}</text>
+ </view>
+ <view id="id-{{id}}" data-test="{{ test }}">动态绑定属性</view>
+ <view>
+   1 + 1 = {{ 1 + 1 }}
+ </view>
+ <view>条件渲染</view>
+ <view wx:if="{{length > 5}}">1</view>
+ <view wx:elif="{{length > 2}}">2</view>
+ <view wx:else>3</view>
+
+ <view hidden="{{show}}">猜猜你能看见我吗</view>
+
+  <view hidden="{{!show}}">
+   heheda
+  </view>
+
+  <block wx:if="{{show}}">
+    <view>view-1</view>
+    <view>view-2</view>
+  </block>
+
+  <view wx:for="{{list}}" wx:key="index">
+    <text>{{item}}</text>
+    <view wx:for="{{subList}}" wx:key="index" wx:for-item="subItem">
+      <text>{{item + subItem}}</text>
+    </view>
+  </view>
+  <view>使用模板</view>
+  <view>
+    <template is="msgTpl" data="{{...message}}"></template>
+  </view>
+</view>
+
+<!-- 定义模板 -->
+<template name="msgTpl">
+  <view>
+    <text>{{msg}}</text>
+    <text> -- 时间:{{time}}</text>
+  </view>
+
+  <view>
+    [] == ![] ? true or false
+  </view>
+</template>

+ 5 - 0
16_miniapp/day-1/code/douniwan/pages/index/index.wxss

@@ -0,0 +1,5 @@
+/**index.wxss**/
+.title {
+  font-size: 20px;
+  font-weight: 700;
+}

+ 18 - 0
16_miniapp/day-1/code/douniwan/pages/logs/logs.js

@@ -0,0 +1,18 @@
+// logs.js
+const util = require('../../utils/util.js')
+
+Page({
+  data: {
+    logs: []
+  },
+  onLoad() {
+    this.setData({
+      logs: (wx.getStorageSync('logs') || []).map(log => {
+        return {
+          date: util.formatTime(new Date(log)),
+          timeStamp: log
+        }
+      })
+    })
+  }
+})

+ 4 - 0
16_miniapp/day-1/code/douniwan/pages/logs/logs.json

@@ -0,0 +1,4 @@
+{
+  "navigationBarTitleText": "查看启动日志",
+  "usingComponents": {}
+}

+ 6 - 0
16_miniapp/day-1/code/douniwan/pages/logs/logs.wxml

@@ -0,0 +1,6 @@
+<!--logs.wxml-->
+<view class="container log-list">
+  <block wx:for="{{logs}}" wx:key="timeStamp" wx:for-item="log">
+    <text class="log-item">{{index + 1}}. {{log.date}}</text>
+  </block>
+</view>

+ 8 - 0
16_miniapp/day-1/code/douniwan/pages/logs/logs.wxss

@@ -0,0 +1,8 @@
+.log-list {
+  display: flex;
+  flex-direction: column;
+  padding: 40rpx;
+}
+.log-item {
+  margin: 10rpx;
+}

+ 51 - 0
16_miniapp/day-1/code/douniwan/project.config.json

@@ -0,0 +1,51 @@
+{
+  "description": "项目配置文件",
+  "packOptions": {
+    "ignore": [],
+    "include": []
+  },
+  "setting": {
+    "bundle": false,
+    "userConfirmedBundleSwitch": false,
+    "urlCheck": true,
+    "scopeDataCheck": false,
+    "coverView": true,
+    "es6": false,
+    "postcss": true,
+    "compileHotReLoad": false,
+    "lazyloadPlaceholderEnable": false,
+    "preloadBackgroundData": false,
+    "minified": true,
+    "autoAudits": false,
+    "newFeature": false,
+    "uglifyFileName": false,
+    "uploadWithSourceMap": true,
+    "useIsolateContext": true,
+    "nodeModules": false,
+    "enhance": false,
+    "useMultiFrameRuntime": true,
+    "useApiHook": true,
+    "useApiHostProcess": true,
+    "showShadowRootInWxmlPanel": true,
+    "packNpmManually": false,
+    "enableEngineNative": false,
+    "packNpmRelationList": [],
+    "minifyWXSS": true,
+    "showES6CompileOption": false,
+    "minifyWXML": true,
+    "babelSetting": {
+      "ignore": [],
+      "disablePlugins": [],
+      "outputPath": ""
+    }
+  },
+  "compileType": "miniprogram",
+  "libVersion": "2.19.4",
+  "appid": "wxb7f9a42f0b768006",
+  "projectname": "miniprogram-92",
+  "condition": {},
+  "editorSetting": {
+    "tabIndent": "insertSpaces",
+    "tabSize": 2
+  }
+}

+ 9 - 0
16_miniapp/day-1/code/douniwan/project.private.config.json

@@ -0,0 +1,9 @@
+{
+  "description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档:https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html",
+  "projectname": "douniwan",
+  "setting": {
+    "compileHotReLoad": true,
+    "urlCheck": false
+  },
+  "libVersion": "2.30.2"
+}

+ 7 - 0
16_miniapp/day-1/code/douniwan/sitemap.json

@@ -0,0 +1,7 @@
+{
+  "desc": "关于本文件的更多信息,请参考文档 https://developers.weixin.qq.com/miniprogram/dev/framework/sitemap.html",
+  "rules": [{
+  "action": "allow",
+  "page": "*"
+  }]
+}

+ 19 - 0
16_miniapp/day-1/code/douniwan/utils/util.js

@@ -0,0 +1,19 @@
+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
+}

BIN
16_miniapp/day-1/note/app-window配置.jpg