dfws-ve-taro-request 0.0.4 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,12 +1,17 @@
1
1
  {
2
2
  "name": "dfws-ve-taro-request",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "description": "东方网升最佳东方小程序Taro公共请求方法",
5
5
  "main": "dist/index.js",
6
6
  "browser": "dist/index.umd.js",
7
7
  "module": "dist/index.esm.js",
8
8
  "source": "src/index.ts",
9
9
  "types": "global.d.ts",
10
+ "files": [
11
+ "lib",
12
+ "dist",
13
+ "types"
14
+ ],
10
15
  "scripts": {
11
16
  "test": "jest",
12
17
  "build:component": "cross-env NODE_ENV=production rollup -c",
package/.babelrc DELETED
@@ -1,9 +0,0 @@
1
- {
2
- "presets": ["@babel/preset-env", "@babel/preset-typescript"],
3
- "plugins": [
4
- [
5
- "@babel/plugin-transform-runtime"
6
- ]
7
- ]
8
- }
9
-
package/rollup.config.js DELETED
@@ -1,71 +0,0 @@
1
- import NodePath from 'path'
2
- import RollupJson from '@rollup/plugin-json'
3
- import RollupNodeResolve from '@rollup/plugin-node-resolve'
4
- import RollupCommonjs from '@rollup/plugin-commonjs'
5
- import RollupTypescript from 'rollup-plugin-typescript2'
6
- import RollupCopy from 'rollup-plugin-copy'
7
-
8
- const resolveFile = path => NodePath.resolve(__dirname, path)
9
-
10
- import Package from './package.json'
11
-
12
- const externalPackages = [
13
- 'react',
14
- 'react-dom',
15
- '@tarojs/components',
16
- '@tarojs/runtime',
17
- '@tarojs/taro',
18
- '@tarojs/react',
19
- 'taro-ui',
20
- 'classname'
21
- ]
22
-
23
- export default {
24
- input: resolveFile('src/index.ts'),
25
- output: [
26
- {
27
- file: resolveFile(Package.main),
28
- format: 'cjs',
29
- sourcemap: true
30
- },
31
- {
32
- file: resolveFile(Package.module),
33
- format: 'es',
34
- sourcemap: true,
35
- },
36
- {
37
- file: resolveFile(Package.browser),
38
- format: 'umd',
39
- name: 'dfws-trao-request',
40
- sourcemap: true,
41
- globals: {
42
- react: 'React',
43
- '@tarojs/components': 'components',
44
- '@tarojs/taro': 'Taro'
45
- }
46
- }
47
- ],
48
- external: externalPackages,
49
- plugins: [
50
- RollupNodeResolve({
51
- customResolveOptions: {
52
- moduleDirectory: 'node_modules'
53
- }
54
- }),
55
- RollupCommonjs({
56
- include: /\/node_modules\//
57
- }),
58
- RollupJson(),
59
- RollupTypescript({
60
- tsconfig: resolveFile('tsconfig.rollup.json')
61
- }),
62
- // RollupCopy({
63
- // targets: [
64
- // {
65
- // src: resolveFile('src/'),
66
- // dest: resolveFile('dist')
67
- // }
68
- // ]
69
- // })
70
- ]
71
- }
@@ -1,8 +0,0 @@
1
- // 接口加密密钥
2
- export const secretkey:string = "dz15z9z2z15z11z8zf";
3
-
4
- // 图片验证码加密密钥
5
- export const captchaKey = "3dz2dz2bzcz8z30z2hz2nz3dz2nz2mz2oz2n";
6
-
7
- // 项目渠道配置:管理后台-138美业人才-系统设置-渠道管理
8
- export const channel:IChannel = { "project": "VE", "origin": "C", "platform": "XCX", "device": "ZJDF", "version": "1.0.0" };
package/src/global.d.ts DELETED
@@ -1,56 +0,0 @@
1
- declare module '*.png'
2
- declare module '*.gif'
3
- declare module '*.jpg'
4
- declare module '*.jpeg'
5
- declare module '*.svg'
6
- declare module '*.css'
7
- declare module '*.scss'
8
-
9
- declare var App: {
10
- BJ_REPORT:any
11
- }
12
- declare var Taro: any
13
- /**
14
- * 全局状态
15
- */
16
-
17
- interface IResponse{
18
- status: number
19
- data: T
20
- errCode: string
21
- errMsg: string
22
- statusCode: number
23
- }
24
-
25
- interface IOptions {
26
- url: string
27
- data?: T
28
- method: string
29
- }
30
-
31
- interface IHeaders {
32
- authorization?: string
33
- version?: string
34
- params?: string
35
- 'content-type'?: string
36
- 'resume-language'?: string
37
- }
38
- interface IChannel {
39
- project?:string
40
- origin?:string
41
- platform?:string
42
- device?:string
43
- version?: string
44
- network?:string
45
- }
46
- /**
47
- * dva异步方法调用
48
- */
49
- type IDispatch = (object: { type: string; payload?: object; callback?: (res: any) => void }) => any
50
-
51
- interface IEffectsAction {
52
- //参数
53
- payload?: any
54
- //回调
55
- callback?: (res?: any | boolean) => void
56
- }
package/src/index.ts DELETED
@@ -1,31 +0,0 @@
1
- // import Taro from '@tarojs/taro'
2
- import getPublicChannel from "dfws-channel/dist/taro"
3
- import { channel } from './config'
4
- import request from "./utils/request";
5
- import { decryptByDES, encryptByDES, encryptBySso } from "./utils/instance";
6
-
7
- export default {
8
- request: (taro: any, projectChannel: IChannel = {}, url: string, data: any, method: string, headers: any = {}, debug: boolean = false) => {
9
- /**
10
- * 东方网升项目公共 header
11
- * @param {object} dfws_params
12
- */
13
- const dfws_header = getPublicChannel({ ...channel, ...projectChannel }, taro)
14
- // 获取网络环境
15
- dfws_header.getNetworkType((network: string) => {
16
- channel.network = network
17
- })
18
-
19
- return request(url, data, method, {
20
- version: channel.version,
21
- params: JSON.stringify(dfws_header.queryChannels()),
22
- ...headers
23
- }, taro, debug)
24
- },
25
- // 接口解密
26
- decryptByDES,
27
- // 接口加密
28
- encryptByDES,
29
- // 验证码加密
30
- encryptBySso
31
- }
@@ -1,48 +0,0 @@
1
- import dfwsCrypto from "dfws-crypto";
2
- import { secretkey, captchaKey } from "../config";
3
-
4
- // 是否进行接口解密
5
- export const isEncoding = (url = '') => {
6
- return url.includes('/sso/v1/') || url.includes('/resume/v1/');
7
- };
8
- // 加密
9
- export const encryptByDES = (params: object | string, debug: boolean = false) => {
10
- debug && console.log(`请求参数:`, params)
11
- return encodeURIComponent(
12
- dfwsCrypto.encryptByDES(JSON.stringify(params), secretkey)
13
- );
14
- };
15
- //解密
16
- export const decryptByDES = (params: string, debug: boolean = false) => {
17
- const data = JSON.parse(dfwsCrypto.decryptByDES(params, secretkey));
18
- debug && console.log(`获取内容:`, data)
19
- return data
20
- };
21
- // 对象转URL字符串
22
- export const objectToQueryString = (obj: object) => {
23
- return Object.keys(obj)
24
- .map(key => {
25
- const value = obj[key];
26
- // 编码键和值以处理特殊字符
27
- return `${(key)}=${value}`;
28
- })
29
- .join('&');
30
- }
31
-
32
- //短信/邮箱验证码加密
33
- export const encryptBySso = (value: string) => {
34
- const key = Date.parse(new Date().toString())
35
- const sign = dfwsCrypto.encryptByDES(`${dfwsCrypto.decrypto(captchaKey, 123, 25)}${value}${key}`, secretkey)
36
- return {
37
- check_sign: sign,
38
- check_key: key,
39
- }
40
- };
41
-
42
- export default {
43
- isEncoding,
44
- encryptByDES,
45
- decryptByDES,
46
- encryptBySso,
47
- objectToQueryString
48
- };
@@ -1,124 +0,0 @@
1
- // import Taro from '@tarojs/taro';
2
- import {
3
- isEncoding,
4
- encryptByDES,
5
- decryptByDES,
6
- objectToQueryString,
7
- } from "./instance";
8
-
9
- const codeMessage = {
10
- 200: '服务器成功返回请求的数据。',
11
- 201: '新建或修改数据成功。',
12
- 202: '一个请求已经进入后台排队(异步任务)。',
13
- 204: '删除数据成功。',
14
- 400: '发出的请求有错误,服务器没有进行新建或修改数据的操作。',
15
- 401: '用户没有权限(令牌、用户名、密码错误)。',
16
- 403: '用户得到授权,但是访问是被禁止的。',
17
- 404: '发出的请求针对的是不存在的记录,服务器没有进行操作。',
18
- 406: '请求的格式不可得。',
19
- 410: '请求的资源被永久删除,且不会再得到的。',
20
- 422: '当创建一个对象时,发生一个验证错误。',
21
- 500: '服务器发生错误,请检查服务器。',
22
- 502: '网关错误。',
23
- 503: '服务不可用,服务器暂时过载或维护。',
24
- 504: '网关超时。',
25
- };
26
-
27
- // 错误上报监控系统
28
- const onErrorMsgRrport = (response: IResponse, options: IOptions, Taro: any) => {
29
- const { statusCode } = response;
30
- const { method = "get", url, data } = options;
31
- const errorText = codeMessage[statusCode] || '';
32
- const statusParams = data;
33
- const encoding =
34
- isEncoding(url) &&
35
- response.data?.type !== "application/octet-stream";
36
- const errorData = {
37
- 'id': '9',
38
- 'uin': Taro.getStorageSync('ticket') || "",
39
- 'msg[0]':
40
- `后端又挂了,${statusCode}: ${errorText}请求方式:${method},参数:${encoding && statusParams
41
- ? decryptByDES(unescape(statusParams)) || JSON.stringify(statusParams)
42
- : JSON.stringify(statusParams)
43
- }`, // 错误信息
44
- 'target[0]': url, // 错误的来源js
45
- 'romNum[0]': '0',
46
- 'colNum[0]': '0',
47
- 'from[0]': '最佳东方小程序',
48
- 'level[0]': '4',
49
- 'count': '1',
50
- '_t': new Date().getTime()
51
- }
52
-
53
- Taro.request({
54
- url: "https://probe.dfwsgroup.com/badjs",
55
- method: "get",
56
- data: errorData
57
- }).then((res: any) => {
58
- console.log('error:', res);
59
- }).catch((err: object) => {
60
- console.log('error:', err);
61
- })
62
- };
63
-
64
- const checkStatus = (response: IResponse, options: IOptions, Taro: any) => {
65
- const { statusCode, data } = response;
66
- if (statusCode >= 200 && statusCode < 300) {
67
- data.status = 1;
68
- data.errMsg = "";
69
- return data;
70
- }
71
- if (statusCode === 401) {
72
- Taro.clearStorage(); // 清除token
73
- Taro.removeStorage({ key: 'ticket' })
74
- Taro.removeStorage({ key: 'user_id' })
75
- data.status = 0;
76
- data.errMsg = ""
77
- return data
78
- } else {
79
- Taro.showToast({
80
- title: '网络异常,请稍后重试',
81
- icon: 'none',
82
- });
83
- // 上报前端监控系统
84
- return onErrorMsgRrport(response, options, Taro);
85
- }
86
- };
87
-
88
- export default (url: string, data: object, method: any = 'get', header: IHeaders, Taro: any, debug: boolean = false) => {
89
-
90
- const isEncode = isEncoding(url) // 判断是否加密
91
- const isMethod = method.toLocaleLowerCase() === 'get' && Object.keys(data).length // 请求方式get而且加密处理
92
- if (isMethod) {
93
- url = "".concat(url, "?").concat(isEncode ? encryptByDES(objectToQueryString(data), debug) : objectToQueryString(data));
94
- }
95
- return Taro.request({
96
- url: url,
97
- data: isEncode ? encryptByDES(data, debug) : data,
98
- method,
99
- timeout: 15000,
100
- header: {
101
- 'authorization': Taro.getStorageSync('ticket'),
102
- 've-version': header.version || '1.0.0',
103
- 'dfws-params': header.params || '',
104
- 'content-type': header["content-type"] || 'application/json',
105
- 'resume-language': header['resume-language'] || 'zh-CN',
106
- }
107
- }).then((res: any) => {
108
- const response: any = isEncode ? {
109
- ...res,
110
- data: decryptByDES(unescape(res.data), debug)
111
- } : res;
112
- return checkStatus(response, { url, data, method }, Taro);
113
- }).catch((err: object) => {
114
- console.log('error:', err);
115
- Taro.showToast({
116
- title: '网络异常,请稍后重试',
117
- icon: 'none',
118
- });
119
- return {
120
- status: 0,
121
- errMsg: '',
122
- };
123
- });
124
- };
@@ -1,28 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "allowSyntheticDefaultImports": true,
4
- "experimentalDecorators": true,
5
- "jsx": "react",
6
- "jsxFactory": "React.createElement",
7
- "moduleResolution": "node",
8
- "noImplicitAny": false,
9
- "noUnusedLocals": true,
10
- "noUnusedParameters": true,
11
- "preserveConstEnums": true,
12
- "skipLibCheck": true,
13
- "sourceMap": true,
14
- "strictNullChecks": true,
15
- "resolveJsonModule": true,
16
- "target": "es2017",
17
- "module": "es6",
18
- "outDir": "./lib"
19
- },
20
- "compileOnSave": false,
21
- "exclude": [
22
- "node_modules/*",
23
- "dist/*"
24
- ],
25
- "include": [
26
- "src/**/*"
27
- ]
28
- }
package/tsconfig.json DELETED
@@ -1,32 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "allowSyntheticDefaultImports": true,
4
- "experimentalDecorators": true,
5
- "jsx": "react",
6
- "jsxFactory": "React.createElement",
7
- "moduleResolution": "node",
8
- "noImplicitAny": false,
9
- "noUnusedLocals": true,
10
- "noUnusedParameters": true,
11
- "preserveConstEnums": true,
12
- "skipLibCheck": true,
13
- "sourceMap": true,
14
- "strictNullChecks": true,
15
- "resolveJsonModule": true,
16
- "target": "es2017",
17
- "module": "commonjs",
18
- "baseUrl": "./",
19
- "typeRoots": [
20
- "node_modules/@types",
21
- "global.d.ts"
22
- ],
23
- "types": [
24
- "taro-ui"
25
- ]
26
- },
27
- "compileOnSave": false,
28
- "exclude": [
29
- "node_modules/*",
30
- "dist/*"
31
- ]
32
- }
@@ -1,30 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "allowSyntheticDefaultImports": true,
4
- "experimentalDecorators": true,
5
- "jsx": "react",
6
- "jsxFactory": "React.createElement",
7
- "moduleResolution": "node",
8
- "noImplicitAny": false,
9
- "noUnusedLocals": true,
10
- "noUnusedParameters": true,
11
- "preserveConstEnums": true,
12
- "skipLibCheck": true,
13
- "sourceMap": true,
14
- "strictNullChecks": true,
15
- "resolveJsonModule": true,
16
- "target": "es5",
17
- "module": "es6",
18
- "downlevelIteration": true,
19
- "baseUrl": ".",
20
- "types": ["node"]
21
- },
22
- "compileOnSave": false,
23
- "exclude": [
24
- "node_modules/*",
25
- "dist/*"
26
- ],
27
- "include": [
28
- "src/**/*"
29
- ]
30
- }