Skip to content

Commit

Permalink
feat: integrate Firebase
Browse files Browse the repository at this point in the history
  • Loading branch information
wutiange authored and LynnL4 committed Jan 18, 2024
1 parent 4fade02 commit 6dd80d3
Show file tree
Hide file tree
Showing 8 changed files with 617 additions and 2 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"dayjs": "^1.11.5",
"echarts": "^5.4.0",
"esptool-js": "^0.3.0",
"firebase": "^10.7.1",
"js-base64": "^3.7.5",
"lodash": "^4.17.21",
"mitt": "^3.0.0",
Expand Down
1 change: 1 addition & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { createApp } from 'vue';
import ArcoVue from '@arco-design/web-vue';
import ArcoVueIcon from '@arco-design/web-vue/es/icon';
import './utils/firebase';
import router from './router';
import store from './store';
import i18n from './locale';
Expand Down
2 changes: 2 additions & 0 deletions src/pages/setup/config/components/Config.vue
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
import { DeviceStatus } from '@/sscma';
import useDeviceManager from '@/hooks/deviceManager';
import { retry } from '@/utils/timer';
import { logEvent } from '@/utils/firebase';
const appStore = useAppStore();
const { device } = useDeviceManager();
Expand Down Expand Up @@ -175,6 +176,7 @@
const change = ref(true);
const handleSubmit = async () => {
logEvent('config', { type: 'Config Wifi Or MQTT', behavior: 'save' });
loading.value = true;
let ret = 0;
if (
Expand Down
3 changes: 3 additions & 0 deletions src/pages/setup/process/components/Config.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import { useDeviceStore } from '@/store';
import useDeviceManager from '@/hooks/deviceManager';
import { DeviceStatus } from '@/sscma';
import { logEvent } from '@/utils/firebase';
const { device } = useDeviceManager();
Expand All @@ -61,13 +62,15 @@
const result = await device.value?.setScore(value as number);
if (Number(result) === Number(value)) {
deviceStore.setScore(Number(result));
logEvent('config', { type: 'Confidence', value });
}
};
const setIou = async (value: number | [number, number]) => {
const result = await device.value?.setIOU(value as number);
if (Number(result) === Number(value)) {
deviceStore.setIOU(Number(result));
logEvent('config', { type: 'iou', value });
}
};
Expand Down
15 changes: 15 additions & 0 deletions src/pages/setup/process/components/Device.vue
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@
import useDeviceManager from '@/hooks/deviceManager';
import { FlashWayType, DeviceWIFIStatus } from '@/store/modules/device';
import { flashErrorHandle } from '@/utils/flash';
import { logEvent } from '@/utils/firebase';
export type FileType<T> = {
data: T;
Expand Down Expand Up @@ -539,6 +540,11 @@
};
const handleUpload = async () => {
logEvent('flash', {
type: 'Prefabricated',
behavior: 'send',
modelName: deviceStore.models[selectedModel.value]?.name,
});
if (deviceStore.flashWay === FlashWayType.ComeToSenseCraftAI) {
if (isComeToFlashFinished.value) {
Message.warning(t('workplace.device.message.model.current'));
Expand Down Expand Up @@ -582,6 +588,7 @@
};
const beforeUpload = (file: File): Promise<boolean> => {
logEvent('flash', { type: 'Custom', behavior: 'before upload' });
return new Promise((resolve) => {
if (file) {
modelFile.value = file;
Expand All @@ -591,6 +598,7 @@
};
const beforeRemove = (fileItem: FileItem): Promise<boolean> => {
logEvent('flash', { type: 'Custom', behavior: 'before remove' });
return new Promise((resolve) => {
const file = fileItem.file;
if (file) {
Expand All @@ -601,6 +609,7 @@
};
const handleAddClass = () => {
logEvent('flash', { type: 'Custom', behavior: 'add class' });
showInput.value = true;
nextTick(() => {
if (inputRef.value) {
Expand All @@ -610,6 +619,7 @@
};
const handleAdd = () => {
logEvent('flash', { type: 'Custom', behavior: 'add' });
if (inputVal.value) {
modelObjects.value.push(inputVal.value);
inputVal.value = '';
Expand All @@ -618,10 +628,12 @@
};
const handleRemove = (key: any) => {
logEvent('flash', { type: 'Custom', behavior: 'remove' });
modelObjects.value = modelObjects.value.filter((tag) => tag !== key);
};
const handleCustomModelOk = async () => {
logEvent('flash', { type: 'Custom', behavior: 'ok' });
try {
if (modalName.value == null || modalName.value === '') {
throw new Error(t('workplace.device.message.model.name'));
Expand All @@ -646,15 +658,18 @@
};
const handleOk = () => {
logEvent('flash', { type: 'Come to SenseCraftAI', behavior: 'ok' });
comeToSenseCraftAIFlash();
visible.value = false;
};
const handleCancel = () => {
logEvent('flash', { type: 'Come to SenseCraftAI', behavior: 'cancel' });
visible.value = false;
};
const onClickGoToConfigWifi = () => {
logEvent('config', { type: 'Go to Config Wifi' });
router.push('/setup/config');
};
Expand Down
3 changes: 3 additions & 0 deletions src/pages/setup/process/components/Preview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import { useDeviceStore } from '@/store';
import useDeviceManager from '@/hooks/deviceManager';
import { DeviceStatus } from '@/sscma';
import { logEvent } from '@/utils/firebase';
const { device, term } = useDeviceManager();
Expand Down Expand Up @@ -73,6 +74,7 @@
const length = computed(() => classes.value.length);
const handleInvoke = async () => {
logEvent('invoke', { behavior: 'invoke' });
const model = await device.value?.getModel();
const isAvailable = model?.id !== undefined;
deviceStore.setCurrentAvailableModel(isAvailable);
Expand All @@ -90,6 +92,7 @@
};
const handleStop = () => {
logEvent('invoke', { behavior: 'stop' });
device.value?.break();
invoke.value = false;
deviceStore.setIsInvoke(false);
Expand Down
26 changes: 26 additions & 0 deletions src/utils/firebase.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { getAnalytics, logEvent as _logEvent } from 'firebase/analytics';
import { initializeApp } from 'firebase/app';

const firebaseConfig = {
apiKey: 'AIzaSyC29Eoxbxk-vSfXr8R1WsyoXmyfkTcCIfA',
authDomain: 'sensecraft-web-toolkit.firebaseapp.com',
projectId: 'sensecraft-web-toolkit',
storageBucket: 'sensecraft-web-toolkit.appspot.com',
messagingSenderId: '735675280733',
appId: '1:735675280733:web:656f1d11574b7a26530cb4',
measurementId: 'G-5X90WMK2M7',
};

// Initialize Firebase
const firebaseApp = initializeApp(firebaseConfig);
const analytics = getAnalytics(firebaseApp);
export function logEvent(
eventName: string,
eventParams?: {
[key: string]: any;
}
) {
_logEvent(analytics, eventName, eventParams);
}

export default analytics;
Loading

0 comments on commit 6dd80d3

Please sign in to comment.