Skip to content

Commit

Permalink
fix:model selection state
Browse files Browse the repository at this point in the history
  • Loading branch information
chenwenhao committed Sep 12, 2023
1 parent 1e8549b commit 3c3e6a1
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/components/navbar/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
<a-button v-if="deviceStore.deviceStatus === DeviceStatus.SerialConnected" type="primary" status="danger"
@click="handleDisconnect">{{
$t('workplace.device.btn.disconnect') }}</a-button>
<a-button v-else type="primary" :loading="loading" @click="handleConnect">{{ $t('workplace.device.btn.connect')
<a-button v-else type="primary" :loading="loading" :disabled="deviceStore.deviceStatus === DeviceStatus.Burning" @click="handleConnect">{{ $t('workplace.device.btn.connect')
}}</a-button>
</li>
</ul>
Expand Down
2 changes: 1 addition & 1 deletion src/senseCraft/serial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export default class Serial extends Device {
}
// 如果当前在esp连接,需要断开
if (
this.deviceStore.deviceStatus === DeviceStatus.EspConnected &&
(this.deviceStore.deviceStatus === DeviceStatus.EspConnected || this.deviceStore.deviceStatus === DeviceStatus.Burning) &&
this.transport
) {
await this.transport.disconnect();
Expand Down
45 changes: 42 additions & 3 deletions src/views/setup/process/components/device.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@
</div>
<swiper class="carousel" :slides-per-view="3" :space-between="50" :navigation="true" :modules="[Navigation]">
<swiper-slide v-for="(item, index) in deviceStore.models"
:class="['carousel-item', { 'carousel-item-selected': selectedModel === index }]" :key="index"
:onclick="() => handleSelectedModel(index)" :virtualIndex="index">
:class="['carousel-item', { 'carousel-item-selected': selectedModel === index && !isSelectedCustomModel }]"
:key="index" :onclick="() => handleSelectedModel(index)" :virtualIndex="index">
<img :src="item.image" class="carousel-item-image" />
<div class="carousel-item-name">{{ item.name }}</div>
</swiper-slide>
</swiper>
<div v-if="deviceStore.currentModel?.isCustom" class="custom-model-wrapper">
<div v-if="deviceStore.currentModel?.isCustom"
:class="['custom-model-wrapper', { 'custom-model-selected': isSelectedCustomModel }]"
:onclick="() => handleSelectedCustomModel()">
<img :src="customModelIcon" class="custom-model-image" />
<div class="custom-model-name">{{ deviceStore.currentModel?.name }}</div>
</div>
Expand Down Expand Up @@ -145,6 +147,7 @@ const espLoaderTerminal = {
const loading = ref(false);
const loadingTip = ref('');
const selectedModel = ref(-1);
const isSelectedCustomModel = ref(false);
const deviceName: Ref<string | null> = ref('');
const deviceVersion: Ref<string | null> = ref('');
Expand Down Expand Up @@ -307,9 +310,26 @@ const burnFirmware = async (isCustom = false) => {
const handleSelectedModel = (index: number) => {
selectedModel.value = index;
isSelectedCustomModel.value = false;
}
const handleSelectedCustomModel = () => {
selectedModel.value = -1;
isSelectedCustomModel.value = true;
}
const handleUpload = async () => {
if (isSelectedCustomModel.value) {
Message.info('The device is running the current model');
return
}
if (selectedModel.value > -1) {
const model = deviceStore.models[selectedModel.value];
if (model.uuid === deviceStore.currentModel?.uuid) {
Message.info('The device is running the current model');
return
}
}
try {
burnFirmware()
} catch (error) {
Expand Down Expand Up @@ -433,6 +453,20 @@ watch(
handelRefresh(val);
}
);
watch(
() => deviceStore.currentModel,
(currentModel) => {
if (currentModel?.isCustom) {
isSelectedCustomModel.value = currentModel?.isCustom
} else {
const index = deviceStore.models.findIndex((model) => {
return model.uuid === currentModel?.uuid
})
selectedModel.value = index
}
}
);
</script>

<style scoped lang="less">
Expand Down Expand Up @@ -532,6 +566,11 @@ watch(
}
}
.custom-model-selected {
border-color: rgb(var(--primary-6));
border-width: 2px;
}
.bottom {
height: 60px;
display: flex;
Expand Down

0 comments on commit 3c3e6a1

Please sign in to comment.