Skip to content

Commit 0d3bc74

Browse files
优化属性面板 addut
1 parent 7731a6e commit 0d3bc74

File tree

3 files changed

+81
-26
lines changed

3 files changed

+81
-26
lines changed

src/common/attribute-panel/AttributePanel.vue

+18-21
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,13 @@
2222
<ul>
2323
<li v-for="(value, key, index) in attributes" :key="index" class="content">
2424
<div class="left ellipsis" :title="key" :style="formatStyle.keyStyle">{{ key }}</div>
25-
<div class="right ellipsis" :title="value.value || value" :style="formatStyle.valueStyle">
25+
<div class="right ellipsis" :title="value" :style="formatStyle.valueStyle">
2626
<slot v-if="fieldsMap[key]" :name="fieldsMap[key]" :value="value"></slot>
2727
<span v-else>{{ value }}</span>
2828
</div>
2929
</li>
3030
</ul>
3131
</div>
32-
<sm-table-popup
33-
v-if="!$slots.default && !($scopedSlots && Object.keys($scopedSlots).length) && Object.keys(attributes).length"
34-
v-bind="tablePopupProps"
35-
class="sm-component-attribute-panel__self-content"
36-
/>
3732
<sm-empty v-if="!$slots.default && !Object.keys(attributes).length" />
3833
</div>
3934
</div>
@@ -42,12 +37,11 @@
4237
<script lang="ts">
4338
import { Component, Prop, Watch, Mixins } from 'vue-property-decorator';
4439
import Theme from 'vue-iclient/src/common/_mixin/Theme';
45-
import SmTablePopup from 'vue-iclient/src/common/table-popup/TablePopup.vue';
4640
import SmEmpty from 'vue-iclient/src/common/empty/Empty.vue';
4741
4842
@Component({
4943
name: 'SmAttributePanel',
50-
components: { SmTablePopup, SmEmpty }
44+
components: { SmEmpty }
5145
})
5246
class SmAttributePanel extends Mixins(Theme) {
5347
attrIndex = 0;
@@ -88,13 +82,6 @@ class SmAttributePanel extends Mixins(Theme) {
8882
})
8983
attributes: Object;
9084
91-
@Prop({
92-
default: () => {
93-
return [];
94-
}
95-
})
96-
columns: Array<Object>;
97-
9885
@Watch('currentIndex')
9986
currentIndexChanged() {
10087
this.attrIndex = this.currentIndex;
@@ -116,22 +103,32 @@ class SmAttributePanel extends Mixins(Theme) {
116103
return `${this.attrIndex + 1}/${this.total}`;
117104
}
118105
119-
get tablePopupProps() {
120-
return { data: [this.attributes], columns: this.columns };
121-
}
122-
123106
get formatStyle() {
124107
let style = Object.assign({}, this.attributeStyle);
125108
Object.keys(style).forEach(item => {
126109
// @ts-ignore
127110
if (Object.prototype.hasOwnProperty.call(style[item], 'width')) {
128111
// @ts-ignore
129-
style[item].width += 'px';
112+
if (style[item].width === 0) {
113+
style[item].width = 'unset';
114+
style[item].flex = 1;
115+
} else {
116+
if (style[item].width !== 'unset') {
117+
style[item].width += 'px';
118+
}
119+
style[item].flex = 'unset';
120+
}
130121
}
131122
// @ts-ignore
132123
if (Object.prototype.hasOwnProperty.call(style[item], 'height')) {
133124
// @ts-ignore
134-
style[item].height += 'px';
125+
if (style[item].height === 0) {
126+
style[item].height = 'unset';
127+
} else {
128+
if (style[item].height !== 'unset') {
129+
style[item].height += 'px';
130+
}
131+
}
135132
}
136133
});
137134
return style;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { mount, createLocalVue } from '@vue/test-utils';
2+
import SmAttributePanel from '../AttributePanel.vue';
3+
const localVue = createLocalVue();
4+
5+
describe('AttributePanel.vue', () => {
6+
let wrapper;
7+
beforeEach(() => {
8+
wrapper = null;
9+
});
10+
11+
afterEach(() => {
12+
if (wrapper) {
13+
wrapper.destroy();
14+
}
15+
});
16+
17+
it('render', async done => {
18+
wrapper = mount(SmAttributePanel, {
19+
localVue,
20+
propsData: {
21+
attributeStyle: {
22+
"keyStyle":
23+
{
24+
"fontFamily": "微软雅黑",
25+
"color": "",
26+
"textAlign": "left",
27+
"width": "110",
28+
"fontSize": "0.296296rem",
29+
"fontWeight": "normal",
30+
"height": "unset",
31+
"flex": "unset"
32+
},
33+
"valueStyle": {
34+
"fontFamily": "微软雅黑",
35+
"color": "",
36+
"textAlign": "left",
37+
"width": "170",
38+
"fontSize": "0.296296rem",
39+
"fontWeight": "normal",
40+
"height": "unset",
41+
"flex": "unset"
42+
}
43+
},
44+
attributes: {
45+
"链接": "www.test.com",
46+
"text": "weidapao2",
47+
},
48+
fields: [
49+
{ "slotName": "11", "linkTitle": "", "field": "链接", "linkTarget": "_blank", "repeatOption": "left", "title": "链接", "type": "text" },
50+
{ "slotName": "13", "linkTitle": "", "field": "text", "linkTarget": "_blank", "repeatOption": "left", "title": "text", "type": "text" }]
51+
},
52+
attachToDocument: 'body'
53+
});
54+
await wrapper.vm.$nextTick();
55+
expect(wrapper.vm.fieldsMap).toEqual({ "链接": "11", "text": "13" });
56+
expect(wrapper.vm.formatStyle).toEqual({ "keyStyle": { "fontFamily": "微软雅黑", "color": "", "textAlign": "left", "width": "110px", "fontSize": "0.296296rem", "fontWeight": "normal", "height": "unset", "flex": "unset" }, "valueStyle": { "fontFamily": "微软雅黑", "color": "", "textAlign": "left", "width": "170px", "fontSize": "0.296296rem", "fontWeight": "normal", "height": "unset", "flex": "unset" } });
57+
wrapper.vm.changeIndex(1);
58+
expect(wrapper.vm.attrIndex).toBe(1);
59+
done();
60+
});
61+
});

src/common/attribute-panel/style/attribute-panel.scss

+2-5
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@
55
min-width: 200px;
66
height: 100%;
77
overflow: auto;
8-
padding: 10px;
98
border-radius: 4px;
109
border: 1px solid $border-color-split;
1110
@include e(header) {
1211
width: 100%;
1312
display: inline-flex;
1413
align-items: center;
15-
padding: 0px 8px 4px ;
14+
padding: 8px 8px 2px ;
1615
border-bottom: 2px solid $border-color-split;
1716
.switchDataText {
1817
position: absolute;
@@ -48,17 +47,15 @@
4847
margin: 0;
4948
padding: 0;
5049
font-size: 14px;
51-
max-height: 200px;
5250
background: transparent;
5351
li {
5452
> div {
55-
padding: 4px 16px;
53+
margin: 4px 16px;
5654
}
5755
}
5856
border-collapse: separate;
5957
.content {
6058
display: flex;
61-
justify-content: space-around;
6259
.left {
6360
width: 110px;
6461
}

0 commit comments

Comments
 (0)