Files
workGit/数字孪生可视化大屏vue源码/YouTeVue2TV/tmp_switch_to_seamless_scroll.py
2026-05-23 14:11:26 +08:00

167 lines
5.2 KiB
Python

from pathlib import Path
p = Path(r"d:\5ITlearning\DT_TV\YouTeVue2TV\src\views\metalLathe.vue")
s = p.read_text(encoding='utf-8')
s = s.replace("import * as echarts from 'echarts'\n", "import * as echarts from 'echarts'\nimport vueSeamlessScroll from 'vue-seamless-scroll'\n", 1)
s = s.replace("export default {\n name: 'MetalLathe',\n", "export default {\n name: 'MetalLathe',\n components: {\n vueSeamlessScroll\n },\n", 1)
s = s.replace(
""" <div class="data-card">
<div class="card-title">主轴数据</div>
<div
class="data-grid spindle-scroll"
@mouseenter="spindleScrollPaused = true"
@mouseleave="spindleScrollPaused = false">
<div class="spindle-scroll-track" :class="{ paused: spindleScrollPaused }">
<div v-for="(item, index) in scrollingSpindleItems" :key="`${item.key}-${index}`" class="data-item">
<span class="item-label">{{ item.label }}</span>
<span class="item-value">{{ item.value }}</span>
</div>
</div>
</div>
</div>
""",
""" <div class="data-card">
<div class="card-title">主轴数据</div>
<vue-seamless-scroll
:data="spindleItems"
:class-option="scrollClassOption"
class="data-grid seamless-scroll-panel"
>
<div class="scroll-list">
<div
v-for="(item, index) in spindleItems"
:key="`${item.key}-${index}`"
class="data-item"
>
<span class="item-label">{{ item.label }}</span>
<span class="item-value">{{ item.value }}</span>
</div>
</div>
</vue-seamless-scroll>
</div>
""",
1,
)
s = s.replace(
""" <div class="data-card">
<div class="card-title">进给轴数据</div>
<div
class="data-grid feed-axis-scroll"
@mouseenter="feedAxisScrollPaused = true"
@mouseleave="feedAxisScrollPaused = false"
>
<div
class="feed-axis-scroll-track"
:class="{ paused: feedAxisScrollPaused }"
>
<div
v-for="(item, index) in scrollingFeedAxisItems"
:key="`${item.axis}-${item.key}-${index}`"
class="data-item"
>
<span class="item-label">{{ item.label }}</span>
<span class="item-value">{{ item.value }}</span>
</div>
</div>
</div>
</div>
""",
""" <div class="data-card">
<div class="card-title">进给轴数据</div>
<vue-seamless-scroll
:data="feedAxisItems"
:class-option="scrollClassOption"
class="data-grid seamless-scroll-panel"
>
<div class="scroll-list">
<div
v-for="(item, index) in feedAxisItems"
:key="`${item.axis}-${item.key}-${index}`"
class="data-item"
>
<span class="item-label">{{ item.label }}</span>
<span class="item-value">{{ item.value }}</span>
</div>
</div>
</vue-seamless-scroll>
</div>
""",
1,
)
s = s.replace(
""" <div class="data-card">
<div class="card-title">床身温度实时监测</div>
<div
class="data-grid bed-scroll"
@mouseenter="bedScrollPaused = true"
@mouseleave="bedScrollPaused = false"
>
<div
class="bed-scroll-track"
:class="{ paused: bedScrollPaused }"
>
<div
v-for="(item, index) in scrollingBedItems"
:key="`${item.key}-${index}`"
class="data-item"
>
<span class="item-label">{{ item.label }}</span>
<span class="item-value">{{ item.value }}</span>
</div>
</div>
</div>
</div>
""",
""" <div class="data-card">
<div class="card-title">床身温度实时监测</div>
<vue-seamless-scroll
:data="bedItems"
:class-option="scrollClassOption"
class="data-grid seamless-scroll-panel"
>
<div class="scroll-list">
<div
v-for="(item, index) in bedItems"
:key="`${item.key}-${index}`"
class="data-item"
>
<span class="item-label">{{ item.label }}</span>
<span class="item-value">{{ item.value }}</span>
</div>
</div>
</vue-seamless-scroll>
</div>
""",
1,
)
marker = " computed: {\n"
insert = " computed: {\n scrollClassOption() {\n return {\n step: 0.35,\n direction: 1,\n limitMoveNum: 1,\n hoverStop: true,\n openTouch: false\n }\n },\n"
s = s.replace(marker, insert, 1)
start = s.index('.feed-axis-scroll {')
end = s.index('@keyframes feed-axis-scroll-up {', start)
new_css = '''.seamless-scroll-panel {
display: block;
height: 220px;
overflow: hidden;
position: relative;
}
.scroll-list {
display: block;
}
'''
s = s[:start] + new_css + s[end:]
end_keyframes = s.index('.data-item {')
s = s[:s.index('@keyframes feed-axis-scroll-up {')] + s[end_keyframes:]
p.write_text(s, encoding='utf-8')
print('ok')