Commit 35571c66 by liimin

init

0 parents
module.exports = {
root: true,
env: {
node: true
},
parser: '@typescript-eslint/parser',
parserOptions: {
parser: 'babel-eslint'
},
rules: {
'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off'
}
}
.DS_Store
node_modules
# local env files
.env.local
.env.*.local
# Log files
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
# Editor directories and files
.idea
.vscode
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
{
"printWidth": 800,
"tabWidth": 2,
"singleQuote": true,
"trailingComma": "none",
"semi": false,
"wrap_line_length": 820,
"wrap_attributes": "auto",
"proseWrap": "always",
"arrowParens": "avoid",
"bracketSpacing": true,
"htmlWhitespaceSensitivity": "ignore",
"javascript.format.insertSpaceBeforeFunctionParenthesis": true,
"jsxBracketSameLine": true,
"files.insertFinalNewline": true,
"prettier.ignorePath": ".prettierignore",
"useTabs": false,
"eslintIntegration": false,
"overrides": [
{
"files": ".prettierrc",
"options": {
"parser": "json"
}
}
],
"endOfLine": "auto"
}
This diff could not be displayed because it is too large.
{
"name": "glsx-common-sdk",
"version": "0.2.0",
"description": "glsx-common-sdk",
"main": "src/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "rollup -c",
"doc":"jsdoc src/index.js"
},
"author": "limin",
"license": "ISC",
"devDependencies": {
"rollup": "^1.32.1",
"rollup-plugin-babel": "^4.4.0",
"rollup-plugin-commonjs": "^10.1.0",
"rollup-plugin-eslint": "^7.0.0",
"rollup-plugin-node-polyfills": "^0.2.1",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-replace": "^2.2.0",
"rollup-plugin-uglify": "^6.0.4"
}
}
import resolve from 'rollup-plugin-node-resolve'
import commonjs from 'rollup-plugin-commonjs'
import { eslint } from 'rollup-plugin-eslint'
import babel from 'rollup-plugin-babel'
import replace from 'rollup-plugin-replace'
import { uglify } from 'rollup-plugin-uglify'
const packages = require('./package.json')
export default {
input: `src/index.js`,
output: {
file: `dist/${packages.name}.js`,
format: 'umd',
name: packages.name
},
plugins: [
resolve(),
commonjs(),
eslint({
include: ['src/**'],
exclude: ['node_modules/**']
}),
babel({
exclude: 'node_modules/**',
runtimeHelpers: true
}),
replace({
exclude: 'node_modules/**',
ENV: JSON.stringify(process.env.NODE_ENV)
}),
uglify()
]
}
/*
* @Descripttion: 常量类
* @version: 1.0.0
* @Author: limin
* @Date: 2023-07-04 17:40:51
* @LastEditors: limin
* @LastEditTime: 2023-07-05 08:48:32
* @FilePath: \glsx-map-sdk\src\constants.js
*/
export const MAP_OPTIONS = { domain: 'https://restapi.amap.com', KEY: '373bd88fa36ebc0247d60281386b6cec', SECRET: 'a2a93fa04721a36819d86b71cb31fe41' }
/*
* @Descripttion:帮助类
* @version: 1.0.0
* @Author: limin
* @Date: 2023-07-04 17:37:45
* @LastEditors: limin
* @LastEditTime: 2023-07-05 08:46:52
* @FilePath: \glsx-map-sdk\src\helper.js
*/
export const isMiniprogram = !window
/*
* @Descripttion:
* @version: 1.0.0
* @Author: limin
* @Date: 2023-08-15 16:37:55
* @LastEditors: limin
* @LastEditTime: 2023-08-15 18:21:22
* @FilePath: \glsx-common-sdk\src\index.js
*/
import Request from './request/index'
class GLCommon {
constructor(params = {}) {
const { key, secret } = params
this.request = new Request(key, secret)
}
}
export default GLCommon
/*
* @Descripttion: 定义一个Request类,用于封装请求高德地图API的方法
* @version: 1.0.0
* @Author: limin
* @Date: 2023-07-04 17:25:31
* @LastEditors: limin
* @LastEditTime: 2023-08-15 18:10:22
* @FilePath: \glsx-common-sdk\src\request\index.js
*/
import md5 from '../lib/md5'
import qs from '../lib/qs'
import wxRequest from './wx'
import webRequest from './web'
import { isMiniprogram } from '../helper/index'
class Request {
// 构造函数,接收key和secret作为参数,如果没有传入,则使用默认值
constructor(key = MAP_OPTIONS.KEY, secret = MAP_OPTIONS.SECRET) {
// 将key和secret赋值给实例属性
this.key = key
this.secret = secret
}
/**对参数进行排序:按参数名升序 */
setLocaleCompare(params) {
// 将key添加到参数对象中
params.key = this.key
return Object.fromEntries(Object.entries(params).sort(([a], [b]) => a.localeCompare(b)))
}
/**签名计算(sig) */
getSign(params) {
return md5(`${decodeURIComponent(qs.stringify(this.setLocaleCompare(params)))}${this.secret}`)
}
/**封装的GET方法 */
get(method, data) {
// 调用request方法,传入请求方式为GET,请求路径为method,请求数据为data
return this.request('GET', method, data)
}
/**封装的请求方法 */
async request(RequestMethods, method, data = {}) {
// 调用getSign方法,传入请求数据和请求路径,得到签名
const sig = this.getSign(data, method),
obj = {
...this.setLocaleCompare(data),
sig
}
return await [webRequest,wxRequest][+isMiniprogram](RequestMethods, method, obj)
}
}
export default Request
import { MAP_OPTIONS } from '../helper/constants'
export default async (RequestMethods, method, obj = {}) => {
const params = []
Object.keys(obj).map(key => {
params.push(`${key}=${encodeURIComponent(obj[key])}`)
})
try {
const res = await window.fetch(`${MAP_OPTIONS.domain}${method}?${params.join('&')}`, {
method: RequestMethods
})
const data = await res.json()
if (data.status == '1') return data
else throw data.info
} catch (error) {
console.error(`接口异常:`, error)
throw error
}
}
import { MAP_OPTIONS } from '../helper/constants'
export default async (RequestMethods, method, params = {}) => {
wx.showNavigationBarLoading()
try {
const res = await new Promise((resolve, reject) => {
wx.request({
url: `${MAP_OPTIONS.domain}${method}`,
data:params,
method: RequestMethods,
header:
RequestMethods === 'POST'
? {
'content-type': 'application/json'
}
: {},
dataType: 'json',
responseType: 'text',
success: resolve,
fail: reject
})
})
const { statusCode, data, errMsg } = res
if (statusCode == '200') {
if (data.status == '1') {
return data
} else {
wx.showToast({
title: data.info,
icon: 'none'
})
}
} else {
wx.showToast({
title: errMsg,
icon: 'error'
})
}
} catch (error) {
wx.hideLoading()
console.error(`接口异常:`, error)
wx.showToast({
title: '系统异常',
icon: 'error'
})
throw error
} finally {
wx.hideNavigationBarLoading()
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!