From b8e649de052787b8d79edb2dd5f2a2b3c5ae8006 Mon Sep 17 00:00:00 2001 From: wuxw <928255095@qq.com> Date: Tue, 18 Mar 2025 17:52:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.js | 4 +- node_modules/.package-lock.json | 5 + node_modules/vue-jsonp/LICENSE | 21 +++ node_modules/vue-jsonp/README.md | 155 +++++++++++++++++++ node_modules/vue-jsonp/dist/index.d.ts | 101 ++++++++++++ node_modules/vue-jsonp/dist/index.esm.js | 8 + node_modules/vue-jsonp/dist/index.js | 8 + node_modules/vue-jsonp/dist/utils/index.d.ts | 20 +++ node_modules/vue-jsonp/package.json | 50 ++++++ package-lock.json | 8 +- package.json | 3 +- 11 files changed, 379 insertions(+), 4 deletions(-) create mode 100644 node_modules/vue-jsonp/LICENSE create mode 100644 node_modules/vue-jsonp/README.md create mode 100644 node_modules/vue-jsonp/dist/index.d.ts create mode 100644 node_modules/vue-jsonp/dist/index.esm.js create mode 100644 node_modules/vue-jsonp/dist/index.js create mode 100644 node_modules/vue-jsonp/dist/utils/index.d.ts create mode 100644 node_modules/vue-jsonp/package.json diff --git a/main.js b/main.js index 39bc124..9cc7d24 100644 --- a/main.js +++ b/main.js @@ -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 diff --git a/node_modules/.package-lock.json b/node_modules/.package-lock.json index 91dbc65..6fe6eb8 100644 --- a/node_modules/.package-lock.json +++ b/node_modules/.package-lock.json @@ -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==" } } } diff --git a/node_modules/vue-jsonp/LICENSE b/node_modules/vue-jsonp/LICENSE new file mode 100644 index 0000000..9b2ef9e --- /dev/null +++ b/node_modules/vue-jsonp/LICENSE @@ -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. diff --git a/node_modules/vue-jsonp/README.md b/node_modules/vue-jsonp/README.md new file mode 100644 index 0000000..821a1fd --- /dev/null +++ b/node_modules/vue-jsonp/README.md @@ -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('/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` + + - `jsonp: (url: string, param?: IJsonpParam, timeout?: number) => Promise` + +## 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('/my-awesome-url') +assert(result === 'such a jsonp') +``` + +## License + +MIT diff --git a/node_modules/vue-jsonp/dist/index.d.ts b/node_modules/vue-jsonp/dist/index.d.ts new file mode 100644 index 0000000..9329ace --- /dev/null +++ b/node_modules/vue-jsonp/dist/index.d.ts @@ -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; +/** + * 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} + * + * @example + * const data = await jsonp('/url', { + * type: 'admin', + * date: '2020' + * }) + */ +declare function jsonp(url: string, param?: IJsonpParam, timeout?: number): Promise; +declare function jsonp(url: string, param?: IJsonpParam, config?: IConfig): Promise; +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; +} diff --git a/node_modules/vue-jsonp/dist/index.esm.js b/node_modules/vue-jsonp/dist/index.esm.js new file mode 100644 index 0000000..b20ed26 --- /dev/null +++ b/node_modules/vue-jsonp/dist/index.esm.js @@ -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}; diff --git a/node_modules/vue-jsonp/dist/index.js b/node_modules/vue-jsonp/dist/index.js new file mode 100644 index 0000000..339fe86 --- /dev/null +++ b/node_modules/vue-jsonp/dist/index.js @@ -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})})); diff --git a/node_modules/vue-jsonp/dist/utils/index.d.ts b/node_modules/vue-jsonp/dist/utils/index.d.ts new file mode 100644 index 0000000..8f155d8 --- /dev/null +++ b/node_modules/vue-jsonp/dist/utils/index.d.ts @@ -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 }; diff --git a/node_modules/vue-jsonp/package.json b/node_modules/vue-jsonp/package.json new file mode 100644 index 0000000..1bcd9ef --- /dev/null +++ b/node_modules/vue-jsonp/package.json @@ -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" + } +} diff --git a/package-lock.json b/package-lock.json index 188c776..9f8a1bb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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==" } } } diff --git a/package.json b/package.json index 3e4bbdf..d1915f9 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,6 @@ { "dependencies": { - "file-saver": "^2.0.5" + "file-saver": "^2.0.5", + "vue-jsonp": "^2.1.0" } }