优化代码

This commit is contained in:
wuxw 2025-03-18 17:52:16 +08:00
parent 07346b3b3f
commit b8e649de05
11 changed files with 379 additions and 4 deletions

View File

@ -13,8 +13,8 @@ import {getStaffId,getStaffName,getStaffTel} from './api/staff/staff.js';
import store from './store'
import cuCustom from './lib/colorui/components/cu-custom.vue'
// import {VueJsonp} from 'vue-jsonp'
// Vue.use(VueJsonp)
import {VueJsonp} from 'vue-jsonp'
Vue.use(VueJsonp)
Vue.component('cu-custom',cuCustom)
Vue.config.productionTip = false

5
node_modules/.package-lock.json generated vendored
View File

@ -7,6 +7,11 @@
"version": "2.0.5",
"resolved": "https://registry.npmjs.org/file-saver/-/file-saver-2.0.5.tgz",
"integrity": "sha512-P9bmyZ3h/PRG+Nzga+rbdI4OEpNDzAVyy74uVO9ATgzLK6VtAsYybF/+TOCvrc0MO793d6+42lLyZTw7/ArVzA=="
},
"node_modules/vue-jsonp": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/vue-jsonp/-/vue-jsonp-2.1.0.tgz",
"integrity": "sha512-kezmjaAcMWdieO3tWxniC+82DitYUYjR1e2GsWIKHCTf+zhWUt2nPhN3dnmnAVhDQ+po3BspM7sKjiQaIhijUg=="
}
}
}

21
node_modules/vue-jsonp/LICENSE generated vendored Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2020 LancerComet
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

155
node_modules/vue-jsonp/README.md generated vendored Normal file
View File

@ -0,0 +1,155 @@
# Vue-jsonp
[![npm version](https://badge.fury.io/js/vue-jsonp.svg)](https://badge.fury.io/js/vue-jsonp)
[![VueJsonp](https://github.com/LancerComet/vue-jsonp/workflows/Test/badge.svg)](https://github.com/LancerComet/vue-jsonp/actions)
A tiny library for handling JSONP request.
## Quick Start
As Vue plugin:
```ts
import { VueJsonp } from 'vue-jsonp'
// Vue Plugin.
Vue.use(VueJsonp)
// Now you can use "$jsonp" on Vue components.
const vm = new Vue()
const data = await vm.$jsonp('/some-jsonp-url', {
myCustomUrlParam: 'veryNice'
})
```
Use function directly:
```ts
import { jsonp } from 'vue-jsonp'
// Pass a response type.
const data = await jsonp<string>('/some-jsonp-url', {
myCustomUrlParam: 'veryNice'
})
```
## Send data and set query & function name
### Send data
```ts
// The request url will be "/some-jsonp-url?type=admin&date=2020&callback=jsonp_{RANDOM_STR}".
const data = await jsonp('/some-jsonp-url', {
type: 'admin',
date: 2020
})
```
### Custom query & function name
The url uniform is `/url?{callbackQuery}={callbackName}&...` and the default is `/url?callback=jsonp_{RANDOM_STRING}&...`.
And you can change it like this:
```ts
// The request url will be "/some-jsonp-url?type=admin&date=2020&cb=jsonp_func".
jsonp('/some-jsonp-url', {
callbackQuery: 'cb',
callbackName: 'jsonp_func',
type: 'admin',
date: 2020
})
```
## Module exports
- `VueJsonp: PluginObject<never>`
- `jsonp<T>: (url: string, param?: IJsonpParam, timeout?: number) => Promise<T>`
## API
### IJsonpParam
IJsonpParam is the type of param for jsonp function.
```ts
/**
* JSONP parameter declaration.
*/
interface IJsonpParam {
/**
* Callback query name.
* This param is used to define the query name of the callback function.
*
* @example
* // The request url will be "/some-url?myCallback=jsonp_func&myCustomUrlParam=veryNice"
* const result = await jsonp('/some-url', {
* callbackQuery: 'myCallback',
* callbackName: 'jsonp_func',
* myCustomUrlParam: 'veryNice'
* })
*
* @default callback
*/
callbackQuery?: string
/**
* Callback function name.
* This param is used to define the jsonp function name.
*
* @example
* // The request url will be "/some-url?myCallback=jsonp_func&myCustomUrlParam=veryNice"
* const result = await jsonp('/some-url', {
* callbackQuery: 'myCallback',
* callbackName: 'jsonp_func',
* myCustomUrlParam: 'veryNice'
* })
*
* @default jsonp_ + randomStr()
*/
callbackName?: string
/**
* Custom data.
*/
[key: string]: any
}
```
## Example
```ts
import Vue from 'vue'
import { VueJsonp } from 'vue-jsonp'
Vue.use(VueJsonp)
const vm = new Vue()
const { code, data, message } = await vm.$jsonp<{
code: number,
message: string,
data: {
id: number,
nickname: string
}
}>('/my-awesome-url', {
name: 'MyName', age: 20
})
assert(code === 0)
assert(message === 'ok')
assert(data.id === 1)
assert(data.nickname === 'John Smith')
```
```ts
import { jsonp } from 'vue-jsonp'
const result = await jsonp<string>('/my-awesome-url')
assert(result === 'such a jsonp')
```
## License
MIT

101
node_modules/vue-jsonp/dist/index.d.ts generated vendored Normal file
View File

@ -0,0 +1,101 @@
/**
* Vue Jsonp.
* # Carry Your World #
*
* @author: LancerComet
* @license: MIT
*/
import { PluginObject } from 'vue/types/plugin';
declare module 'vue/types/vue' {
interface Vue {
$jsonp: typeof jsonp;
}
}
/**
* JSONP Vue plugin.
*
* @example
* Vue.use(VueJsonp)
*/
declare const VueJsonp: PluginObject<never>;
/**
* Make a json request.
*
* @template T
* @param {string} url Target URL address.
* @param {IJsonpParam} [param={}] Querying params object.
* @param {number} [timeout] Timeout setting (ms).
* @returns {Promise<T>}
*
* @example
* const data = await jsonp<string>('/url', {
* type: 'admin',
* date: '2020'
* })
*/
declare function jsonp<T = any>(url: string, param?: IJsonpParam, timeout?: number): Promise<T>;
declare function jsonp<T = any>(url: string, param?: IJsonpParam, config?: IConfig): Promise<T>;
export { VueJsonp, jsonp };
/**
* JSONP parameter declaration.
*/
interface IJsonpParam {
/**
* Callback query name.
* This param is used to define the query name of the callback function.
*
* @example
* // The request url will be "/some-url?myCallback=jsonp_func&myCustomUrlParam=veryNice"
* const result = await jsonp('/some-url', {
* callbackQuery: 'myCallback',
* callbackName: 'jsonp_func',
* myCustomUrlParam: 'veryNice'
* })
*
* @default callback
*/
callbackQuery?: string;
/**
* Callback function name.
* This param is used to define the jsonp function name.
*
* @example
* // The request url will be "/some-url?myCallback=jsonp_func&myCustomUrlParam=veryNice"
* const result = await jsonp('/some-url', {
* callbackQuery: 'myCallback',
* callbackName: 'jsonp_func',
* myCustomUrlParam: 'veryNice'
* })
*
* @default jsonp_ + randomStr()
*/
callbackName?: string;
/**
* Custom data.
*/
[key: string]: any;
}
/**
* JSONP Config.
*/
interface IConfig {
/**
* Request timeout, ms.
*
* @default 5000
*/
timeout?: number;
/**
* This is the indicator that used in query string to indicate arrays.
*
* @example
* // When you pass a '[]' or nothing:
* a[]=1&a[]=2&a[]=3 // This form is used widely.
*
* // An empty sring was passed:
* a=1&a=2&a=3 // This is a custom example.
*
* @default '[]'
*/
arrayIndicator?: string;
}

8
node_modules/vue-jsonp/dist/index.esm.js generated vendored Normal file
View File

@ -0,0 +1,8 @@
function e(t,o,n){void 0===n&&(n="[]"),t=t.replace(/=/g,"");var r=[];if(null==o)return r;switch(o.constructor){case String:case Number:case Boolean:r.push(encodeURIComponent(t)+"="+encodeURIComponent(o));break;case Array:o.forEach((function(o){r=r.concat(e(""+t+n+"=",o,n))}));break;case Object:Object.keys(o).forEach((function(a){var c=o[a];r=r.concat(e(t+"["+a+"]",c,n))}))}return r}function t(e){var o=[];return e.forEach((function(e){"string"==typeof e?o.push(e):o=o.concat(t(e))})),o}
/**
* Vue Jsonp.
* # Carry Your World #
*
* @author: LancerComet
* @license: MIT
*/var o={install:function(e){e.prototype.$jsonp=n}};function n(o,n,r){var a;if(void 0===n&&(n={}),"string"!=typeof o)throw new Error('[Vue-jsonp] Type of param "url" is not string.');if("object"!=typeof n||!n)throw new Error("[Vue-jsonp] Invalid params, should be an object.");var c="number"==typeof r?r:null!==(a=null==r?void 0:r.timeout)&&void 0!==a?a:5e3,i="[]";if("object"==typeof r){var u=r.arrayIndicator;"string"==typeof u&&(i=u)}return new Promise((function(r,a){var u="string"==typeof n.callbackQuery?n.callbackQuery:"callback",s="string"==typeof n.callbackName?n.callbackName:"jsonp_"+(Math.floor(1e5*Math.random())*Date.now()).toString(16);n[u]=s,delete n.callbackQuery,delete n.callbackName;var l=[];Object.keys(n).forEach((function(t){l=l.concat(e(t,n[t],i))}));var f=t(l).join("&"),d=function(){p(),clearTimeout(b),a({status:400,statusText:"Bad Request"})},p=function(){v.removeEventListener("error",d)},m=function(){document.body.removeChild(v),delete window[s]},b=null;c>-1&&(b=setTimeout((function(){p(),m(),a({statusText:"Request Timeout",status:408})}),c)),window[s]=function(e){clearTimeout(b),p(),m(),r(e)};var v=document.createElement("script");v.addEventListener("error",d),v.src=o+(/\?/.test(o)?"&":"?")+f,document.body.appendChild(v)}))}export{o as VueJsonp,n as jsonp};

8
node_modules/vue-jsonp/dist/index.js generated vendored Normal file
View File

@ -0,0 +1,8 @@
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).VueJsonp={})}(this,(function(e){"use strict";function t(e,o,n){void 0===n&&(n="[]"),e=e.replace(/=/g,"");var r=[];if(null==o)return r;switch(o.constructor){case String:case Number:case Boolean:r.push(encodeURIComponent(e)+"="+encodeURIComponent(o));break;case Array:o.forEach((function(o){r=r.concat(t(""+e+n+"=",o,n))}));break;case Object:Object.keys(o).forEach((function(a){var c=o[a];r=r.concat(t(e+"["+a+"]",c,n))}))}return r}function o(e){var t=[];return e.forEach((function(e){"string"==typeof e?t.push(e):t=t.concat(o(e))})),t}
/**
* Vue Jsonp.
* # Carry Your World #
*
* @author: LancerComet
* @license: MIT
*/var n={install:function(e){e.prototype.$jsonp=r}};function r(e,n,r){var a;if(void 0===n&&(n={}),"string"!=typeof e)throw new Error('[Vue-jsonp] Type of param "url" is not string.');if("object"!=typeof n||!n)throw new Error("[Vue-jsonp] Invalid params, should be an object.");var c="number"==typeof r?r:null!==(a=null==r?void 0:r.timeout)&&void 0!==a?a:5e3,i="[]";if("object"==typeof r){var u=r.arrayIndicator;"string"==typeof u&&(i=u)}return new Promise((function(r,a){var u="string"==typeof n.callbackQuery?n.callbackQuery:"callback",s="string"==typeof n.callbackName?n.callbackName:"jsonp_"+(Math.floor(1e5*Math.random())*Date.now()).toString(16);n[u]=s,delete n.callbackQuery,delete n.callbackName;var f=[];Object.keys(n).forEach((function(e){f=f.concat(t(e,n[e],i))}));var l=o(f).join("&"),d=function(){p(),clearTimeout(m),a({status:400,statusText:"Bad Request"})},p=function(){y.removeEventListener("error",d)},b=function(){document.body.removeChild(y),delete window[s]},m=null;c>-1&&(m=setTimeout((function(){p(),b(),a({statusText:"Request Timeout",status:408})}),c)),window[s]=function(e){clearTimeout(m),p(),b(),r(e)};var y=document.createElement("script");y.addEventListener("error",d),y.src=e+(/\?/.test(e)?"&":"?")+l,document.body.appendChild(y)}))}e.VueJsonp=n,e.jsonp=r,Object.defineProperty(e,"__esModule",{value:!0})}));

20
node_modules/vue-jsonp/dist/utils/index.d.ts generated vendored Normal file
View File

@ -0,0 +1,20 @@
/**
* Generate random string.
*
* @return { string }
*/
declare function randomStr(): string;
/**
* Format params into querying string.
*
* @return {string[]}
*/
declare function formatParams(queryKey: string, value: any, arrayIndicator?: string): string[];
/**
* Flat querys.
*
* @param {string[] | (string[])[]} array
* @returns
*/
declare function flatten(array: string[] | (string[])[]): string[];
export { formatParams, flatten, randomStr };

50
node_modules/vue-jsonp/package.json generated vendored Normal file
View File

@ -0,0 +1,50 @@
{
"name": "vue-jsonp",
"version": "2.1.0",
"description": "A tiny library for handling JSONP request.",
"main": "./dist/index.js",
"module": "./dist/index.esm.js",
"keywords": [
"Vue",
"JSONP"
],
"files": [
"dist/",
"index.d.ts",
"README.md"
],
"scripts": {
"build": "rollup -c",
"test": "jest",
"pretest": "npm run build",
"preversion": "npm run test",
"prepublish": "npm run test"
},
"author": {
"name": "LancerComet",
"email": "chw644@hotmail.com"
},
"repository": {
"type": "git",
"url": "https://github.com/LancerComet/vue-jsonp.git"
},
"license": "MIT",
"devDependencies": {
"@types/expect-puppeteer": "^4.4.3",
"@types/jest": "^26.0.14",
"@types/jest-environment-puppeteer": "^4.4.0",
"@types/puppeteer": "^3.0.2",
"jest": "^26.4.2",
"jest-puppeteer": "^4.4.0",
"puppeteer": "^5.3.1",
"rollup": "^2.28.2",
"rollup-plugin-cleanup": "^3.2.1",
"rollup-plugin-delete": "^2.0.0",
"rollup-plugin-terser": "^7.0.2",
"rollup-plugin-typescript2": "^0.27.3",
"ts-jest": "^26.4.1",
"tslint": "^6.1.3",
"typescript": "^4.0.3",
"vue": "^2.6.12"
}
}

8
package-lock.json generated
View File

@ -5,13 +5,19 @@
"packages": {
"": {
"dependencies": {
"file-saver": "^2.0.5"
"file-saver": "^2.0.5",
"vue-jsonp": "^2.1.0"
}
},
"node_modules/file-saver": {
"version": "2.0.5",
"resolved": "https://registry.npmjs.org/file-saver/-/file-saver-2.0.5.tgz",
"integrity": "sha512-P9bmyZ3h/PRG+Nzga+rbdI4OEpNDzAVyy74uVO9ATgzLK6VtAsYybF/+TOCvrc0MO793d6+42lLyZTw7/ArVzA=="
},
"node_modules/vue-jsonp": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/vue-jsonp/-/vue-jsonp-2.1.0.tgz",
"integrity": "sha512-kezmjaAcMWdieO3tWxniC+82DitYUYjR1e2GsWIKHCTf+zhWUt2nPhN3dnmnAVhDQ+po3BspM7sKjiQaIhijUg=="
}
}
}

View File

@ -1,5 +1,6 @@
{
"dependencies": {
"file-saver": "^2.0.5"
"file-saver": "^2.0.5",
"vue-jsonp": "^2.1.0"
}
}