Commit 07abf962 authored by rockyl's avatar rockyl

更新

parent 1a619360
This diff is collapsed.
This diff is collapsed.
{"id":"engine","url":"engine.c62a7b1e88c4bcbbf86609a9b9fe3c2fd353dad2.js"}
\ No newline at end of file
{"id":"engine","url":"engine.8dfca05a06aaf603e4af896d987e7fb60c5f5077.js"}
\ No newline at end of file
function getPxToken(n){if(window.ohjaiohdf){var o=new XMLHttpRequest;o.open("get","getToken",!0),o.onreadystatechange=function(){if(4===o.readyState&&200===o.status){var e=JSON.parse(o.response);if(e.success)window.eval(e.data),n(null,window.ohjaiohdf());else switch(e.code){case"100001":n("need login");break;case"100024":n("state invalid");break;default:n(e.code)}}},o.onerror=function(e){t()},o.onloadend=function(){404===o.status&&t()},o.send()}else n("need login");function t(){n("net error")}}
\ No newline at end of file
......@@ -467,14 +467,7 @@ export default class Container extends DisplayObject {
}
}
let widthSetted = !!this._width && this._width !== 0;
let heightSetted = !!this._height && this._height !== 0;
if (widthSetted) {
this._bounds.width = this._width;
}
if (heightSetted) {
this._bounds.height = this._height;
}
}
/**
......@@ -482,6 +475,28 @@ export default class Container extends DisplayObject {
*/
protected _calculateBounds() {
//子类自己重写
//let wp = this.worldMatrix.transformPoint(this.x, this.y);
let widthSetted = !!this._width && this._width !== 0;
let heightSetted = !!this._height && this._height !== 0;
/*if (widthSetted) {
this._bounds.x = this.x;
this._bounds.width = this._width;
}
if (heightSetted) {
this._bounds.y = this.y;
this._bounds.height = this._height;
}*/
if(widthSetted || heightSetted){
const rect = this._localBoundsSelf;
var matrix = this.transform.worldMatrix;
matrix.transformPoint(rect.x, rect.y, DisplayObject._p1);
matrix.transformPoint(rect.x + rect.width, rect.y, DisplayObject._p2);
matrix.transformPoint(rect.x + rect.width, rect.y + rect.height, DisplayObject._p3);
matrix.transformPoint(rect.x, rect.y + rect.height, DisplayObject._p4);
Rectangle.createFromPoints(this._bounds, DisplayObject._p1, DisplayObject._p2, DisplayObject._p3, DisplayObject._p4);
}
}
/**
......@@ -492,8 +507,9 @@ export default class Container extends DisplayObject {
//如果不可见
if (!this.visible) return null
//如果禁止子级的鼠标事件
let result = this.hitTestSelf(globalPoint);
if (isMouseEvent && !this.mouseChildren) return result;
if (isMouseEvent && !this.mouseChildren){
return this.hitTestSelf(globalPoint);
}
var children = this.children;
var length = children.length;
let child, hitDisplayObject;
......@@ -510,7 +526,7 @@ export default class Container extends DisplayObject {
if (hitDisplayObject) return hitDisplayObject;
}
return this.hitTestSelf(globalPoint);
return this.displayObjectHitTestPoint(globalPoint, isMouseEvent);
}
hitTestSelf(globalPoint) {
......@@ -521,8 +537,9 @@ export default class Container extends DisplayObject {
}
hitTestSelfBounds(globalPoint) {
if (this.width && this.height) {
let {x: tx, y: ty} = this.getBounds();
if (this._width && this._height) {
//let {x: tx, y: ty} = this.getBounds();
let {tx, ty} = this.worldMatrix;
const {x, y} = globalPoint;
if (x > tx &&
x < tx + this.width &&
......@@ -701,6 +718,7 @@ export default class Container extends DisplayObject {
if (this._width !== value) {
//子类有用,有_width,才需设置scaleX
this._width = value;
this._localBoundsSelf.width = value;
//if (this.stage) this.stage.layoutInvalid = true;
this.dispatchEvent(Event.RESIZE);
}
......@@ -724,6 +742,7 @@ export default class Container extends DisplayObject {
// }
if (this._height !== value) {
this._height = value;
this._localBoundsSelf.height = value;
//if (this.stage) this.stage.layoutInvalid = true;
this.dispatchEvent(Event.RESIZE);
}
......
......@@ -280,6 +280,10 @@ export class DisplayObject extends EventDispatcher {
this.parent = parentRef;
this.transform = transformRef;
if (this.parent && this.stage) {
this.updateTransform();
}
return bounds;
}
......@@ -609,7 +613,7 @@ export class DisplayObject extends EventDispatcher {
}
set mask(value) {
if(value === this){
if (value === this) {
return;
}
if (this.$mask) {
......
This diff is collapsed.
import { calculatePlaneIndices } from './Plane';
import { Texture } from '../texture';
import CanvasRenderer from '../renderers/CanvasRenderer';
import { Mesh } from './Mesh';
//提前计算好的索引
const indicesNN = calculatePlaneIndices(4, 4)
/**
* 九宫格
*```js
* let Plane9 = new NineSlicePlane(Texture.fromUrl('BoxWithRoundedCorners.png'), 15, 15, 15, 15);
* ```0,1,3,5,7,8,16,24,都是0
*
* 0...1...2...3
* . . . .
* 4...5...6...7
* . . . .
* 8...9...10..11
* . . . .
* 12..13..14..15
* <pre>
* A B
* +---+----------------------+---+
* C | 1 | 2 | 3 |
* +---+----------------------+---+
* | | | |
* | 4 | 5 | 6 |
* | | | |
* +---+----------------------+---+
* D | 7 | 8 | 9 |
* +---+----------------------+---+
* 当修改宽高width height时,不再改变scale属性
* 1 3 7 9 永远不变
* 2 8 只会水平横向拉伸
* 4 6 只会垂直纵向拉伸
* 5 都会拉伸
* </pre>
*
*
*/
export class NineSlicePlane extends Mesh {
/**
* 宽高get set都重写,不再修改缩放,修改uv和顶点
*/
get width(): number {
return this._width;
}
set width(value: number) {
this._width = value;
this._needRefresh = true;
}
get height(): number {
return this._height;
}
set height(value: number) {
this._height = value;
this._needRefresh = true;
}
/**
* 原始宽度
*/
private _origWidth: number;
/**
* 原始高度
*/
private _origHeight: number;
/**
* 左边宽度
*/
private _leftWidth: number;
get leftWidth(): number {
return this._leftWidth;
}
set leftWidth(value: number) {
this._leftWidth = value;
this._needRefresh = true;
}
/**
* 右边宽度
*/
private _rightWidth: number;
get rightWidth(): number {
return this._rightWidth;
}
set rightWidth(value: number) {
this._rightWidth = value;
this._needRefresh = true;
}
/**
* 上边高度
*/
private _topHeight: number;
get topHeight(): number {
return this._topHeight;
}
set topHeight(value: number) {
this._topHeight = value;
this._needRefresh = true;
}
/**
* 下边高度
*/
private _bottomHeight: number;
get bottomHeight(): number {
return this._bottomHeight;
}
set bottomHeight(value: number) {
this._bottomHeight = value;
this._needRefresh = true;
}
/**
* @param {Texture} texture
* @param {number} [leftWidth=10]
* @param {number} [topHeight=10]
* @param {number} [rightWidth=10]
* @param {number} [bottomHeight=10]
*/
constructor(texture: Texture, leftWidth: number = 10, topHeight: number = 10, rightWidth: number = 10, bottomHeight: number = 10) {
super(texture);
//考虑对于未加载好的图片怎么处理吧,肯定需要加在onTextureUpdate的
this._origWidth = texture.orig.width;
this._origHeight = texture.orig.height;
this._width = this._origWidth;
this._height = this._origHeight;
this._leftWidth = leftWidth;
this._rightWidth = rightWidth;
this._topHeight = topHeight;
this._bottomHeight = bottomHeight;
//计算索引,完全不用变,所以提前计算
this._indices = indicesNN;
//顶点数量长度可以确定先
this._vertices = new Float32Array(4 * 4 * 2);
//uv长度也可以确定先
this._uvs = new Float32Array(4 * 4 * 2);
this.refresh(true);
}
/**
* 额外增加修改原始宽高
*/
protected _onTextureUpdate() {
super._onTextureUpdate();
this._origWidth = this.texture.orig.width;
this._origHeight = this.texture.orig.height;
}
/**
* 计算横向顶点
*/
private updateHorizontalVertices() {
const vertices = this._vertices;
const h = this._topHeight + this._bottomHeight;
const scale = this._height > h ? 1.0 : this._height / h;
vertices[9] = vertices[11] = vertices[13] = vertices[15] = this._topHeight * scale;
vertices[17] = vertices[19] = vertices[21] = vertices[23] = this._height - (this._bottomHeight * scale);
vertices[25] = vertices[27] = vertices[29] = vertices[31] = this._height;
}
/**
* 计算纵向顶点
*/
private updateVerticalVertices() {
const vertices = this._vertices;
const w = this._leftWidth + this._rightWidth;
const scale = this._width > w ? 1.0 : this._width / w;
vertices[2] = vertices[10] = vertices[18] = vertices[26] = this._leftWidth * scale;
vertices[4] = vertices[12] = vertices[20] = vertices[28] = this._width - (this._rightWidth * scale);
vertices[6] = vertices[14] = vertices[22] = vertices[30] = this._width;
}
/**
*
* 考虑是否用缓存,不然每次相当于9次绘制,到时应该是集成到一个插件里的
* @private
* @param {CanvasRenderer} renderer
*/
_renderCanvas(renderer: CanvasRenderer) {
const context = renderer.context;
context.globalAlpha = this._worldAlpha;
renderer.setBlendMode(this.blendMode);
const transform = this.worldMatrix;
context.setTransform(
transform.a,
transform.b,
transform.c,
transform.d,
transform.tx,
transform.ty
);
const base = this.texture.baseTexture;
const textureSource = base.source;
const w = base.width;
const h = base.height;
this.drawSegment(context, textureSource, w, h, 0, 1, 10, 11);
this.drawSegment(context, textureSource, w, h, 2, 3, 12, 13);
this.drawSegment(context, textureSource, w, h, 4, 5, 14, 15);
this.drawSegment(context, textureSource, w, h, 8, 9, 18, 19);
this.drawSegment(context, textureSource, w, h, 10, 11, 20, 21);
this.drawSegment(context, textureSource, w, h, 12, 13, 22, 23);
this.drawSegment(context, textureSource, w, h, 16, 17, 26, 27);
this.drawSegment(context, textureSource, w, h, 18, 19, 28, 29);
this.drawSegment(context, textureSource, w, h, 20, 21, 30, 31);
}
/**
* 分部画
* 每部分保证至少有1像素
* @private
* @param {CanvasRenderingContext2D} context
* @param {CanvasImageSource} textureSource - 图片资源
* @param {number} w - 贴图宽
* @param {number} h - 贴图高
* @param {number} x1 - x index 1
* @param {number} y1 - y index 1
* @param {number} x2 - x index 2
* @param {number} y2 - y index 2
*/
private drawSegment(
context: CanvasRenderingContext2D,
textureSource: HTMLImageElement | HTMLCanvasElement,
w: number,
h: number,
x1: number,
y1: number,
x2: number,
y2: number
) {
const uvs = this._uvs;
const vertices = this._vertices;
let sw = (uvs[x2] - uvs[x1]) * w;
let sh = (uvs[y2] - uvs[y1]) * h;
let dw = vertices[x2] - vertices[x1];
let dh = vertices[y2] - vertices[y1];
//绘制源保证至少有一像素
if (sw < 1) sw = 1;
if (sh < 1) sh = 1;
//绘制体保证至少一像素
if (dw < 1) dw = 1;
if (dh < 1) dh = 1;
context.drawImage(textureSource, uvs[x1] * w, uvs[y1] * h, sw, sh, vertices[x1], vertices[y1], dw, dh);
}
/**
* 计算所有坐标
*/
_refresh() {
const uvs = this._uvs;
const texture = this.texture;
this._origWidth = texture.orig.width;
this._origHeight = texture.orig.height;
const _uvw = 1.0 / this._origWidth;
const _uvh = 1.0 / this._origHeight;
uvs[0] = uvs[8] = uvs[16] = uvs[24] = 0;
uvs[1] = uvs[3] = uvs[5] = uvs[7] = 0;
uvs[6] = uvs[14] = uvs[22] = uvs[30] = 1;
uvs[25] = uvs[27] = uvs[29] = uvs[31] = 1;
uvs[2] = uvs[10] = uvs[18] = uvs[26] = _uvw * this._leftWidth;
uvs[4] = uvs[12] = uvs[20] = uvs[28] = 1 - (_uvw * this._rightWidth);
uvs[9] = uvs[11] = uvs[13] = uvs[15] = _uvh * this._topHeight;
uvs[17] = uvs[19] = uvs[21] = uvs[23] = 1 - (_uvh * this._bottomHeight);
this.updateHorizontalVertices();
this.updateVerticalVertices();
this._vertexDirty++;
this.multiplyUvs();
}
}
import { Mesh } from './Mesh';
import { Texture } from '../texture';
/**
* 根据分段数的平面
* verticesX和verticesY都是xy轴上的顶点数,比分段数多1
*
*/
export class Plane extends Mesh {
/**
* x轴顶点数目
*/
private _verticesX: number;
get verticesX(): number {
return this._verticesX
}
set verticesX(value: number) {
if (this._verticesX !== value) {
this._verticesX = value
this._needRefresh = true;
}
}
/**
* y轴顶点数目
*/
private _verticesY: number;
get verticesY(): number {
return this._verticesY
}
set verticesY(value: number) {
if (this._verticesY !== value) {
this._verticesY = value
this._needRefresh = true;
}
}
/**
* @param {Texture} texture
* @param {int} [verticesX=10]
* @param {int} [verticesY=10]
*/
constructor(texture: Texture, verticesX: number = 10, verticesY: number = 10) {
super(texture);
this._verticesX = verticesX;
this._verticesY = verticesY;
this.refresh();
}
/**
* 计算所有坐标
*/
_refresh() {
const texture = this.texture;
const total = this.verticesX * this.verticesY;
const verts = [];
const uvs = [];
const segmentsX = this.verticesX - 1;
const segmentsY = this.verticesY - 1;
const sizeX = texture.width / segmentsX;
const sizeY = texture.height / segmentsY;
for (let i = 0; i < total; i++) {
const x = (i % this.verticesX);
const y = ((i / this.verticesX) | 0);
verts.push(x * sizeX, y * sizeY);
uvs.push(x / segmentsX, y / segmentsY);
}
this._vertices = new Float32Array(verts);
this._uvs = new Float32Array(uvs);
this._indices = calculatePlaneIndices(this.verticesX, this.verticesY);
//标记dirty
this._vertexDirty++;
this.multiplyUvs();
}
}
/**
* 计算平面的索引
* @param verticesX x轴上的顶点数量,最小2
* @param verticesY y轴上的顶点数量,最小2
*/
export function calculatePlaneIndices(verticesX: number, verticesY: number): Uint16Array {
const segmentsX = verticesX - 1;
const segmentsY = verticesY - 1;
const totalSub = segmentsX * segmentsY;
const indices = [];
for (let i = 0; i < totalSub; i++) {
const xpos = i % segmentsX;
const ypos = (i / segmentsX) | 0;
const value = (ypos * verticesX) + xpos;
const value2 = (ypos * verticesX) + xpos + 1;
const value3 = ((ypos + 1) * verticesX) + xpos;
const value4 = ((ypos + 1) * verticesX) + xpos + 1;
indices.push(value, value2, value3);
indices.push(value2, value4, value3);
}
return new Uint16Array(indices);
}
import { Mesh } from './Mesh';
import { Texture } from '../texture';
import { Point } from '../math';
/**
* 为了能加入批处理,不用TRIANGLE_STRIP方式渲染(有需要看v4版本的pixi),还是用TRIANGLE
*```js
* for (let i = 0; i < 20; i++) {
* points.push(new Point(i * 50, 0));
* };
* let rope = new Rope(Texture.fromUrl("snake.png"), points);
* ```
*
*
*/
export class Rope extends Mesh {
/**
* 一组点
*/
points: Point[];
/**
* 是否自动更新顶点,为true,自动更新顶点,否则在points里顶点修改后,自行refreshVertices
*/
autoUpdateVertices: boolean;
/**
* 以横向的为基准,纹理高度
*/
private textureHeight: number;
/**
* @param {Texture} texture
* @param {Point[]} points
*/
constructor(texture: Texture, points: Point[]) {
super(texture);
this.points = points;
this._vertices = new Float32Array(points.length * 4);
this._uvs = new Float32Array(points.length * 4);
this._indices = new Uint16Array((points.length - 1) * 6);
this.textureHeight = texture.height;
this.refresh(true);
this.refreshVertices();
}
/**
* 计算索引和uv,和顶点计算的要分开
*/
_refresh() {
const points = this.points;
//没点,或贴图uv为空
if (points.length < 1 || !this.texture._uvs) return;
//如果顶点数量有变
if (this._vertices.length / 4 !== points.length) {
this._vertices = new Float32Array(points.length * 4);
this._uvs = new Float32Array(points.length * 4);
this._indices = new Uint16Array((points.length - 1) * 6);
}
const uvs = this._uvs;
const indices = this._indices;
uvs[0] = 0;
uvs[1] = 0;
uvs[2] = 0;
uvs[3] = 1;
// indices[0] = 0;
// indices[1] = 1;
const total = points.length;
for (let i = 1; i < total; i++) {
// time to do some smart drawing!
let index = i * 4;
const amount = i / (total - 1);
uvs[index] = amount;
uvs[index + 1] = 0;
uvs[index + 2] = amount;
uvs[index + 3] = 1;
}
let indexCount = 0;
for (let i = 0; i < total - 1; i++) {
const index = i * 2;
indices[indexCount++] = index;
indices[indexCount++] = index + 1;
indices[indexCount++] = index + 2;
indices[indexCount++] = index + 2;
indices[indexCount++] = index + 1;
indices[indexCount++] = index + 3;
}
this.multiplyUvs();
// this.refreshVertices();
}
/**
* 根据points刷新顶点
*/
refreshVertices() {
const points = this.points;
//
if (points.length < 1) return;
//如果points数量修改过,去执行_refresh
if (this._vertices.length / 4 !== points.length) {
this._refresh();//里面肯定会把_vertices的长度矫正
this.refreshVertices();
return;
}
let lastPoint = points[0];
let nextPoint;
let perpX = 0;
let perpY = 0;
// this.count -= 0.2;
const vertices = this._vertices;
const total = points.length;
for (let i = 0; i < total; i++) {
const point = points[i];
const index = i * 4;
if (i < points.length - 1) {
nextPoint = points[i + 1];
}
else {
nextPoint = point;
}
perpY = -(nextPoint.x - lastPoint.x);
perpX = nextPoint.y - lastPoint.y;
let ratio = (1 - (i / (total - 1))) * 10;
if (ratio > 1) {
ratio = 1;
}
const perpLength = Math.sqrt((perpX * perpX) + (perpY * perpY));
const num = this.textureHeight / 2; // (20 + Math.abs(Math.sin((i + this.count) * 0.3) * 50) )* ratio;
perpX /= perpLength;
perpY /= perpLength;
perpX *= num;
perpY *= num;
vertices[index] = point.x + perpX;
vertices[index + 1] = point.y + perpY;
vertices[index + 2] = point.x - perpX;
vertices[index + 3] = point.y - perpY;
lastPoint = point;
}
//标记修改
this._vertexDirty++;
}
update() {
super.update();
//自动更新顶点,或者纹理高度有修改
if (this.autoUpdateVertices || this.textureHeight !== this.texture.height) {
this.textureHeight = this.texture.height
this.refreshVertices();
}
}
}
export * from "./Mesh"
export * from "./NineSlicePlane"
export * from "./Plane"
export * from "./Rope"
\ No newline at end of file
......@@ -2,7 +2,7 @@
* Created by rockyl on 2019-11-22.
*/
import {injectProperties, obj2query} from "../zeroing/utils";
import {injectProperties, obj2query} from "../zeroing/utils/index";
import {queryParams} from "../zeroing/web";
/**
......
This diff is collapsed.
......@@ -271,7 +271,7 @@ export class ScrollViewBase extends Container {
}
protected calMaxDistance(){
return this.viewPort[this.paramSize];
return this.viewPort[this.paramSize] + this.viewPort.getLocalBounds()[this.paramXY]
}
get direction(): SCROLL_DIRECTION {
......
......@@ -15,8 +15,8 @@ import {Toast} from "./Toast";
import {arrayFind} from "../utils/index";
import {Node} from "./nodes/Node";
import {bind, createStore} from "./mvvm/index";
import {safeEval} from "../utils/utils";
import {registerCustomModules} from "./custom-module";
import {dealPageRemainTime, dealPxEnv} from "../px-logics";
/**
* 游戏舞台
......@@ -129,6 +129,9 @@ export class GameStage extends Node {
this.start();
dealPxEnv();
dealPageRemainTime();
onStart && onStart();
function p() {
......@@ -185,7 +188,7 @@ export class GameStage extends Node {
view = instantiate(viewConfig);
let store = {};
if(viewConfig.store){
if (viewConfig.store) {
const {exp, computed} = viewConfig.store;
store = createStore(exp, computed);
}
......
......@@ -2,7 +2,7 @@
* Created by rockyl on 2019-11-21.
*/
export let env = {};
export let env:any = {};
export function injectEnv(data){
if(data){
......
......@@ -25,4 +25,29 @@ export class HtmlView extends FloatDisplay implements IUIComponent{
afterConstructor() {
}
get $store() {
let p = this;
do {
if (p['$isViewRoot']) {
break;
}
p = p.parent;
}
while (p.parent);
if (p) {
return p['$_store'];
}
}
/**
* 根据uuid搜索子节点
* @param uuid
*/
findChildByUUID(uuid: string) {
if (this['uuid'] === uuid) {
return this;
}
}
}
......@@ -15,6 +15,8 @@ const assetScheme = 'asset://';
export class Image extends Sprite implements IUIComponent {
isUI = true;
crossOrigin = true;
private _originText;
private _escapes = [];
private _registeredEvents = [];
......@@ -49,7 +51,7 @@ export class Image extends Sprite implements IUIComponent {
url = assetConfig.uuid;
}
}
this.texture = Texture.fromImage(url);
this.texture = Texture.fromImage(url, this.crossOrigin);
} else {
this.texture = null;
}
......
......@@ -258,7 +258,7 @@ export class TextInput extends Label implements IUIComponent {
private onClickStatic() {
this.setFocus();
this.stage.once(MouseEvent.CLICK, this.onClickStage, this);
this.stage.once(MouseEvent.MOUSE_DOWN, this.onClickStage, this);
}
private onResize() {
......
......@@ -11,6 +11,7 @@ export * from './game-warpper'
export * from './behavior-runtime'
export * from './web'
export * from './log-switch'
export {cleanNewUser, accessLog} from './px-logics'
import {instantiate, registerNodeType} from './game-warpper/view-interpreter'
export {Howl, Howler} from 'howler';
......
/**
* Created by rockyl on 2020-04-07.
*
* 星速台环境变量处理
*/
import {env} from "./game-warpper/enviroment";
import {queryParams} from "./web";
import {httpRequest} from "../2d/net";
import {injectProp} from "./utils/utils";
export function dealPxEnv() {
//appID提取
if (queryParams.appID) {
env.appID = queryParams.appID;
}
//渠道类型提取
if (queryParams.channelType) {
env.channelType = queryParams.channelType;
}
//projectID提取
if (queryParams.projectID) {
env.projectID = queryParams.projectID;
} else {
let result = window.location.pathname.match(/\/projectx\/(.*?)\/.*?/);
if (result) {
env.projectID = result[1];
}
}
//是否是分享回流
if (queryParams.is_from_share) {
env.fromShare = true;
}
//新用户标记提取
let newUser = true;
let key = 'nu_' + env.appID + '_' + env.projectID;
let v = localStorage.getItem(key);
if (v) {
newUser = false;
} else {
localStorage.setItem(key, '1');
}
env.newUser = newUser;
if (window['isSharePage']) {
accessLog(506);
}
}
export function cleanNewUser(){
let key = 'nu_' + env.appID + '_' + env.projectID;
localStorage.removeItem(key);
}
export function dealPageRemainTime() {
let startTimer = new Date().getTime();
let endTimer;
//设置隐藏属性和改变可见属性的事件的名称
let visibilityChange;
if (typeof document.hidden !== 'undefined') {
visibilityChange = 'visibilitychange';
} else if (typeof document['msHidden'] !== 'undefined') {
visibilityChange = 'msvisibilitychange';
} else if (typeof document['webkitHidden'] !== 'undefined') {
visibilityChange = 'webkitvisibilitychange';
}
const handleVisibilityChange = (e) => {
if (document.visibilityState == "visible") {
startTimer = new Date().getTime();
//console.log('starttimer', startTimer)
}
if (document.visibilityState == "hidden") {
endTimer = new Date().getTime();
//console.log('endTimer', endTimer);
sendData();
}
};
const sendData = () => {
const t0 = endTimer - startTimer;
//console.log('duration', t0);
accessLog(156, {
remain: t0,
});
};
document.addEventListener(
visibilityChange,
handleVisibilityChange,
false
);
document.body['onbeforeunload'] = () => {
endTimer = new Date().getTime();
return sendData();
}
}
export function accessLog(pagebizid, params?) {
let p = {
pagebizid,
};
injectProp(p, params);
return httpRequest('buriedPoint', 'get', p);
}
......@@ -15,3 +15,24 @@ for (let item of search.replace('?', '').split('&')) {
queryParams[arr[0]] = arr.length === 1 ? true : arr[1];
}
/**
* 添加一个script
* @param script
* @param parent
*/
export function appendScript(script, parent = document.body) {
if(!script){
return;
}
let scriptContent;
if (script.indexOf('<script') === 0) {
let temp = document.createElement('div');
temp.innerHTML = script;
scriptContent = temp.children[0].innerHTML;
} else {
scriptContent = script;
}
let scriptEl = document.createElement('script');
scriptEl.innerHTML = scriptContent;
parent.appendChild(scriptEl);
}
This diff is collapsed.
......@@ -7,8 +7,6 @@
"removeComments": true,
"noEmitOnError": true,
"noEmitHelpers": true,
"declarationDir": "types",
"declaration": true,
"experimentalDecorators": true,
"outDir": "dist-m",
"lib": [
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment