537 lines
13 KiB
Vue
Raw Normal View History

2019-03-15 10:08:39 +08:00
<template>
2021-04-04 15:42:16 +08:00
<div id="ui-prop">
2021-06-15 22:19:47 +08:00
<div class="normal-data" style="display: flex;flex-direction: row;align-items: center;min-height: 30px;margin: 0;">
2021-06-17 22:35:37 +08:00
<div @mousedown="onPropNameMouseDown" class="key"
@click="onClickFold"
:style="{'cursor':isArrayOrObject()?'pointer':''}"
>
<i class="data-arrow"
2021-06-15 22:19:47 +08:00
v-if="arrow"
:class="fold?'el-icon-caret-right':'el-icon-caret-bottom'"
2021-06-17 22:35:37 +08:00
:style="{'visibility':isArrayOrObject()?'visible':'hidden','margin-left':indent*10+'px'}">
2021-06-17 21:37:09 +08:00
</i>
2021-11-06 20:43:45 +08:00
<div class="text" ref="propText">
<el-popover placement="top" trigger="hover" :disabled="!isShowTooltip()">
<div>{{ name }}</div>
<span slot="reference">{{ name }}</span>
</el-popover>
</div>
2021-04-04 15:42:16 +08:00
</div>
2021-06-15 22:19:47 +08:00
<div class="value">
2021-11-06 21:42:37 +08:00
<div v-if="isInvalid()" class="invalid">
2021-11-07 00:09:02 +08:00
{{ value.data }}
2021-11-06 21:42:37 +08:00
</div>
2021-06-15 22:19:47 +08:00
<el-input v-if="isString()" v-model="value.data"
:disabled="value.readonly"
@change="onChangeValue">
</el-input>
<el-input v-if="isText()"
type="textarea"
:autosize="{minRows:3,maxRows:5}"
placeholder="请输入内容"
:disabled="value.readonly"
@change="onChangeValue"
v-model="value.data">
</el-input>
<el-input-number v-if="isNumber()"
style="width: 100%;text-align: left"
v-model="value.data"
:step="step"
:disabled="value.readonly"
@change="onChangeValue"
controls-position="right"
></el-input-number>
<div v-if="isVec2()||isVec3()" class="vec">
<ui-prop v-for="(vec, index) in value.data"
2021-04-04 15:42:16 +08:00
:key="index"
2021-06-15 22:19:47 +08:00
:arrow="false"
:value="vec.value"
:name="vec.name">
</ui-prop>
</div>
<el-select v-model="value.data"
2021-05-08 20:36:32 +08:00
:disabled="value.readonly"
2021-06-15 22:19:47 +08:00
v-if="isEnum()" style="width: 100%;"
2021-05-08 20:36:32 +08:00
@change="onChangeValue">
2021-06-15 22:19:47 +08:00
<el-option v-for="(opt, index) in value.values"
:key="index"
:label="opt.name"
:value="opt.value">
</el-option>
</el-select>
<el-checkbox v-model="value.data"
v-if="isBool()"
:disabled="value.readonly"
@change="onChangeValue">
</el-checkbox>
<div class="color" v-if="isColor()">
<el-color-picker style="position: absolute;"
:disabled="value.readonly"
v-model="value.data" @change="onChangeValue">
</el-color-picker>
<div class="hex" :style="{color:colorReverse(value.data)}">{{ value.data }}</div>
2021-04-06 18:41:54 +08:00
</div>
2021-06-15 22:19:47 +08:00
<!-- <div v-if="isArrayOrObject()" class="array-object">-->
<!-- <div class="text">-->
<!-- </div>-->
<!-- <el-button @click="onShowValueInConsole">log</el-button>-->
<!-- </div>-->
<div v-if="isImage()" class="image-property">
<el-popover v-if="isImage()" placement="top" trigger="hover">
<div
style="width: 100%;height: 100%;display: flex;flex-direction: row;align-items: center;justify-content: center;">
<img :src="value.data" alt="图片" style="max-width: 100px;max-height: 100px;object-fit: contain;">
</div>
<img :src="value.data" slot="reference" style="height: 36px;" alt="图片">
</el-popover>
<div style="flex:1;display: flex; flex-direction: row-reverse;">
<el-button @click="onShowValueInConsole">log</el-button>
2021-06-15 20:51:19 +08:00
</div>
2021-06-15 22:19:47 +08:00
</div>
2021-06-19 19:51:05 +08:00
<div v-if="isEngine()" class="engine">
<div class="head">
<i class="icon" :class="getEngineTypeIcon()"></i>
<div class="type">{{ value.engineType }}</div>
</div>
<div class="name">{{ value.engineName }}</div>
<el-button @click="onPlaceInTree" type="primary" icon="el-icon-place"></el-button>
</div>
2021-11-06 21:14:38 +08:00
<div v-if="isObject()&&fold" class="objectDesc">
2021-11-06 20:19:21 +08:00
{{ value.data }}
</div>
2021-11-06 21:14:38 +08:00
<div v-if="isArray()" class="array">
Array({{ value.data.length }})
</div>
<div class="slot" v-if="false">
2021-06-15 22:19:47 +08:00
<slot></slot>
2021-06-14 19:41:58 +08:00
</div>
2021-04-06 18:41:54 +08:00
</div>
2021-06-15 22:19:47 +08:00
</div>
2021-06-17 22:35:37 +08:00
<div v-if="isArrayOrObject()">
2021-11-06 20:19:21 +08:00
<div v-show="!fold&&subData" style="display: flex;flex-direction: column;">
<ui-prop v-for="(arr,index) in subData"
2021-06-15 22:19:47 +08:00
:key="index"
:indent="indent+1"
:value="arr.value"
2021-06-17 22:35:37 +08:00
:name="getName(isArray(),arr)"
>
2021-06-15 22:19:47 +08:00
</ui-prop>
2019-03-15 10:08:39 +08:00
</div>
</div>
</div>
</template>
2021-04-02 22:34:09 +08:00
<script lang="ts">
2021-04-04 19:04:55 +08:00
2021-04-02 22:34:09 +08:00
import Vue from "vue"
2021-11-06 21:14:38 +08:00
import {Component, Prop, Watch} from "vue-property-decorator"
2021-11-06 20:19:21 +08:00
import {DataType, Info, EngineData, Property} from "../data"
2021-05-08 17:52:29 +08:00
import {connectBackground} from "@/devtools/connectBackground";
2021-06-17 22:35:37 +08:00
import {Msg} from "@/core/types";
2021-10-30 16:32:58 +08:00
import Bus, {BusMsg} from "../bus"
2021-04-02 22:34:09 +08:00
2021-04-04 19:04:55 +08:00
@Component({
components: {}
})
2021-04-02 22:34:09 +08:00
export default class UiProp extends Vue {
2021-04-03 22:45:51 +08:00
@Prop({default: ""})
name: string | undefined;
2021-04-02 22:34:09 +08:00
2021-06-15 22:19:47 +08:00
@Prop({default: 0})
indent!: number;
@Prop({default: true})
arrow!: boolean;
2021-04-04 15:42:16 +08:00
@Prop()
2021-05-08 17:52:29 +08:00
value!: Info;
2021-04-04 15:42:16 +08:00
2021-11-06 21:14:38 +08:00
@Watch("value")
watchValue() {
if (this.isArray()) {
this.subData = this.value.data;
} else {
this.subData = null;
}
}
2021-11-06 21:42:37 +08:00
isInvalid() {
return this.value && (this.value.type === DataType.Invalid);
}
2021-04-04 15:42:16 +08:00
isString() {
2021-04-04 19:04:55 +08:00
return this.value && (this.value.type === DataType.String);
2021-04-04 15:42:16 +08:00
}
isText() {
2021-04-04 19:04:55 +08:00
return this.value && (this.value.type === DataType.Text);
2021-04-04 15:42:16 +08:00
}
isNumber() {
2021-04-04 19:04:55 +08:00
return this.value && (this.value.type === DataType.Number);
2021-04-04 15:42:16 +08:00
}
isVec2() {
2021-04-04 19:04:55 +08:00
return this.value && (this.value.type === DataType.Vec2);
2021-04-04 15:42:16 +08:00
}
isVec3() {
2021-04-04 19:04:55 +08:00
return this.value && (this.value.type === DataType.Vec3);
2021-04-04 15:42:16 +08:00
}
isEnum() {
2021-04-04 19:04:55 +08:00
return this.value && (this.value.type === DataType.Enum);
}
isBool() {
return this.value && (this.value.type === DataType.Bool);
}
isColor() {
return this.value && (this.value.type === DataType.Color);
2021-04-04 15:42:16 +08:00
}
2021-04-06 18:41:54 +08:00
isArrayOrObject() {
return this.value && (this.value.type === DataType.Array || this.value.type === DataType.Object)
}
2021-06-17 22:35:37 +08:00
isObject() {
return this.value && (this.value.type === DataType.Object)
}
2021-06-15 22:19:47 +08:00
isArray() {
return this.value && (this.value.type === DataType.Array)
}
2021-06-14 19:41:58 +08:00
isImage() {
2021-06-15 20:51:19 +08:00
return this.value && (this.value.type === DataType.Image)
2021-06-14 19:41:58 +08:00
}
2021-06-19 19:51:05 +08:00
isEngine() {
return this.value && (this.value.type === DataType.Engine)
}
onPlaceInTree() {
Bus.$emit(BusMsg.ShowPlace, this.value);
}
2021-04-04 15:42:16 +08:00
created() {
2021-11-06 21:14:38 +08:00
}
mounted() {
this.watchValue();
2021-04-04 15:42:16 +08:00
}
2021-11-06 20:43:45 +08:00
isShowTooltip() {
2021-11-07 00:09:02 +08:00
const el: HTMLDivElement = this.$refs.propText as HTMLDivElement;
2021-11-06 20:43:45 +08:00
if (el) {
if (el.scrollWidth > el.offsetWidth) {
// 出现了省略号
return true;
}
}
return false;
}
2021-06-19 19:51:05 +08:00
getEngineTypeIcon() {
const value = this.value as EngineData;
switch (value.engineType) {
case "cc_Sprite": {
return "el-icon-picture-outline";
2021-06-19 19:51:05 +08:00
}
case "cc_Label": {
return "el-icon-third-text";
2021-06-19 19:51:05 +08:00
}
case "cc_Node": {
return "el-icon-third-node"
2021-06-19 19:51:05 +08:00
}
}
return "el-icon-third-unknow";
2021-06-19 19:51:05 +08:00
}
2021-06-17 22:35:37 +08:00
getName(isArray: boolean, arr: UiProp) {
const type = arr.value.type;
if (isArray) {
return `[${arr.name}]`
} else {
return arr.name;
}
}
2021-11-06 20:19:21 +08:00
private fold = true;
private subData: Property[] | null = null;
2021-06-15 22:19:47 +08:00
onClickFold() {
2021-11-06 20:19:21 +08:00
if (this.isObject() && this.fold && !this.subData) {
// 请求object的item数据
Bus.$emit(BusMsg.RequestObjectData, this.value, (info: Property[]) => {
2021-06-15 22:19:47 +08:00
2021-11-06 20:19:21 +08:00
this.fold = false;
this.subData = info;
})
} else {
this.fold = !this.fold;
2021-04-06 18:41:54 +08:00
}
}
onShowValueInConsole() {
2021-04-07 17:26:16 +08:00
if (Array.isArray(this.value.path)) {
let uuid = this.value.path[0];
let key = this.value.path[1]; // todo 暂时只支持一级key
if (uuid && key) {
2021-05-08 17:52:29 +08:00
chrome.devtools.inspectedWindow.eval(`window.CCInspector.logValue('${uuid}','${key}')`)
2021-04-07 17:26:16 +08:00
}
}
}
onChangeValue() {
2021-05-08 20:36:32 +08:00
if (!this.value.readonly) {
connectBackground.postMessageToBackground(Msg.SetProperty, this.value);
}
2021-04-06 18:41:54 +08:00
}
2021-04-03 22:45:51 +08:00
@Prop({default: 1})
step: number | undefined;
2021-04-03 11:42:08 +08:00
2021-04-04 15:42:16 +08:00
2021-04-02 22:34:09 +08:00
clientX: number = 0;
2021-04-04 15:42:16 +08:00
onPropNameMouseDown(event: MouseEvent) {
2021-04-02 22:34:09 +08:00
document.addEventListener("mousemove", this._onMouseMove);
document.addEventListener("mouseup", this._onMouseUp);
document.addEventListener("onselectstart", this._onSelect);
}
2021-04-04 20:48:18 +08:00
colorReverse(OldColorValue: string) {
2021-04-04 19:04:55 +08:00
OldColorValue = "0x" + OldColorValue.replace(/#/g, "");
2021-04-05 13:50:47 +08:00
var str = "000000" + (0xFFFFFF - parseInt(OldColorValue)).toString(16);
return "#" + str.substring(str.length - 6, str.length);
2021-04-04 19:04:55 +08:00
}
2021-04-02 22:34:09 +08:00
_onSelect() {
return false;
}
2021-04-03 11:42:08 +08:00
_onMouseMove(event: MouseEvent) {
2021-04-02 22:34:09 +08:00
let x = event.clientX;
2021-04-03 22:45:51 +08:00
let calcStep = this.step || 0;
2021-04-02 22:34:09 +08:00
if (x > this.clientX) {
calcStep = Math.abs(calcStep);
} else {
calcStep = -Math.abs(calcStep);
}
this.$emit("movestep", calcStep);
this.clientX = x;
}
2021-04-03 11:42:08 +08:00
_onMouseUp(event: MouseEvent) {
2021-04-02 22:34:09 +08:00
document.removeEventListener("mousemove", this._onMouseMove);
document.removeEventListener("mouseup", this._onMouseUp);
document.removeEventListener("onselectstart", this._onSelect);
}
2021-04-01 17:47:56 +08:00
};
2019-03-15 10:08:39 +08:00
</script>
2021-04-04 15:42:16 +08:00
<style scoped lang="less">
#ui-prop {
min-height: 30px;
2021-06-17 22:35:37 +08:00
margin: 1px 0;
2021-04-04 15:42:16 +08:00
display: flex;
2021-06-15 22:19:47 +08:00
flex-direction: column;
justify-content: center;
2021-04-04 15:42:16 +08:00
2021-06-15 22:19:47 +08:00
.normal-data {
margin: 0;
min-height: 30px;
overflow: hidden;
width: 100%;
2021-04-04 15:42:16 +08:00
display: flex;
flex-direction: row;
align-items: center;
2021-04-04 19:04:55 +08:00
2021-06-15 22:19:47 +08:00
.key {
flex: 1;
float: left;
text-align: left;
2021-04-04 15:42:16 +08:00
display: flex;
flex-direction: row;
2021-04-04 19:04:55 +08:00
align-items: center;
2021-06-15 22:19:47 +08:00
min-width: 90px;
2021-04-04 15:42:16 +08:00
2021-06-15 22:19:47 +08:00
.data-arrow {
width: 20px;
height: 16px;
font-size: 16px;
cursor: pointer;
2021-04-04 15:42:16 +08:00
}
2021-06-15 22:19:47 +08:00
.text {
flex: 1;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
2021-06-15 22:19:47 +08:00
user-select: none;
font-size: 12px;
margin: 3px;
2021-11-06 20:19:21 +08:00
span {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
2021-04-04 15:42:16 +08:00
}
}
2021-06-15 22:19:47 +08:00
.value {
flex: 3;
text-align: left;
height: 100%;
2021-04-06 18:41:54 +08:00
overflow: hidden;
2021-06-15 22:19:47 +08:00
min-width: 400px;
2021-04-06 18:41:54 +08:00
2021-06-15 22:19:47 +08:00
.color {
position: relative;
height: 30px;
.hex {
line-height: 30px;
position: relative;
text-align: center;
user-select: none;
pointer-events: none;
}
2021-04-06 18:41:54 +08:00
}
2021-11-06 21:42:37 +08:00
.invalid {
color: grey;
}
2021-11-06 21:14:38 +08:00
.objectDesc {
2021-11-06 20:19:21 +08:00
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
user-select: none;
}
2021-11-06 21:14:38 +08:00
.array {
display: flex;
flex-direction: column;
color: red;
}
2021-06-19 19:51:05 +08:00
.engine {
display: flex;
flex-direction: row;
border: solid #409EFF 1px;
border-radius: 5px;
align-items: center;
align-content: center;
.head {
background-color: cornflowerblue;
height: 28px;
align-items: center;
align-content: center;
display: flex;
flex-direction: row;
.icon {
font-size: 20px;
width: 20px;
margin-left: 5px;
}
.type {
display: flex;
align-content: center;
align-items: center;
margin: 0 5px;
}
}
.name {
flex: 1;
height: 28px;
padding-left: 5px;
background-color: gold;
display: flex;
align-items: center;
align-content: center;
}
}
2021-06-15 22:19:47 +08:00
.vec {
width: 100%;
display: flex;
flex-direction: row;
align-items: center;
#ui-prop {
2021-06-17 21:37:09 +08:00
margin: 0 10px;
flex: 1;
2021-06-15 22:19:47 +08:00
.normal-data {
.value {
min-width: 100px;
}
.key {
2021-06-17 21:37:09 +08:00
min-width: unset;
display: block;
margin-right: 5px;
flex: unset;
2021-06-15 22:19:47 +08:00
}
}
}
2021-06-14 19:41:58 +08:00
2021-06-17 21:37:09 +08:00
#ui-prop:first-child {
margin-left: 0;
2021-06-15 22:19:47 +08:00
}
2021-06-17 21:37:09 +08:00
#ui-prop:last-child {
margin-right: 0;
2021-06-15 22:19:47 +08:00
}
2021-06-17 21:37:09 +08:00
}
.array-object {
flex: 1;
max-width: 100%;
overflow: hidden;
display: flex;
flex-direction: row;
align-items: center;
2021-06-15 22:19:47 +08:00
2021-06-17 21:37:09 +08:00
.text {
flex: 1;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
2021-06-15 22:19:47 +08:00
}
}
2021-06-17 21:37:09 +08:00
.image-property {
display: flex;
flex-direction: row;
align-content: center;
align-items: center;
height: 36px;
}
.slot {
display: flex;
width: 100%;
}
2021-04-04 15:42:16 +08:00
}
}
2021-04-01 17:47:56 +08:00
}
2019-03-15 10:08:39 +08:00
</style>