|
@@ -358,19 +358,10 @@ struct MyView{
|
|
|
### 3.1.get请求
|
|
|
|
|
|
```tsx
|
|
|
-
|
|
|
HttpHelper.get()
|
|
|
- .get<HttpResult<T>>(url.url.startsWith('http') ? url.url : GlobalValue.getInstance().envUrl + url.url,
|
|
|
+ .get<HttpResult<T>>(url,
|
|
|
data ? JSON.stringify(data) : undefined, {
|
|
|
- userId: GlobalValue.getInstance().userIds,
|
|
|
- clientId: GlobalValue.getInstance().getClientIds(),
|
|
|
- version: ConstantValue.VERSION,
|
|
|
- deviceType: '01',
|
|
|
- timeStamp: timeStamp + '',
|
|
|
- sign: sign,
|
|
|
- phoneModel: 'sign',
|
|
|
- phoneVersion: 'sign',
|
|
|
- phoneBrand: 'HarmonyOS'
|
|
|
+ version: ConstantValue.VERSION
|
|
|
}, url.apiNo)
|
|
|
.then((res: HttpResult<T>) => {
|
|
|
if (res.status === '0') {
|
|
@@ -390,18 +381,10 @@ HttpHelper.get()
|
|
|
```tsx
|
|
|
|
|
|
HttpHelper.get()
|
|
|
- .post<HttpResult<T>>(url.url.startsWith('http') ? url.url : GlobalValue.getInstance().envUrl + url.url,
|
|
|
+ .post<HttpResult<T>>(url,
|
|
|
data ? JSON.stringify(data) : undefined, {
|
|
|
- userId: GlobalValue.getInstance().userIds,
|
|
|
- clientId: GlobalValue.getInstance().getClientIds(),
|
|
|
- version: ConstantValue.VERSION,
|
|
|
- deviceType: '01',
|
|
|
- timeStamp: timeStamp + '',
|
|
|
- sign: sign,
|
|
|
- phoneModel: 'sign',
|
|
|
- phoneVersion: 'sign',
|
|
|
- phoneBrand: 'HarmonyOS'
|
|
|
-}, url.apiNo)
|
|
|
+ version: ConstantValue.VERSION
|
|
|
+}, apiNo)
|
|
|
.then((res: HttpResult<T>) => {
|
|
|
if (res.status === '0') {
|
|
|
resolve(res.data as T)
|
|
@@ -415,6 +398,57 @@ HttpHelper.get()
|
|
|
})
|
|
|
```
|
|
|
|
|
|
+### 3.3.postForm
|
|
|
+
|
|
|
+```tsx
|
|
|
+HttpHelper.get()
|
|
|
+ .postForm<HttpResult<T>>({
|
|
|
+ url: '',
|
|
|
+ data: data,
|
|
|
+ headers: {
|
|
|
+ version: ConstantValue.VERSION,
|
|
|
+ deviceId: GlobalValue.getInstance().deviceId,
|
|
|
+ }
|
|
|
+ }, apiNo, showLog)
|
|
|
+ .then((res: HttpResult<T>) => {
|
|
|
+ if (res.status === '0' || res.code === 200) {
|
|
|
+ resolve(res.data as T)
|
|
|
+ } else {
|
|
|
+ reject(new YWXError(res.status ?? res.code?.toString() ?? '-1', res.message))
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .catch((error: Error) => {
|
|
|
+ reject(new YWXError(error.name ?? '-1', error.message))
|
|
|
+ })
|
|
|
+```
|
|
|
+
|
|
|
+### 3.4.upload
|
|
|
+
|
|
|
+```tsx
|
|
|
+HttpHelper.get()
|
|
|
+ .upload<HttpResult<T>>({
|
|
|
+ url: url,
|
|
|
+ data: data,
|
|
|
+ onProgress,
|
|
|
+ headers: {
|
|
|
+ 'X-Access-Token': HosGlobalValue.getInstance().token,
|
|
|
+ }
|
|
|
+ }, apiNo, showLog)
|
|
|
+ .then((res: HttpResult<T>) => {
|
|
|
+ if (res.code === 200) {
|
|
|
+ resolve(res.data as T)
|
|
|
+ } else if (res.code === 40003) {
|
|
|
+ AccountManager.get().logout()
|
|
|
+ ToolsHelper.showMessage('登录已过期,请重新登录')
|
|
|
+ } else {
|
|
|
+ reject(new YWXError(res.code?.toString() ?? '-1', res.message))
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .catch((error: Error) => {
|
|
|
+ reject(new YWXError(error.name ?? '-1', error.message))
|
|
|
+ })
|
|
|
+```
|
|
|
+
|
|
|
## 4.[自定义view](./src/main/ets/view)
|
|
|
|
|
|
### 4.1.[LoadingView](./src/main/ets/view/LoadingView.ets)
|