316 lines
7.6 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">
<div @mousedown="onPropNameMouseDown" class="key">
<div class="text">{{ name }}</div>
2019-03-15 10:08:39 +08:00
</div>
2021-04-04 15:42:16 +08:00
<div class="value">
2021-05-08 20:36:32 +08:00
<el-input v-if="isString()" v-model="value.data"
:disabled="value.readonly"
@change="onChangeValue">
</el-input>
2021-04-04 15:42:16 +08:00
<el-input v-if="isText()"
type="textarea"
:autosize="{minRows:3,maxRows:5}"
placeholder="请输入内容"
2021-05-08 20:36:32 +08:00
:disabled="value.readonly"
2021-05-08 17:52:29 +08:00
@change="onChangeValue"
2021-04-04 15:42:16 +08:00
v-model="value.data">
</el-input>
<el-input-number v-if="isNumber()"
style="width: 100%;text-align: left"
v-model="value.data"
:step="step"
2021-05-08 20:36:32 +08:00
:disabled="value.readonly"
2021-05-08 17:52:29 +08:00
@change="onChangeValue"
2021-04-04 15:42:16 +08:00
controls-position="right"
></el-input-number>
<div v-if="isVec2()||isVec3()" class="vec">
<ui-prop v-for="(vec, index) in value.data"
:key="index"
:value="vec.value"
:name="vec.name">
</ui-prop>
</div>
2021-05-08 20:36:32 +08:00
<el-select v-model="value.data"
:disabled="value.readonly"
v-if="isEnum()" style="width: 100%;"
@change="onChangeValue">
2021-04-04 15:42:16 +08:00
<el-option v-for="(opt, index) in value.values"
:key="index"
:label="opt.name"
:value="opt.value">
</el-option>
</el-select>
2021-05-08 20:36:32 +08:00
<el-checkbox v-model="value.data"
v-if="isBool()"
:disabled="value.readonly"
@change="onChangeValue">
</el-checkbox>
2021-04-04 19:04:55 +08:00
<div class="color" v-if="isColor()">
2021-05-08 20:36:32 +08:00
<el-color-picker style="position: absolute;"
:disabled="value.readonly"
v-model="value.data" @change="onChangeValue">
</el-color-picker>
2021-04-04 19:04:55 +08:00
<div class="hex" :style="{color:colorReverse(value.data)}">{{ value.data }}</div>
</div>
2021-04-06 18:41:54 +08:00
<div v-if="isArrayOrObject()" class="array-object">
<div class="text">
{{ valueString() }}
</div>
2021-06-14 19:41:58 +08:00
<el-button @click="onShowValueInConsole">log</el-button>
</div>
<div v-if="isImage()" class="image-property">
<el-popover v-if="isImage()" placement="top" trigger="hover">
<!-- 会有一个undefined的错误-->
<el-image v-if="isImage()" style="width: 100px;height: 100px" fit="contain" :src="value.data"></el-image>
<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>
</div>
2021-04-06 18:41:54 +08:00
</div>
2021-04-04 15:42:16 +08:00
<div class="slot">
2019-03-15 10:08:39 +08:00
<slot></slot>
</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-05-08 17:52:29 +08:00
import {DataType, Info, NullOrUndefinedData, Vec2Data, Vec3Data} from './data'
import {connectBackground} from "@/devtools/connectBackground";
import {Msg, Page, PluginEvent} 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-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-14 19:41:58 +08:00
isImage() {
return this.value && (this.value.type === DataType.Array || this.value.type === DataType.Image)
}
2021-04-04 15:42:16 +08:00
created() {
}
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 {
margin: 0;
min-height: 30px;
overflow: hidden;
width: 100%;
display: flex;
flex-direction: row;
align-items: center;
2019-03-15 10:08:39 +08:00
2021-04-04 15:42:16 +08:00
.key {
flex: 1;
float: left;
text-align: left;
display: flex;
flex-direction: row;
align-items: center;
2021-04-07 17:26:16 +08:00
min-width: 90px;
2021-04-04 15:42:16 +08:00
.text {
user-select: none;
line-height: 30px;
font-size: 12px;
margin: 3px;
}
}
.value {
flex: 3;
text-align: left;
2021-04-04 19:04:55 +08:00
height: 100%;
2021-04-06 18:41:54 +08:00
overflow: hidden;
2021-04-07 17:26:16 +08:00
min-width: 400px;
2021-04-04 19:04:55 +08:00
.color {
position: relative;
height: 30px;
.hex {
line-height: 30px;
position: relative;
text-align: center;
user-select: none;
pointer-events: none;
}
}
2021-04-04 15:42:16 +08:00
.vec {
width: 100%;
display: flex;
flex-direction: row;
2021-04-04 19:04:55 +08:00
align-items: center;
2021-04-04 15:42:16 +08:00
#ui-prop {
margin-top: 0;
margin-bottom: 0;
margin-right: 20px;
2021-04-07 17:26:16 +08:00
.value {
min-width: 100px;
}
.key {
min-width: 20px;
}
2021-04-04 15:42:16 +08:00
}
#ui-prop:last-child {
margin-right: 0;
}
}
2021-04-06 18:41:54 +08:00
.array-object {
2021-04-07 17:26:16 +08:00
flex: 1;
2021-04-06 18:41:54 +08:00
max-width: 100%;
overflow: hidden;
display: flex;
flex-direction: row;
align-items: center;
.text {
2021-04-07 17:26:16 +08:00
flex: 1;
2021-04-06 18:41:54 +08:00
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
}
2021-06-14 19:41:58 +08:00
.image-property {
display: flex;
flex-direction: row;
align-content: center;
align-items: center;
height: 36px;
}
2021-04-04 15:42:16 +08:00
.slot {
display: flex;
width: 100%;
}
}
2021-04-01 17:47:56 +08:00
}
2019-03-15 10:08:39 +08:00
</style>