代码:
1、hello.js
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, {
/******/ configurable: false,
/******/ enumerable: true,
/******/ get: getter
/******/ });
/******/ }
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 2);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */,
/* 1 */,
/* 2 */
/***/ (function(module, exports, __webpack_require__) {
var $app_template$ = __webpack_require__(3)
var $app_style$ = __webpack_require__(4)
var $app_script$ = __webpack_require__(5)
$app_define$('@app-component/hello', [], function($app_require$, $app_exports$, $app_module$){
$app_script$($app_module$, $app_exports$, $app_require$)
if ($app_exports$.__esModule && $app_exports$.default) {
$app_module$.exports = $app_exports$.default
}
$app_module$.exports.template = $app_template$
$app_module$.exports.style = $app_style$
})
$app_bootstrap$('@app-component/hello',{ packagerName:'fa-toolkit', packagerVersion: '1.0.4-Stable.300'})
/***/ }),
/* 3 */
/***/ (function(module, exports) {
module.exports = {
"type": "div",
"attr": {},
"classList": [
"container"
],
"children": [
{
"type": "div",
"attr": {},
"children": [
{
"type": "image",
"attr": {
"src": "/Common/cheer.gif",
"show": function () {return this.showCheer}
},
"classList": [
"image-cheer"
]
},
{
"type": "div",
"attr": {},
"classList": [
"item"
],
"children": [
{
"type": "image",
"attr": {
"src": function () {return this.leftExpression}
},
"classList": [
"image-expression"
]
},
{
"type": "image",
"attr": {
"src": function () {return this.imgUser}
},
"classList": [
"image-gesture"
]
}
]
},
{
"type": "text",
"attr": {
"value": "PK"
},
"classList": [
"pk-text"
]
},
{
"type": "div",
"attr": {},
"classList": [
"item"
],
"children": [
{
"type": "image",
"attr": {
"src": function () {return this.rightExpression}
},
"classList": [
"image-expression"
]
},
{
"type": "image",
"attr": {
"src": function () {return this.imgAi}
},
"classList": [
"image-gesture"
]
}
]
}
]
},
{
"type": "text",
"attr": {
"value": function () {return this.btnText}
},
"classList": [
"start-btn"
],
"events": {
"click": "startOrPause"
}
}
]
}
/***/ }),
/* 4 */
/***/ (function(module, exports) {
module.exports = {
".container": {
"flexDirection": "column",
"justifyContent": "center",
"alignContent": "center",
"alignItems": "center"
},
".title": {
"fontSize": "100px"
},
".item": {
"flexDirection": "column",
"justifyContent": "center",
"alignContent": "center",
"alignItems": "center"
},
".image-cheer": {
"position": "fixed",
"marginTop": "0px",
"marginRight": "0px",
"marginBottom": "0px",
"marginLeft": "0px",
"left": "50px",
"right": "50px",
"top": "300px",
"bottom": "300px"
},
".image-expression": {
"width": "100px",
"height": "100px"
},
".image-gesture": {
"marginTop": "50px",
"marginRight": "50px",
"marginBottom": "50px",
"marginLeft": "50px",
"borderRadius": "5px",
"width": "200px",
"height": "188px"
},
".pk-text": {
"fontSize": "50px",
"fontWeight": "bold"
},
".start-btn": {
"marginTop": "50px",
"paddingTop": "10px",
"paddingRight": "10px",
"paddingBottom": "10px",
"paddingLeft": "10px",
"fontSize": "50px",
"fontWeight": "bold"
}
}
/***/ }),
/* 5 */
/***/ (function(module, exports) {
module.exports = function(module, exports, $app_require$){'use strict';
var _system = $app_require$('@app-module/system.audio');
var _system2 = _interopRequireDefault(_system);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
module.exports = {
data: {
title: 'World',
srcs: ['/Common/fist.png', '/Common/scissors.png', '/Common/cloth.png'],
imgAi: '/Common/fist.png',
imgUser: '/Common/scissors.png',
aiNum: 0,
userNum: 1,
started: false,
timer: null,
btnText: '准备喝',
leftExpression: '',
rightExpression: '',
showCheer: false,
result: 0,
audioSrc: '',
t: null
},
onInit: function onInit() {
this.$page.setTitleBar({
text: '小游戏',
textColor: '#ffffff',
backgroundColor: '#007DFF',
backgroundOpacity: 0.5
});
},
startOrPause: function startOrPause() {
if (this.started) {
this.started = false;
if (null !== this.timer) {
clearInterval(this.timer);
}
this.leftExpression = '';
this.rightExpression = '';
this.btnText = '准备喝';
var dif = this.userNum - this.aiNum;
switch (dif) {
case 0:
this.result = 0;
break;
case 1:
this.result = -1;
break;
case 2:
this.result = 1;
break;
case -1:
this.result = 1;
break;
case -2:
this.result = -1;
break;
}
switch (this.result) {
case -1:
this.rightExpression = '/Common/laugh.png';
this.leftExpression = '/Common/cry.png';
this.audioSrc = '/Common/失败.wav';
this.t = setTimeout(function () {
this.audioPause();
}.bind(this), 2000);
break;
case 0:
this.leftExpression = '';
this.rightExpression = '';
this.audioSrc = '/Common/干杯.wav';
this.showCheer = true;
this.t = setTimeout(function () {
this.showCheer = false;
this.audioPause();
}.bind(this), 3000);
break;
case 1:
this.leftExpression = '/Common/laugh.png';
this.rightExpression = '/Common/cry.png';
this.audioSrc = '/Common/奸笑.wav';
this.t = setTimeout(function () {
this.audioPause();
}.bind(this), 2000);
break;
}
this.audioPlay();
} else {
this.started = true;
this.leftExpression = '';
this.rightExpression = '';
clearTimeout(this.t);
this.showCheer = false;
this.audioPause();
this.timer = setInterval(function () {
this.aiNum = parseInt(Math.random() * 3);
this.userNum = parseInt(Math.random() * 3);
this.imgAi = this.srcs[this.aiNum];
this.imgUser = this.srcs[this.userNum];
}.bind(this), 100);
this.btnText = '开始喝';
}
},
audioPlay: function audioPlay() {
_system2.default.src = this.audioSrc;
_system2.default.autoplay = true;
_system2.default.loop = false;
_system2.default.currentTime = 0;
_system2.default.play();
},
audioPause: function audioPause() {
_system2.default.pause();
}
};
var moduleOwn = exports.default || module.exports;
var accessors = ['public', 'protected', 'private'];
if (moduleOwn.data && accessors.some(function (acc) {
return moduleOwn[acc];
})) {
throw new Error('页面VM对象中属性data不可与public, protected, private同时存在,请使用public替代data!');
} else if (!moduleOwn.data) {
moduleOwn.data = {};
moduleOwn._descriptor = {};
accessors.forEach(function(acc) {
var accType = typeof moduleOwn[acc];
if (accType === 'object') {
moduleOwn.data = Object.assign(moduleOwn.data, moduleOwn[acc]);
for (var name in moduleOwn[acc]) {
moduleOwn._descriptor[name] = {access : acc};
}
} else if (accType === 'function') {
console.warn('页面VM对象中的属性' + acc + '的值不能使函数,请使用对象');
}
});
}}
/***/ })
/******/ ]);
2.hello.ux
PK
{{btnText}}