useGenerateAlignerApiStore.js
5.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import axios from 'axios';
import { ElMessage } from 'element-plus';
import { defineStore, storeToRefs } from 'pinia';
import { useRoute } from 'vue-router';
import { useI18n } from 'vue-i18n';
import { useIsLoadingStore } from '@/views/stores/inprogress/useIsLoadingStore';
import { useAlignerParamsStore } from '@/views/stores/modal/useAlignerParamsStore';
import { useClassFunctionStore } from '@/views/stores/useClassFunctionStore';
import { useInProgressStore } from '@/views/stores/inprogress/useInProgressStore';
export const useGenerateAlignerApiStore = defineStore('aligner-generate-api', () => {
const i18n = useI18n();
const route = useRoute();
const loadingStore = useIsLoadingStore();
const { setIsLoading } = loadingStore;
const alignerParamsStore = useAlignerParamsStore();
const { alignerParams } = alignerParamsStore;
const { isBase } = storeToRefs(alignerParamsStore);
const classFunctionStore = useClassFunctionStore();
const { MarkPointsOnMeshClass } = storeToRefs(classFunctionStore);
const { MarkPointsOnMeshClassDispose } = classFunctionStore;
const inProgressStore = useInProgressStore();
const { setCurrentProgress } = inProgressStore;
const ossUrl = 'https://tcloud.luxcreo.cn/oss/';
const generateAlignerUrl = 'https://tcloud.luxcreo.cn/api/step/steptwo';
const errorMessage = (message, error) => {
console.log(error);
ElMessage.error({
message,
duration: 5000,
showClose: true
});
setIsLoading(false);
setCurrentProgress('trimPointDefine');
};
const successMessage = (message) => {
ElMessage.success({
message,
duration: 5000,
showClose: true
});
MarkPointsOnMeshClassDispose();
};
const createOSSFormData = (data, key, file) => {
const uploadData = new FormData();
const { accessid, policy, callback, signature } = data;
uploadData.append('OSSAccessKeyId', accessid);
uploadData.append('policy', policy);
uploadData.append('success_action_status', '200');
uploadData.append('callback', callback);
uploadData.append('Signature', signature);
uploadData.append('key', key);
uploadData.append('file', file);
return uploadData;
};
const postTables = ({ meshKey, trimlineKey }) => {
const { fid } = route.query;
const { markPointPosition } = MarkPointsOnMeshClass.value;
const data = new FormData();
data.append('fid', fid);
data.append('stl', meshKey);
data.append('trimline', trimlineKey);
const isNeedBase = isBase.value ? 1 : 0;
data.append('NeedBase', isNeedBase);
if (markPointPosition) {
data.append('RefPosX', markPointPosition.x);
data.append('RefPosY', markPointPosition.y);
data.append('RefPosZ', markPointPosition.z);
}
alignerParams.forEach((el) => {
const { key, value } = el;
const objectsKey = `${key.replace(/^./, key[0].toUpperCase())}`;
data.append(objectsKey, value);
});
axios
.post(generateAlignerUrl, data)
.then(() => {
setIsLoading(false);
successMessage(i18n.t('alignerloadingSuccess'));
})
.catch((error) => {
errorMessage('postGenerateAlignerParametersError', error);
});
};
const alignerPost = ({ meshKey, meshBlob, trimlineKey, trimlineBlob }) => {
const customConfig = {
headers: {
'Content-Type': 'application/json'
}
};
axios
.get(ossUrl, customConfig)
.then((response) => {
const { data } = response;
const { host } = data;
const ossAxios = axios.create({
headers: {
'Content-Type': 'multipart/form-data'
}
});
const meshFormData = createOSSFormData(data, meshKey, meshBlob);
const trimlineFormData = createOSSFormData(data, trimlineKey, trimlineBlob);
ossAxios
.post(host, trimlineFormData)
.then(() => {
const ossMeshAxios = axios.create({
headers: {
'Content-Type': 'multipart/form-data'
}
});
ossMeshAxios
.post(host, meshFormData)
.then(() => {
postTables({ meshKey, trimlineKey });
})
.catch((error) => {
errorMessage(i18n.t('alignerloadingFail'), error);
});
})
.catch((error) => {
errorMessage(i18n.t('alignerloadingFail'), error);
});
})
.catch((error) => {
errorMessage(i18n.t('getOSSError'), error);
});
};
return {
alignerPost
};
});