396 lines
9.8 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-06-15 22:19:47 +08:00
<div class="text">{{ name }}</div>
2021-04-04 15:42:16 +08:00
</div>
2021-06-15 22:19:47 +08:00
<div class="value">
<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="isArray()" style="display: flex;flex-direction: column;">
{{ value.data.length }}
</div>
<!-- <div v-if="isArrayOrObject()" class="array-object">-->
<!-- <div class="text">-->
<!-- {{ valueString() }}-->
<!-- </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>
<div class="slot">
<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-06-15 22:19:47 +08:00
<div v-show="!fold" style="display: flex;flex-direction: column;">
<ui-prop v-for="(arr,index) in value.data"
: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"
import {Component, Prop} from "vue-property-decorator"
2021-06-17 22:35:37 +08:00
import {DataType, Info} 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-04-02 22:34:09 +08:00
2021-04-04 19:04:55 +08:00
@Component({
components: {}
})
2021-04-05 18:38:44 +08:00
// todo 支持array
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
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-04-04 15:42:16 +08:00
created() {
}
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-06-15 22:19:47 +08:00
private fold = false;
onClickFold() {
this.fold = !this.fold;
}
2021-04-06 18:41:54 +08:00
valueString() {
try {
return JSON.stringify(this.value.data)
} catch (e) {
return ''
}
}
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);
2021-04-04 19:04:55 +08:00
return '#' + str.substring(str.length - 6, str.length);
}
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 {
user-select: none;
font-size: 12px;
margin: 3px;
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-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-17 21:37:09 +08:00
.text {
}
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>