{"id":30035,"date":"2024-11-25T08:54:09","date_gmt":"2024-11-25T00:54:09","guid":{"rendered":"https:\/\/fwq.ai\/blog\/30035\/"},"modified":"2024-11-25T08:54:09","modified_gmt":"2024-11-25T00:54:09","slug":"%e5%b0%8f%e7%a8%8b%e5%ba%8f%e5%bc%80%e5%8f%91%e4%b9%8b%e8%ae%a1%e7%ae%97%e5%99%a8","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/30035\/","title":{"rendered":"\u5c0f\u7a0b\u5e8f\u5f00\u53d1\u4e4b\u8ba1\u7b97\u5668"},"content":{"rendered":"<p>\u5728\u8fd9\u7bc7\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u5f00\u53d1\u6559\u7a0b\u4e2d\uff0c\u6211\u4eec\u5c06\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u5f00\u53d1\u8ba1\u7b97\u5668\u529f\u80fd\u3002<\/p>\n<p>\u672c\u6587\u4e3b\u8981\u5206\u4e3a\u4e24\u4e2a\u90e8\u5206\uff0c\u5c0f\u7a0b\u5e8f\u4e3b\u4f53\u90e8\u5206\u53ca\u8ba1\u7b97\u5668\u4e1a\u52a1\u9875\u9762\u90e8\u5206<\/p>\n<h2>\u4e00\u3001\u5c0f\u7a0b\u5e8f\u4e3b\u4f53\u90e8\u5206<\/h2>\n<p>\u4e00\u4e2a\u5c0f\u7a0b\u5e8f\u4e3b\u4f53\u90e8\u5206\u7531\u4e09\u4e2a\u6587\u4ef6\u7ec4\u6210\uff0c\u5fc5\u987b\u653e\u5728\u9879\u76ee\u7684\u6839\u76ee\u5f55\uff0c\u5982\u4e0b\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/001\/505\/957cd71a3f4f65061c2eccce574a2dec-0.png\" class=\"aligncenter\" title=\"\u5c0f\u7a0b\u5e8f\u5f00\u53d1\u4e4b\u8ba1\u7b97\u5668\u63d2\u56fe\" alt=\"\u5c0f\u7a0b\u5e8f\u5f00\u53d1\u4e4b\u8ba1\u7b97\u5668\u63d2\u56fe\" \/><\/p>\n<p>1. \u5c0f\u7a0b\u5e8f\u903b\u8f91<\/p>\n<pre>App({\r\n  onLaunch: function() { \r\n    \/\/ Do something initial when launch.  },\r\n  onShow: function() {      \/\/ Do something when show.  },\r\n  onHide: function() {      \/\/ Do something when hide.  },\r\n  globalData: 'I am global data'})<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>2. \u5c0f\u7a0b\u5e8f\u516c\u5171\u8bbe\u7f6e<\/p>\n<pre>{\r\n  \"pages\": [\r\n    \"page\/index\/index\"\r\n  ],\r\n  \"window\": {\r\n    \"navigationBarBackgroundColor\": \"#000\",\r\n    \"backgroundColor\": \"#000\",\r\n    \"navigationBarBackgroundColor\": \"#000\"\r\n  },\r\n  \"networkTimeout\": {\r\n    \"request\": 10000,\r\n    \"connectSocket\": 10000,\r\n    \"uploadFile\": 10000,\r\n    \"downloadFile\": 10000\r\n  },\r\n  \"debug\": true\r\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<h2>\u4e8c\u3001\u8ba1\u7b97\u5668\u9875\u9762\u90e8\u5206<\/h2>\n<p>\u8ba1\u7b97\u5668\u9875\u9762\u4e3b\u8981\u7531\u4ee5\u4e0b\u6587\u4ef6\u7ec4\u6210\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/001\/505\/4ea66f8e0a1e5c0b99ded692e59a566a-1.png\" class=\"aligncenter\" title=\"\u5c0f\u7a0b\u5e8f\u5f00\u53d1\u4e4b\u8ba1\u7b97\u5668\u63d2\u56fe1\" alt=\"\u5c0f\u7a0b\u5e8f\u5f00\u53d1\u4e4b\u8ba1\u7b97\u5668\u63d2\u56fe1\" \/><\/p>\n<p>1. \u8ba1\u7b97\u5668\u9875\u9762\u7ed3\u6784<\/p>\n<p>\u9875\u9762\u7ed3\u6784\u5206\u4e3a2\u4e2a\u4e3b\u8981\u90e8\u5206\uff1a\u663e\u793a\u533a\u548c\u952e\u76d8\u533a<\/p>\n<p>\u5176\u4e2d\u952e\u76d8\u533a\u53c8\u5206\u529f\u80fd\u952e\u3001\u6570\u5b57\u952e\uff0c\u53ca\u8fd0\u7b97\u952e\uff0c\u9875\u9762\u7ed3\u6784\u5982\u4e0b<\/p>\n<pre>&lt;template name=\"calculator-key\"&gt;\r\n  &lt;button hover-start-time=\"{{5}}\" hover-stay-time=\"{{20}}\" hover-class=\"calculator-key-hover\" data-key=\"{{className}}\" class=\"calculator-key {{className}}\"&gt;{{display}}&lt;\/button&gt;&lt;\/template&gt;&lt;view class=\"calculator\"&gt;\r\n  &lt;view class=\"calculator-display\"&gt;\r\n    &lt;view class=\"calculator-display-text\"&gt;{{displayValue}}&lt;\/view&gt;\r\n  &lt;\/view&gt;\r\n  &lt;view class=\"calculator-keypad\"&gt;\r\n    &lt;view class=\"input-keys\"&gt;\r\n      &lt;view class=\"function-keys\" catchtap=\"onTapFunction\"&gt;\r\n        &lt;template is=\"calculator-key\" data=\"{{className: 'key-clear', display: clearDisplay ? 'C' : 'AC'}}\"\/&gt;\r\n        &lt;template is=\"calculator-key\" data=\"{{className: 'key-sign', display: '\u00b1'}}\"\/&gt;\r\n        &lt;template is=\"calculator-key\" data=\"{{className: 'key-percent', display: '%'}}\"\/&gt;\r\n      &lt;\/view&gt;\r\n      \/*sdf*\/      &lt;view class=\"digit-keys\" catchtap=\"onTapDigit\"&gt;\r\n        &lt;template is=\"calculator-key\" data=\"{{className: 'key-0', display: '0'}}\"\/&gt;\r\n        &lt;template is=\"calculator-key\" data=\"{{className: 'key-dot', display: '\u25cf'}}\"\/&gt;\r\n        &lt;template is=\"calculator-key\" data=\"{{className: 'key-1', display: '1'}}\"\/&gt;\r\n        &lt;template is=\"calculator-key\" data=\"{{className: 'key-2', display: '2'}}\"\/&gt;\r\n        &lt;template is=\"calculator-key\" data=\"{{className: 'key-3', display: '3'}}\"\/&gt;\r\n        &lt;template is=\"calculator-key\" data=\"{{className: 'key-4', display: '4'}}\"\/&gt;\r\n        &lt;template is=\"calculator-key\" data=\"{{className: 'key-5', display: '5'}}\"\/&gt;\r\n        &lt;template is=\"calculator-key\" data=\"{{className: 'key-6', display: '6'}}\"\/&gt;\r\n        &lt;template is=\"calculator-key\" data=\"{{className: 'key-7', display: '7'}}\"\/&gt;\r\n        &lt;template is=\"calculator-key\" data=\"{{className: 'key-8', display: '8'}}\"\/&gt;\r\n        &lt;template is=\"calculator-key\" data=\"{{className: 'key-9', display: '9'}}\"\/&gt;\r\n      &lt;\/view&gt;\r\n    &lt;\/view&gt;\r\n    &lt;view class=\"operator-keys\" catchtap=\"onTapOperator\"&gt;\r\n        &lt;template is=\"calculator-key\" data=\"{{className: 'key-pide', display: '\u00f7'}}\"\/&gt;\r\n        &lt;template is=\"calculator-key\" data=\"{{className: 'key-multiply', display: '\u00d7'}}\"\/&gt;\r\n        &lt;template is=\"calculator-key\" data=\"{{className: 'key-subtract', display: '\u2212'}}\"\/&gt;\r\n        &lt;template is=\"calculator-key\" data=\"{{className: 'key-add', display: '+'}}\"\/&gt;\r\n        &lt;template is=\"calculator-key\" data=\"{{className: 'key-equals', display: '='}}\"\/&gt;\r\n    &lt;\/view&gt;\r\n  &lt;\/view&gt;&lt;\/view&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>2. \u8ba1\u7b97\u5668\u6837\u5f0f\u8868<\/p>\n<p>\u6837\u5f0f\u4ee3\u7801\u5982\u4e0b\u6240\u793a<\/p>\n<pre>@import \"reset.wxss\";\r\n\r\npage {\r\n  font: 100 14px 'Roboto';\r\n}.calculator {\r\n  width: 100%;\r\n  height: 100vh;\r\n  background: black;\r\n  position: relative;\r\n  box-shadow: 0px 0px 20px 0px #aaa;\r\n  display: flex;\r\n  flex-direction: column;\r\n  box-sizing: border-box;\r\n}.calculator-display {\r\n  background: #1c191c;\r\n  flex: 1;\r\n}\/*TODO:\u89e3\u51b3\u6587\u672c\u5782\u76f4\u5c45\u4e2d\u95ee\u9898*\/.calculator-display-text {\r\n  padding: 0 30px;\r\n  font-size: 6em;\r\n  color: white;\r\n  text-align: right;\r\n}.calculator-keypad {\r\n  display: flex;\r\n}.calculator .function-keys {\r\n  display: flex;\r\n}.calculator .digit-keys {\r\n  background: #e0e0e7;\r\n  display: flex;\r\n  flex-direction: row;\r\n  flex-wrap: wrap-reverse;\r\n}.calculator-key-hover {\r\n  box-shadow: inset 0px 0px 25vw 0px rgba(0,0,0,0.25);\r\n}.calculator-key {\r\n  display: block;\r\n  width: 25vw;\r\n  height: 25vw;\r\n  line-height: 25vw;\r\n  border-top: 1px solid #777;\r\n  border-right: 1px solid #666;\r\n  text-align: center;\r\n  box-sizing: border-box;\r\n}.calculator .function-keys .calculator-key {\r\n  font-size: 2em;\r\n}.calculator .digit-keys .calculator-key {\r\n  font-size: 2.25em;\r\n}.calculator .digit-keys .key-0 {\r\n  width: 50vw;\r\n  text-align: left;\r\n  padding-left: 9vw;\r\n}.calculator .digit-keys .key-dot {\r\n  padding-top: 1em;\r\n  font-size: 0.75em;\r\n}.calculator .operator-keys .calculator-key {\r\n  color: white;\r\n  border-right: 0;\r\n  font-size: 3em;\r\n}.calculator .function-keys {\r\n  background: linear-gradient(to bottom, rgba(202,202,204,1) 0%, rgba(196,194,204,1) 100%);\r\n}.calculator .operator-keys {\r\n  background:  linear-gradient(to bottom, rgba(252,156,23,1) 0%, rgba(247,126,27,1) 100%);\r\n}.input-keys {\r\n  width: 75%;\r\n}.operator-keys {\r\n  width: 25%;\r\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>3\u3001 \u8ba1\u7b97\u5668\u9875\u9762\u903b\u8f91\u5904\u7406<\/p>\n<pre>Page({\r\n  data: {\r\n    value: null, \/\/ \u4e0a\u6b21\u8ba1\u7b97\u540e\u7684\u7ed3\u679c\uff0cnull\u8868\u793a\u6ca1\u6709\u4e0a\u6b21\u8ba1\u7b97\u7684\u7ed3\u679c\r\n    displayValue: '0', \/\/ \u663e\u793a\u6570\u503c\r\n    operator: null, \/\/ \u4e0a\u6b21\u8ba1\u7b97\u7b26\u53f7\uff0cnull\u8868\u793a\u6ca1\u6709\u672a\u5b8c\u6210\u7684\u8ba1\u7b97\r\n    waitingForOperand: false \/\/ \u524d\u4e00\u6309\u952e\u662f\u5426\u4e3a\u8ba1\u7b97\u7b26\u53f7  },\r\n\r\n  onLoad: function(options) {    this.calculatorOperations = {      'key-pide': (prevValue, nextValue) =&gt; prevValue \/ nextValue,      'key-multiply': (prevValue, nextValue) =&gt; prevValue * nextValue,      'key-add': (prevValue, nextValue) =&gt; prevValue + nextValue,      'key-subtract': (prevValue, nextValue) =&gt; prevValue - nextValue,      'key-equals': (prevValue, nextValue) =&gt; nextValue\r\n    }\r\n  },  \r\n  \/* AC\u64cd\u4f5c\uff0c\u4e00\u4e0b\u56de\u5230\u89e3\u653e\u524d *\/\r\n  clearAll() {    this.setData({\r\n      value: null,\r\n      displayValue: '0',\r\n      operator: null,\r\n      waitingForOperand: false\r\n    })\r\n  },  \/* \u4ec5\u6e05\u7a7a\u5f53\u524d\u663e\u793a\u7684\u8f93\u5165\u503c *\/\r\n  clearDisplay() {    this.setData({\r\n      displayValue: '0'\r\n    })\r\n  },\r\n\r\n  onTapFunction: function(event) {\r\n    const key = event.target.dataset.key;    switch(key) {      case 'key-clear':        if (this.data.displayValue !== '0') {          this.clearDisplay();\r\n        } else {          this.clearAll();\r\n        }        break;      case 'key-sign':        var newValue = parseFloat(this.data.displayValue) * -1        \r\n        this.setData({\r\n          displayValue: String(newValue)\r\n        })        break;      case 'key-percent':\r\n        const fixedDigits = this.data.displayValue.replace(\/^-?d*.?\/, '')        var newValue = parseFloat(this.data.displayValue) \/ 100        \r\n        this.setData({\r\n          displayValue: String(newValue.toFixed(fixedDigits.length + 2))\r\n        });        break;        \r\n      default:        break;\r\n    }\r\n  },\r\n\r\n  onTapOperator: function(event) {\r\n    const nextOperator = event.target.dataset.key;\r\n    const inputValue = parseFloat(this.data.displayValue);    \r\n    if (this.data.value == null) {      this.setData({\r\n        value: inputValue\r\n      });\r\n    } else if (this.data.operator) {\r\n      const currentValue = this.data.value || 0;\r\n      const newValue = this.calculatorOperations[this.data.operator](currentValue, inputValue);      this.setData({\r\n        value: newValue,\r\n        displayValue: String(newValue)\r\n      });\r\n    }    \r\n    this.setData({\r\n      waitingForOperand: true,\r\n      operator: nextOperator\r\n    });\r\n  },\r\n\r\n  onTapDigit: function(event) {\r\n    const key = event.target.dataset.key; \/\/ \u6839\u636edata-key\u6807\u8bb0\u6309\u952e\r\n\r\n    if(key == 'key-dot') {      \/\/ \u6309\u4e0b\u70b9\u53f7\r\n      if (!(\/.\/).test(this.data.displayValue)) {        this.setData({\r\n          displayValue: this.data.displayValue + '.',\r\n          waitingForOperand: false\r\n        })\r\n      }\r\n    } else {      \/\/ \u6309\u4e0b\u6570\u5b57\u952e\r\n      const digit = key[key.length-1];      if (this.data.waitingForOperand) {        this.setData({\r\n          displayValue: String(digit),\r\n          waitingForOperand: false\r\n        })\r\n      } else {        this.setData({\r\n          displayValue: this.data.displayValue === '0' ? String(digit) : this.data.displayValue + digit\r\n        })\r\n      }\r\n    }\r\n  }\r\n})<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<h2>\u4e09\u3001\u7a0b\u5e8f\u6548\u679c\u56fe<\/h2>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/001\/505\/4ea66f8e0a1e5c0b99ded692e59a566a-2.png\" class=\"aligncenter\" title=\"\u5c0f\u7a0b\u5e8f\u5f00\u53d1\u4e4b\u8ba1\u7b97\u5668\u63d2\u56fe2\" alt=\"\u5c0f\u7a0b\u5e8f\u5f00\u53d1\u4e4b\u8ba1\u7b97\u5668\u63d2\u56fe2\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>\u3010\u76f8\u5173\u63a8\u8350\u3011<\/p>\n<p>1.<\/p>\n<p>2.<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5c0f\u7a0b\u5e8f\u5f00\u53d1\u4e4b\u8ba1\u7b97\u5668\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u8fd9\u7bc7\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u5f00\u53d1\u6559\u7a0b\u4e2d\uff0c\u6211\u4eec\u5c06\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u5f00\u53d1\u8ba1\u7b97\u5668\u529f\u80fd\u3002 \u672c\u6587\u4e3b\u8981\u5206\u4e3a\u4e24\u4e2a\u90e8\u5206\uff0c\u5c0f\u7a0b\u5e8f\u4e3b\u4f53\u90e8\u5206\u53ca\u8ba1\u7b97\u5668\u4e1a\u52a1\u9875\u9762\u90e8\u5206 \u4e00\u3001\u5c0f\u7a0b\u5e8f\u4e3b\u4f53\u90e8\u5206 \u4e00\u4e2a\u5c0f\u7a0b\u5e8f\u4e3b\u4f53\u90e8\u5206\u7531\u4e09\u4e2a\u6587\u4ef6\u7ec4\u6210\uff0c\u5fc5\u987b\u653e\u5728\u9879\u76ee\u7684\u6839\u76ee\u5f55\uff0c\u5982\u4e0b\uff1a 1. \u5c0f\u7a0b\u5e8f\u903b\u8f91 App({ onLaunch: function() { \/\/ Do something initial when launch. }, onShow: function() { \/\/ Do something when show. }, onHide: function() { \/\/ Do something when hide. }, globalData: &#8216;I am global data&#8217;}) \u767b\u5f55\u540e\u590d\u5236 2. \u5c0f\u7a0b\u5e8f\u516c\u5171\u8bbe\u7f6e { &#8220;pages&#8221;: [ &#8220;page\/index\/index&#8221; ], &#8220;window&#8221;: { &#8220;navigationBarBackgroundColor&#8221;: &#8220;#000&#8221;, &#8220;backgroundColor&#8221;: &#8220;#000&#8221;, &#8220;navigationBarBackgroundColor&#8221;: [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19],"tags":[],"class_list":["post-30035","post","type-post","status-publish","format-standard","hentry","category-19"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/30035","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=30035"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/30035\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=30035"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=30035"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=30035"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}