2019-03-15 10:08:39 +08:00
|
|
|
<template>
|
2024-12-11 14:56:50 +08:00
|
|
|
<div class="ui-prop">
|
|
|
|
<CCProp :name="name" :icon="icon" :head-width="headWidth" v-model:expand="expand" :arrow="value.isArrayOrObject()" :slide="value.isNumber()" :indent="indent * 10" @change-expand="onClickFold">
|
|
|
|
<div class="prop-value">
|
2024-01-09 15:33:34 +08:00
|
|
|
<div v-if="value.isInvalid()" class="invalid">
|
2021-11-07 00:09:02 +08:00
|
|
|
{{ value.data }}
|
2021-11-06 21:42:37 +08:00
|
|
|
</div>
|
2024-12-11 14:56:50 +08:00
|
|
|
<CCInput v-if="value.isString()" v-model:value="value.data" :disabled="value.readonly" @change="onChangeValue"> </CCInput>
|
|
|
|
<CCTextarea v-if="value.isText()" v-model:value="value.data" :disabled="value.readonly" @change="onChangeValue"> </CCTextarea>
|
|
|
|
<CCInputNumber v-if="value.isNumber()" v-model:value="value.data" :step="step" :disabled="value.readonly" @change="onChangeValue"></CCInputNumber>
|
|
|
|
<div v-if="value.isVec2() || value.isVec3() || value.isVec4()" class="vec">
|
|
|
|
<UiProp v-for="(vec, index) in value.data" :icon="!!index" head-width="auto" :key="index" :arrow="false" :value="vec.value" :name="vec.name"> </UiProp>
|
2021-04-06 18:41:54 +08:00
|
|
|
</div>
|
2024-12-11 14:56:50 +08:00
|
|
|
<CCSelect v-if="value.isEnum()" v-model:value="value.data" :disabled="value.readonly" :data="getEnumValues(value)" @change="onChangeValue"> </CCSelect>
|
|
|
|
<CCCheckBox v-if="value.isBool()" v-model:value="value.data" :disabled="value.readonly" @change="onChangeValue"> </CCCheckBox>
|
|
|
|
<CCColor v-if="value.isColor()" :show-color-text="true" :disabled="value.readonly" v-model:color="value.data" @change="onChangeValue"> </CCColor>
|
2024-01-09 15:33:34 +08:00
|
|
|
<div v-if="value.isImage()" class="image-property">
|
|
|
|
<!-- TODO: 适配 -->
|
|
|
|
<div v-if="value.isImage() || true" placement="top" trigger="hover">
|
2024-12-09 16:23:58 +08:00
|
|
|
<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" />
|
2021-06-15 22:19:47 +08:00
|
|
|
</div>
|
2024-01-09 12:02:47 +08:00
|
|
|
<img :src="value.data" style="height: 36px" alt="图片" />
|
2024-01-09 15:33:34 +08:00
|
|
|
</div>
|
2024-01-09 12:02:47 +08:00
|
|
|
<div style="flex: 1; display: flex; flex-direction: row-reverse">
|
2024-01-09 15:33:34 +08:00
|
|
|
<CCButton @click="onShowValueInConsole">log</CCButton>
|
2021-06-15 20:51:19 +08:00
|
|
|
</div>
|
2021-06-15 22:19:47 +08:00
|
|
|
</div>
|
2024-12-11 14:56:50 +08:00
|
|
|
<Engine v-if="value.isEngine()" v-model:data="(value as EngineData)"> </Engine>
|
|
|
|
<div v-if="value.isObject() && !expand" class="objectDesc">{{ value.data }}</div>
|
|
|
|
<div v-if="value.isArray()" class="array">Array[{{ value.data.length }}]</div>
|
2021-04-06 18:41:54 +08:00
|
|
|
</div>
|
2024-12-11 14:56:50 +08:00
|
|
|
</CCProp>
|
|
|
|
<div v-if="value.isArrayOrObject()">
|
|
|
|
<div v-show="expand && subData">
|
|
|
|
<UiProp v-for="(arr, index) in subData" :key="index" :indent="indent + 1" :value="arr.value" :name="getName(value.isArray(), arr)"> </UiProp>
|
2019-03-15 10:08:39 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
2021-04-02 22:34:09 +08:00
|
|
|
<script lang="ts">
|
2024-12-09 16:23:58 +08:00
|
|
|
import ccui from "@xuyanfeng/cc-ui";
|
|
|
|
import { Option } from "@xuyanfeng/cc-ui/types/cc-select/const";
|
|
|
|
import { defineComponent, onMounted, onUnmounted, PropType, ref, toRaw, watch } from "vue";
|
2024-01-09 12:02:47 +08:00
|
|
|
import { Msg } from "../../../core/types";
|
|
|
|
import Bus, { BusMsg } from "../bus";
|
2024-12-09 16:23:58 +08:00
|
|
|
import { connectBackground } from "../connectBackground";
|
2024-12-11 14:56:50 +08:00
|
|
|
import { DataType, EngineData, EnumData, Info, NumberData, Property, StringData, TextData, Vec2Data, Vec3Data } from "../data";
|
|
|
|
import Engine from "./property-engine.vue";
|
|
|
|
const { CCInput, CCTextarea, CCProp, CCButton, CCInputNumber, CCSelect, CCCheckBox, CCColor } = ccui.components;
|
2024-01-09 12:02:47 +08:00
|
|
|
export default defineComponent({
|
2024-12-11 14:56:50 +08:00
|
|
|
name: "ui-prop",
|
|
|
|
components: { CCProp, Engine, CCTextarea, CCInput, CCButton, CCInputNumber, CCSelect, CCCheckBox, CCColor },
|
2024-01-09 12:02:47 +08:00
|
|
|
props: {
|
2024-01-09 15:33:34 +08:00
|
|
|
name: { type: String, default: "" },
|
|
|
|
indent: { type: Number, default: 0 },
|
2024-12-11 14:56:50 +08:00
|
|
|
icon: { type: Boolean, default: true },
|
|
|
|
headWidth: { type: String, default: "120px" },
|
|
|
|
arrow: { type: Boolean, default: false },
|
2024-01-09 15:33:34 +08:00
|
|
|
step: { type: Number, default: 1 },
|
2024-01-09 12:02:47 +08:00
|
|
|
value: {
|
2024-12-11 14:56:50 +08:00
|
|
|
type: Object as PropType<Info | EngineData | EnumData | NumberData | StringData | TextData | Vec2Data | Vec3Data>,
|
2024-01-09 12:02:47 +08:00
|
|
|
default: () => {},
|
|
|
|
},
|
|
|
|
},
|
2024-01-09 15:33:34 +08:00
|
|
|
setup(props, { emit }) {
|
|
|
|
const { value, step } = props;
|
2024-12-11 14:56:50 +08:00
|
|
|
const expand = ref(false);
|
|
|
|
|
2024-01-09 12:02:47 +08:00
|
|
|
onMounted(() => {
|
|
|
|
watchValue();
|
|
|
|
});
|
|
|
|
function watchValue() {
|
2024-12-11 14:56:50 +08:00
|
|
|
// fold.value = true;
|
2024-01-09 15:33:34 +08:00
|
|
|
if (value.isArray()) {
|
|
|
|
subData.value = value.data;
|
2024-01-09 12:02:47 +08:00
|
|
|
} else {
|
2024-01-09 15:33:34 +08:00
|
|
|
subData.value = null;
|
2021-06-19 19:51:05 +08:00
|
|
|
}
|
2021-04-06 18:41:54 +08:00
|
|
|
}
|
2024-01-09 12:02:47 +08:00
|
|
|
watch(props.value, () => {
|
|
|
|
watchValue();
|
|
|
|
});
|
2024-12-11 14:56:50 +08:00
|
|
|
const subData = ref<Array<Property> | null>(null);
|
2024-01-09 15:33:34 +08:00
|
|
|
|
2024-01-09 12:02:47 +08:00
|
|
|
return {
|
2024-12-11 14:56:50 +08:00
|
|
|
expand,
|
2024-01-09 12:02:47 +08:00
|
|
|
subData,
|
2024-01-09 15:33:34 +08:00
|
|
|
getEnumValues(data: any): Option[] {
|
|
|
|
const value: EnumData = data;
|
|
|
|
const ret: Option[] = [];
|
|
|
|
value.values.map((item) => {
|
|
|
|
ret.push({
|
|
|
|
label: item.name,
|
|
|
|
value: item.value,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
return ret;
|
2024-01-09 12:02:47 +08:00
|
|
|
},
|
2024-12-11 14:56:50 +08:00
|
|
|
|
2024-01-09 12:02:47 +08:00
|
|
|
isImageValid() {
|
2024-01-09 15:33:34 +08:00
|
|
|
return !!value.data;
|
2024-01-09 12:02:47 +08:00
|
|
|
},
|
2024-12-11 14:56:50 +08:00
|
|
|
|
2024-01-09 12:02:47 +08:00
|
|
|
getName(isArray: boolean, arr: Property) {
|
|
|
|
const type = arr.value.type;
|
|
|
|
if (isArray) {
|
2024-12-11 14:56:50 +08:00
|
|
|
return arr.name;
|
2024-01-09 12:02:47 +08:00
|
|
|
} else {
|
|
|
|
return arr.name;
|
|
|
|
}
|
|
|
|
},
|
2024-12-11 14:56:50 +08:00
|
|
|
onClickFold(v: boolean) {
|
|
|
|
if (value.isArray()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const s = toRaw(subData.value);
|
|
|
|
const e = toRaw(expand.value);
|
|
|
|
if (value.isObject() && s === null && e === true) {
|
2024-01-09 12:02:47 +08:00
|
|
|
// 请求object的item数据
|
2024-12-11 14:56:50 +08:00
|
|
|
Bus.emit(BusMsg.RequestObjectData, toRaw(value), (info: Property[]) => {
|
2024-01-09 15:33:34 +08:00
|
|
|
subData.value = info;
|
2024-01-09 12:02:47 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onShowValueInConsole() {
|
2024-01-09 15:33:34 +08:00
|
|
|
if (Array.isArray(value.path)) {
|
|
|
|
let uuid = value.path[0];
|
|
|
|
let key = value.path[1]; // todo 暂时只支持一级key
|
2024-01-09 12:02:47 +08:00
|
|
|
if (uuid && key) {
|
2024-12-09 16:23:58 +08:00
|
|
|
chrome.devtools.inspectedWindow.eval(`window.CCInspector.logValue('${uuid}','${key}')`);
|
2024-01-09 12:02:47 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onChangeValue() {
|
2024-01-09 15:33:34 +08:00
|
|
|
if (!value.readonly) {
|
2024-12-11 14:56:50 +08:00
|
|
|
connectBackground.postMessageToBackground(Msg.SetProperty, toRaw(value));
|
2024-01-09 12:02:47 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
|
|
|
});
|
2019-03-15 10:08:39 +08:00
|
|
|
</script>
|
|
|
|
|
2021-04-04 15:42:16 +08:00
|
|
|
<style scoped lang="less">
|
2024-12-11 14:56:50 +08:00
|
|
|
.ui-prop {
|
2021-04-04 15:42:16 +08:00
|
|
|
display: flex;
|
2021-06-15 22:19:47 +08:00
|
|
|
flex-direction: column;
|
|
|
|
justify-content: center;
|
2024-12-11 14:56:50 +08:00
|
|
|
.prop-value {
|
|
|
|
flex: 3;
|
|
|
|
text-align: left;
|
|
|
|
overflow: hidden;
|
|
|
|
display: flex;
|
|
|
|
flex-direction: row;
|
|
|
|
align-items: flex-start;
|
|
|
|
|
|
|
|
.invalid {
|
|
|
|
color: grey;
|
|
|
|
}
|
|
|
|
|
|
|
|
.objectDesc {
|
|
|
|
white-space: nowrap;
|
|
|
|
overflow: hidden;
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
user-select: none;
|
|
|
|
font-size: 12px;
|
|
|
|
color: #d2d2d2;
|
|
|
|
}
|
|
|
|
|
|
|
|
.array {
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
color: #d2d2d2;
|
|
|
|
font-size: 12px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.vec {
|
|
|
|
width: 100%;
|
|
|
|
display: flex;
|
|
|
|
flex-direction: row;
|
|
|
|
align-items: center;
|
|
|
|
|
|
|
|
.ui-prop {
|
|
|
|
flex: 1;
|
|
|
|
.cc-prop {
|
|
|
|
overflow: hidden;
|
|
|
|
}
|
|
|
|
}
|
2021-04-04 15:42:16 +08:00
|
|
|
|
2024-12-11 14:56:50 +08:00
|
|
|
// #ui-prop:first-child {
|
|
|
|
// margin-left: 0;
|
|
|
|
// }
|
|
|
|
|
|
|
|
// #ui-prop:last-child {
|
|
|
|
// margin-right: 0;
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
|
|
|
|
.array-object {
|
|
|
|
flex: 1;
|
|
|
|
max-width: 100%;
|
|
|
|
overflow: hidden;
|
|
|
|
display: flex;
|
|
|
|
flex-direction: row;
|
|
|
|
align-items: center;
|
|
|
|
}
|
|
|
|
|
|
|
|
.image-property {
|
|
|
|
display: flex;
|
|
|
|
flex-direction: row;
|
|
|
|
align-content: center;
|
|
|
|
align-items: center;
|
|
|
|
height: 36px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.slot {
|
|
|
|
display: flex;
|
|
|
|
width: 100%;
|
|
|
|
}
|
|
|
|
}
|
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-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
|
|
|
.text {
|
2021-10-30 16:08:29 +08:00
|
|
|
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-10-30 16:08:29 +08:00
|
|
|
|
2021-11-06 20:19:21 +08:00
|
|
|
span {
|
2021-10-30 16:08:29 +08:00
|
|
|
white-space: nowrap;
|
|
|
|
overflow: hidden;
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
}
|
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>
|