diff --git a/dist/index.html b/dist/index.html index fe3740d..6d6d3dc 100644 --- a/dist/index.html +++ b/dist/index.html @@ -6,7 +6,7 @@ demo - +
@@ -14,5 +14,5 @@
- + diff --git a/dist/index_demo.html b/dist/index_demo.html index 1586abb..6e179d5 100644 --- a/dist/index_demo.html +++ b/dist/index_demo.html @@ -8,7 +8,7 @@ - +
@@ -18,5 +18,5 @@ - + diff --git a/info.json b/info.json index 15c5c3f..237c193 100644 --- a/info.json +++ b/info.json @@ -5,9 +5,9 @@ "title": "star_flash", "ambName": "星星闪烁", "github": "https://github.com/o2team-ambient/star-flash", - "demoSnippet": "\r\n
\r\n \r\n
\r\n ", - "controlUrl": "//storage.jd.com/ambient/control-star_flash.js?t=1557058666000", - "configUrl": "//storage.jd.com/ambient/config-star_flash.js?t=1557058666000", + "demoSnippet": "\n
\n \n
\n ", + "controlUrl": "//storage.jd.com/ambient/control-star_flash.js?t=1567588173000", + "configUrl": "//storage.jd.com/ambient/config-star_flash.js?t=1567588173000", "placeholderImg": "//storage.jd.com/ambient/star-flash_placeholder.png?t=1557049231000", "spriteImg": "//storage.jd.com/ambient/star-flash_sprite.png?t=1557049231000" } diff --git a/package.json b/package.json index 819d819..d651328 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,8 @@ "author": "src", "license": "ISC", "dependencies": { - "@o2team/ambient-dat.gui": "^0.7.9", + "@o2team/ambient-dat.gui": "^0.7.14", + "@o2team/ambient-report": "^1.0.5", "@tweenjs/tween.js": "^17.3.0" }, "devDependencies": { diff --git a/src/index.js b/src/index.js index b0fd721..90d25e2 100644 --- a/src/index.js +++ b/src/index.js @@ -1,6 +1,7 @@ import './css/base.scss' import './css/package.scss' +import Report from '@o2team/ambient-report' import { O2_AMBIENT_CONFIG } from './js/utils/const' import initAmbient from './js/ambient' @@ -14,3 +15,14 @@ try { } catch (e) { console.log(e) } + +const handleReport = () => { + Report.init({}) + Report.processPV(38) +} + +if (typeof window.XView === 'undefined') { + handleReport() +} else { + window.handleReport = handleReport +} diff --git a/src/js/animate.js b/src/js/animate.js index fd7be23..2d89a0f 100644 --- a/src/js/animate.js +++ b/src/js/animate.js @@ -41,7 +41,7 @@ class Animate{ const { canvas } = this canvas.setAttribute('width', width) canvas.setAttribute('height', height) - canvas.style.background = '#000' + // canvas.style.background = '#000' } setProps () { diff --git a/src/js/configs/keys.js b/src/js/configs/keys.js new file mode 100644 index 0000000..ce3ee8b --- /dev/null +++ b/src/js/configs/keys.js @@ -0,0 +1,3 @@ +export default { + default: '默认' +} diff --git a/src/js/controlinit.js b/src/js/controlinit.js index 6ee25a3..7a1d24d 100644 --- a/src/js/controlinit.js +++ b/src/js/controlinit.js @@ -5,19 +5,32 @@ import dat from '@o2team/ambient-dat.gui' import { - O2_AMBIENT_MAIN + O2_AMBIENT_MAIN, + O2_AMBIENT_CONFIG, + O2_AMBIENT_CLASSNAME } from './utils/const' import Controller from './utils/controller' import { getParameterByName } from './utils/util' +import processLocalConfig from './utils/processLocalConfig' + +import configKeys from './configs/keys' /* eslint-disable no-unused-vars */ const isLoop = getParameterByName('loop') +const configKeyVal = getParameterByName('configKey') +const configKey = configKeys[configKeyVal] || configKeys['default'] + +const loadData = { + '默认': { + '0': {...window[O2_AMBIENT_CONFIG]} + } +} +const allLoadData = processLocalConfig({ configKey, guiName: O2_AMBIENT_CLASSNAME, loadData }) let controlInit = () => { // 非必要配置字段(仅用于展示,如背景颜色、启动/暂停) class OtherConfig { constructor () { - this.message = '星梦' this.backgroundColor = '#000' this.play = () => { if (!window[O2_AMBIENT_MAIN] || !window[O2_AMBIENT_MAIN].toggle || typeof window[O2_AMBIENT_MAIN].toggle !== 'function') return @@ -40,10 +53,16 @@ let controlInit = () => { // demo code const config = this.config const otherConfig = this.otherConfig - const gui = new dat.GUI() + const gui = new dat.GUI({ + name: O2_AMBIENT_CLASSNAME, + preset: configKey, + load: { + 'remembered': { ...allLoadData.remembered } + } + }) + gui.remember(config) gui.addCallbackFunc(this.resetCanvas.bind(this)) - gui.add(otherConfig, 'message').name('配梦板') gui.add(otherConfig, 'play').name('梦起 / 梦停') gui.add(config, 'layoutType', { '半遮面': 'curtain', diff --git a/src/js/utils/processLocalConfig.js b/src/js/utils/processLocalConfig.js new file mode 100644 index 0000000..8fb77c0 --- /dev/null +++ b/src/js/utils/processLocalConfig.js @@ -0,0 +1,25 @@ +/** + * 处理 localStorage 配置 + * @param {object} opts + * @param {string} opts.configKey 当前 configKey 值 + * @param {string} opts.guiName localStorage 前缀 + * @param {object} opts.loadData 官方配置数据 + */ + +export default function ({ configKey = '', guiName = '', loadData = {} }) { + const localData = JSON.parse(localStorage.getItem(`${guiName || document.location.href}.gui`)) + + if (!localData) return { remembered: { ...loadData } } + + if (localData.preset) { + localData.preset = configKey + } + + if (localData.remembered) { + localData.remembered = { ...localData.remembered, ...loadData } + } + + localStorage.setItem(`${guiName || document.location.href}.gui`, JSON.stringify(localData)) + + return localData +}