From d5a9acf4d67523f12822bc6b73306b6c4d71dc4f Mon Sep 17 00:00:00 2001 From: wzp <2880584989@qq.com> Date: 星期五, 11 二月 2022 10:10:57 +0800 Subject: [PATCH] 上传 --- assetMgtH5/js_sdk/luch-request/luch-request/core/dispatchRequest.js | 6 assetMgtH5/js_sdk/luch-request/luch-request/core/InterceptorManager.js | 51 ++ assetMgtH5/pages/assets/list.vue | 21 + assetMgtH5/main.js | 4 assetMgtH5/js_sdk/luch-request/luch-request/core/Request.js | 200 +++++++++ assetMgtH5/js_sdk/luch-request/luch-request/adapters/index.js | 99 ++++ assetMgtH5/api/requestConfig.js | 68 +++ assetMgtH5/js_sdk/luch-request/package.json | 13 assetMgtH5/js_sdk/luch-request/luch-request/core/defaults.js | 30 + assetMgtH5/js_sdk/luch-request/luch-request/core/settle.js | 16 assetMgtH5/js_sdk/luch-request/luch-request/helpers/combineURLs.js | 14 assetMgtH5/js_sdk/luch-request/luch-request/helpers/isAbsoluteURL.js | 14 assetMgtH5/js_sdk/luch-request/luch-request/utils/clone.js | 264 ++++++++++++ assetMgtH5/js_sdk/luch-request/luch-request/helpers/buildURL.js | 69 +++ assetMgtH5/js_sdk/luch-request/luch-request/core/buildFullPath.js | 20 assetMgtH5/js_sdk/luch-request/luch-request/utils.js | 135 ++++++ assetMgtH5/js_sdk/luch-request/luch-request/index.js | 2 assetMgtH5/js_sdk/luch-request/luch-request/core/mergeConfig.js | 103 ++++ assetMgtH5/js_sdk/luch-request/luch-request/index.d.ts | 116 +++++ 19 files changed, 1,245 insertions(+), 0 deletions(-) diff --git a/assetMgtH5/api/requestConfig.js b/assetMgtH5/api/requestConfig.js new file mode 100644 index 0000000..1f62206 --- /dev/null +++ b/assetMgtH5/api/requestConfig.js @@ -0,0 +1,68 @@ +/** + * @version 3.0.5 + * @Author lu-ch + * @Email webwork.s@qq.com + * 鏂囨。: https://www.quanzhan.co/luch-request/ + * github: https://github.com/lei-mu/luch-request + * DCloud: http://ext.dcloud.net.cn/plugin?id=392 + * HBuilderX: beat-3.0.4 alpha-3.0.4 + */ + + +import Request from '@/js_sdk/luch-request/luch-request/index.js' +export const apiBaseUrl = 'http://asset.mengdong.icu' + +const http = new Request() + +const getTokenStorage = () => { + let Authorization = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2NDQ0ODk3NzQsInVzZXJuYW1lIjoiMTM2MTE0NTIxNzUifQ.XSraTbueplGDOyxI8aFy5e0abUrWPhAaMkODfdEAu-Q' + // try { + // Authorization = uni.getStorageSync('token') + // } catch (e) { + // } + return Authorization +} + + +http.setConfig((config) => { /* 璁剧疆鍏ㄥ眬閰嶇疆 */ + config.baseURL = apiBaseUrl /* 鏍瑰煙鍚嶄笉鍚� */ + config.header = { + ...config.header, + // a: 1, // 婕旂ず + // b: 2 // 婕旂ず + } + return config +}) + + +http.interceptors.request.use((config) => { /* 璇锋眰涔嬪墠鎷︽埅鍣ㄣ�傚彲浠ヤ娇鐢╝sync await 鍋氬紓姝ユ搷浣� */ + config.header = { + ...config.header, + Authorization: getTokenStorage() + } + /* + if (!token) { // 濡傛灉token涓嶅瓨鍦紝return Promise.reject(config) 浼氬彇娑堟湰娆¤姹� + return Promise.reject(config) + } + */ + return config +}, (config) => { + return Promise.reject(config) +}) + + +http.interceptors.response.use(async (response) => { /* 璇锋眰涔嬪悗鎷︽埅鍣ㄣ�傚彲浠ヤ娇鐢╝sync await 鍋氬紓姝ユ搷浣� */ + // if (response.data.code !== 200) { // 鏈嶅姟绔繑鍥炵殑鐘舵�佺爜涓嶇瓑浜�200锛屽垯reject() + // return Promise.reject(response) + // } + return response +}, (response) => { // 璇锋眰閿欒鍋氱偣浠�涔堛�傚彲浠ヤ娇鐢╝sync await 鍋氬紓姝ユ搷浣� + console.log(response.data) + return Promise.reject(response) +}) + +export { + http +} + + diff --git a/assetMgtH5/js_sdk/luch-request/luch-request/adapters/index.js b/assetMgtH5/js_sdk/luch-request/luch-request/adapters/index.js new file mode 100644 index 0000000..5a478b5 --- /dev/null +++ b/assetMgtH5/js_sdk/luch-request/luch-request/adapters/index.js @@ -0,0 +1,99 @@ +import buildURL from '../helpers/buildURL' +import buildFullPath from '../core/buildFullPath' +import settle from '../core/settle' +import { isUndefined } from "../utils" + +/** + * 杩斿洖鍙�夊�煎瓨鍦ㄧ殑閰嶇疆 + * @param {Array} keys - 鍙�夊�兼暟缁� + * @param {Object} config2 - 閰嶇疆 + * @return {{}} - 瀛樺湪鐨勯厤缃」 + */ +const mergeKeys = (keys, config2) => { + let config = {} + keys.forEach(prop => { + if (!isUndefined(config2[prop])) { + config[prop] = config2[prop] + } + }) + return config +} +export default (config) => { + return new Promise((resolve, reject) => { + let fullPath = buildURL(buildFullPath(config.baseURL, config.url), config.params) + const _config = { + url: fullPath, + header: config.header, + complete: (response) => { + config.fullPath = fullPath + response.config = config + try { + // 瀵瑰彲鑳藉瓧绗︿覆涓嶆槸json 鐨勬儏鍐靛閿� + if (typeof response.data === 'string') { + response.data = JSON.parse(response.data) + } + // eslint-disable-next-line no-empty + } catch (e) { + } + settle(resolve, reject, response) + } + } + let requestTask + if (config.method === 'UPLOAD') { + delete _config.header['content-type'] + delete _config.header['Content-Type'] + let otherConfig = { + // #ifdef MP-ALIPAY + fileType: config.fileType, + // #endif + filePath: config.filePath, + name: config.name + } + const optionalKeys = [ + // #ifdef APP-PLUS || H5 + 'files', + // #endif + // #ifdef H5 + 'file', + // #endif + // #ifdef H5 || APP-PLUS + 'timeout', + // #endif + 'formData' + ] + requestTask = uni.uploadFile({..._config, ...otherConfig, ...mergeKeys(optionalKeys, config)}) + } else if (config.method === 'DOWNLOAD') { + // #ifdef H5 || APP-PLUS + if (!isUndefined(config['timeout'])) { + _config['timeout'] = config['timeout'] + } + // #endif + requestTask = uni.downloadFile(_config) + } else { + const optionalKeys = [ + 'data', + 'method', + // #ifdef H5 || APP-PLUS || MP-ALIPAY || MP-WEIXIN + 'timeout', + // #endif + 'dataType', + // #ifndef MP-ALIPAY + 'responseType', + // #endif + // #ifdef APP-PLUS + 'sslVerify', + // #endif + // #ifdef H5 + 'withCredentials', + // #endif + // #ifdef APP-PLUS + 'firstIpv4', + // #endif + ] + requestTask = uni.request({..._config,...mergeKeys(optionalKeys, config)}) + } + if (config.getTask) { + config.getTask(requestTask, config) + } + }) +} diff --git a/assetMgtH5/js_sdk/luch-request/luch-request/core/InterceptorManager.js b/assetMgtH5/js_sdk/luch-request/luch-request/core/InterceptorManager.js new file mode 100644 index 0000000..3ea0d5e --- /dev/null +++ b/assetMgtH5/js_sdk/luch-request/luch-request/core/InterceptorManager.js @@ -0,0 +1,51 @@ +'use strict' + + +function InterceptorManager() { + this.handlers = [] +} + +/** + * Add a new interceptor to the stack + * + * @param {Function} fulfilled The function to handle `then` for a `Promise` + * @param {Function} rejected The function to handle `reject` for a `Promise` + * + * @return {Number} An ID used to remove interceptor later + */ +InterceptorManager.prototype.use = function use(fulfilled, rejected) { + this.handlers.push({ + fulfilled: fulfilled, + rejected: rejected + }) + return this.handlers.length - 1 +} + +/** + * Remove an interceptor from the stack + * + * @param {Number} id The ID that was returned by `use` + */ +InterceptorManager.prototype.eject = function eject(id) { + if (this.handlers[id]) { + this.handlers[id] = null + } +} + +/** + * Iterate over all the registered interceptors + * + * This method is particularly useful for skipping over any + * interceptors that may have become `null` calling `eject`. + * + * @param {Function} fn The function to call for each interceptor + */ +InterceptorManager.prototype.forEach = function forEach(fn) { + this.handlers.forEach(h => { + if (h !== null) { + fn(h) + } + }) +} + +export default InterceptorManager diff --git a/assetMgtH5/js_sdk/luch-request/luch-request/core/Request.js b/assetMgtH5/js_sdk/luch-request/luch-request/core/Request.js new file mode 100644 index 0000000..43bb14c --- /dev/null +++ b/assetMgtH5/js_sdk/luch-request/luch-request/core/Request.js @@ -0,0 +1,200 @@ +/** + * @Class Request + * @description luch-request http璇锋眰鎻掍欢 + * @version 3.0.7 + * @Author lu-ch + * @Date 2021-09-04 + * @Email webwork.s@qq.com + * 鏂囨。: https://www.quanzhan.co/luch-request/ + * github: https://github.com/lei-mu/luch-request + * DCloud: http://ext.dcloud.net.cn/plugin?id=392 + * HBuilderX: beat-3.0.4 alpha-3.0.4 + */ + + +import dispatchRequest from './dispatchRequest' +import InterceptorManager from './InterceptorManager' +import mergeConfig from './mergeConfig' +import defaults from './defaults' +import { isPlainObject } from '../utils' +import clone from '../utils/clone' + +export default class Request { + /** + * @param {Object} arg - 鍏ㄥ眬閰嶇疆 + * @param {String} arg.baseURL - 鍏ㄥ眬鏍硅矾寰� + * @param {Object} arg.header - 鍏ㄥ眬header + * @param {String} arg.method = [GET|POST|PUT|DELETE|CONNECT|HEAD|OPTIONS|TRACE] - 鍏ㄥ眬榛樿璇锋眰鏂瑰紡 + * @param {String} arg.dataType = [json] - 鍏ㄥ眬榛樿鐨刣ataType + * @param {String} arg.responseType = [text|arraybuffer] - 鍏ㄥ眬榛樿鐨剅esponseType銆傛敮浠樺疂灏忕▼搴忎笉鏀寔 + * @param {Object} arg.custom - 鍏ㄥ眬榛樿鐨勮嚜瀹氫箟鍙傛暟 + * @param {Number} arg.timeout - 鍏ㄥ眬榛樿鐨勮秴鏃舵椂闂达紝鍗曚綅 ms銆傞粯璁�60000銆侶5(HBuilderX 2.9.9+)銆丄PP(HBuilderX 2.9.9+)銆佸井淇″皬绋嬪簭锛�2.10.0锛夈�佹敮浠樺疂灏忕▼搴� + * @param {Boolean} arg.sslVerify - 鍏ㄥ眬榛樿鐨勬槸鍚﹂獙璇� ssl 璇佷功銆傞粯璁rue.浠匒pp瀹夊崜绔敮鎸侊紙HBuilderX 2.3.3+锛� + * @param {Boolean} arg.withCredentials - 鍏ㄥ眬榛樿鐨勮法鍩熻姹傛椂鏄惁鎼哄甫鍑瘉锛坈ookies锛夈�傞粯璁alse銆備粎H5鏀寔锛圚BuilderX 2.6.15+锛� + * @param {Boolean} arg.firstIpv4 - 鍏―NS瑙f瀽鏃朵紭鍏堜娇鐢╥pv4銆傞粯璁alse銆備粎 App-Android 鏀寔 (HBuilderX 2.8.0+) + * @param {Function(statusCode):Boolean} arg.validateStatus - 鍏ㄥ眬榛樿鐨勮嚜瀹氫箟楠岃瘉鍣ㄣ�傞粯璁tatusCode >= 200 && statusCode < 300 + */ + constructor(arg = {}) { + if (!isPlainObject(arg)) { + arg = {} + console.warn('璁剧疆鍏ㄥ眬鍙傛暟蹇呴』鎺ユ敹涓�涓狾bject') + } + this.config = clone({...defaults, ...arg}) + this.interceptors = { + request: new InterceptorManager(), + response: new InterceptorManager() + } + } + + /** + * @Function + * @param {Request~setConfigCallback} f - 璁剧疆鍏ㄥ眬榛樿閰嶇疆 + */ + setConfig(f) { + this.config = f(this.config) + } + + middleware(config) { + config = mergeConfig(this.config, config) + let chain = [dispatchRequest, undefined] + let promise = Promise.resolve(config) + + this.interceptors.request.forEach(function unshiftRequestInterceptors(interceptor) { + chain.unshift(interceptor.fulfilled, interceptor.rejected) + }) + + this.interceptors.response.forEach(function pushResponseInterceptors(interceptor) { + chain.push(interceptor.fulfilled, interceptor.rejected) + }) + + while (chain.length) { + promise = promise.then(chain.shift(), chain.shift()) + } + + return promise + } + + /** + * @Function + * @param {Object} config - 璇锋眰閰嶇疆椤� + * @prop {String} options.url - 璇锋眰璺緞 + * @prop {Object} options.data - 璇锋眰鍙傛暟 + * @prop {Object} [options.responseType = config.responseType] [text|arraybuffer] - 鍝嶅簲鐨勬暟鎹被鍨� + * @prop {Object} [options.dataType = config.dataType] - 濡傛灉璁句负 json锛屼細灏濊瘯瀵硅繑鍥炵殑鏁版嵁鍋氫竴娆� JSON.parse + * @prop {Object} [options.header = config.header] - 璇锋眰header + * @prop {Object} [options.method = config.method] - 璇锋眰鏂规硶 + * @returns {Promise<unknown>} + */ + request(config = {}) { + return this.middleware(config) + } + + get(url, options = {}) { + return this.middleware({ + url, + method: 'GET', + ...options + }) + } + + post(url, data, options = {}) { + return this.middleware({ + url, + data, + method: 'POST', + ...options + }) + } + + // #ifndef MP-ALIPAY + put(url, data, options = {}) { + return this.middleware({ + url, + data, + method: 'PUT', + ...options + }) + } + + // #endif + + // #ifdef APP-PLUS || H5 || MP-WEIXIN || MP-BAIDU + delete(url, data, options = {}) { + return this.middleware({ + url, + data, + method: 'DELETE', + ...options + }) + } + + // #endif + + // #ifdef H5 || MP-WEIXIN + connect(url, data, options = {}) { + return this.middleware({ + url, + data, + method: 'CONNECT', + ...options + }) + } + + // #endif + + // #ifdef H5 || MP-WEIXIN || MP-BAIDU + head(url, data, options = {}) { + return this.middleware({ + url, + data, + method: 'HEAD', + ...options + }) + } + + // #endif + + // #ifdef APP-PLUS || H5 || MP-WEIXIN || MP-BAIDU + options(url, data, options = {}) { + return this.middleware({ + url, + data, + method: 'OPTIONS', + ...options + }) + } + + // #endif + + // #ifdef H5 || MP-WEIXIN + trace(url, data, options = {}) { + return this.middleware({ + url, + data, + method: 'TRACE', + ...options + }) + } + + // #endif + + upload(url, config = {}) { + config.url = url + config.method = 'UPLOAD' + return this.middleware(config) + } + + download(url, config = {}) { + config.url = url + config.method = 'DOWNLOAD' + return this.middleware(config) + } +} + + +/** + * setConfig鍥炶皟 + * @return {Object} - 杩斿洖鎿嶄綔鍚庣殑config + * @callback Request~setConfigCallback + * @param {Object} config - 鍏ㄥ眬榛樿config + */ diff --git a/assetMgtH5/js_sdk/luch-request/luch-request/core/buildFullPath.js b/assetMgtH5/js_sdk/luch-request/luch-request/core/buildFullPath.js new file mode 100644 index 0000000..f2852f4 --- /dev/null +++ b/assetMgtH5/js_sdk/luch-request/luch-request/core/buildFullPath.js @@ -0,0 +1,20 @@ +'use strict' + +import isAbsoluteURL from '../helpers/isAbsoluteURL' +import combineURLs from '../helpers/combineURLs' + +/** + * Creates a new URL by combining the baseURL with the requestedURL, + * only when the requestedURL is not already an absolute URL. + * If the requestURL is absolute, this function returns the requestedURL untouched. + * + * @param {string} baseURL The base URL + * @param {string} requestedURL Absolute or relative URL to combine + * @returns {string} The combined full path + */ +export default function buildFullPath(baseURL, requestedURL) { + if (baseURL && !isAbsoluteURL(requestedURL)) { + return combineURLs(baseURL, requestedURL) + } + return requestedURL +} diff --git a/assetMgtH5/js_sdk/luch-request/luch-request/core/defaults.js b/assetMgtH5/js_sdk/luch-request/luch-request/core/defaults.js new file mode 100644 index 0000000..38afc3a --- /dev/null +++ b/assetMgtH5/js_sdk/luch-request/luch-request/core/defaults.js @@ -0,0 +1,30 @@ +/** + * 榛樿鐨勫叏灞�閰嶇疆 + */ + + +export default { + baseURL: '', + header: {}, + method: 'GET', + dataType: 'json', + // #ifndef MP-ALIPAY + responseType: 'text', + // #endif + custom: {}, + // #ifdef H5 || APP-PLUS || MP-ALIPAY || MP-WEIXIN + timeout: 60000, + // #endif + // #ifdef APP-PLUS + sslVerify: true, + // #endif + // #ifdef H5 + withCredentials: false, + // #endif + // #ifdef APP-PLUS + firstIpv4: false, + // #endif + validateStatus: function validateStatus(status) { + return status >= 200 && status < 300 + } +} diff --git a/assetMgtH5/js_sdk/luch-request/luch-request/core/dispatchRequest.js b/assetMgtH5/js_sdk/luch-request/luch-request/core/dispatchRequest.js new file mode 100644 index 0000000..c5f2c85 --- /dev/null +++ b/assetMgtH5/js_sdk/luch-request/luch-request/core/dispatchRequest.js @@ -0,0 +1,6 @@ +import adapter from '../adapters/index' + + +export default (config) => { + return adapter(config) +} diff --git a/assetMgtH5/js_sdk/luch-request/luch-request/core/mergeConfig.js b/assetMgtH5/js_sdk/luch-request/luch-request/core/mergeConfig.js new file mode 100644 index 0000000..a3ccbf7 --- /dev/null +++ b/assetMgtH5/js_sdk/luch-request/luch-request/core/mergeConfig.js @@ -0,0 +1,103 @@ +import {deepMerge, isUndefined} from '../utils' + +/** + * 鍚堝苟灞�閮ㄩ厤缃紭鍏堢殑閰嶇疆锛屽鏋滃眬閮ㄦ湁璇ラ厤缃」鍒欑敤灞�閮紝濡傛灉鍏ㄥ眬鏈夎閰嶇疆椤瑰垯鐢ㄥ叏灞� + * @param {Array} keys - 閰嶇疆椤� + * @param {Object} globalsConfig - 褰撳墠鐨勫叏灞�閰嶇疆 + * @param {Object} config2 - 灞�閮ㄩ厤缃� + * @return {{}} + */ +const mergeKeys = (keys, globalsConfig, config2) => { + let config = {} + keys.forEach(prop => { + if (!isUndefined(config2[prop])) { + config[prop] = config2[prop] + } else if (!isUndefined(globalsConfig[prop])) { + config[prop] = globalsConfig[prop] + } + }) + return config +} +/** + * + * @param globalsConfig - 褰撳墠瀹炰緥鐨勫叏灞�閰嶇疆 + * @param config2 - 褰撳墠鐨勫眬閮ㄩ厤缃� + * @return - 鍚堝苟鍚庣殑閰嶇疆 + */ +export default (globalsConfig, config2 = {}) => { + const method = config2.method || globalsConfig.method || 'GET' + let config = { + baseURL: globalsConfig.baseURL || '', + method: method, + url: config2.url || '', + params: config2.params || {}, + custom: {...(globalsConfig.custom || {}), ...(config2.custom || {})}, + header: deepMerge(globalsConfig.header || {}, config2.header || {}) + } + const defaultToConfig2Keys = ['getTask', 'validateStatus'] + config = {...config, ...mergeKeys(defaultToConfig2Keys, globalsConfig, config2)} + + // eslint-disable-next-line no-empty + if (method === 'DOWNLOAD') { + // #ifdef H5 || APP-PLUS + if (!isUndefined(config2.timeout)) { + config['timeout'] = config2['timeout'] + } else if (!isUndefined(globalsConfig.timeout)) { + config['timeout'] = globalsConfig['timeout'] + } + // #endif + } else if (method === 'UPLOAD') { + delete config.header['content-type'] + delete config.header['Content-Type'] + const uploadKeys = [ + // #ifdef APP-PLUS || H5 + 'files', + // #endif + // #ifdef MP-ALIPAY + 'fileType', + // #endif + // #ifdef H5 + 'file', + // #endif + 'filePath', + 'name', + // #ifdef H5 || APP-PLUS + 'timeout', + // #endif + 'formData', + ] + uploadKeys.forEach(prop => { + if (!isUndefined(config2[prop])) { + config[prop] = config2[prop] + } + }) + // #ifdef H5 || APP-PLUS + if (isUndefined(config.timeout) && !isUndefined(globalsConfig.timeout)) { + config['timeout'] = globalsConfig['timeout'] + } + // #endif + } else { + const defaultsKeys = [ + 'data', + // #ifdef H5 || APP-PLUS || MP-ALIPAY || MP-WEIXIN + 'timeout', + // #endif + 'dataType', + // #ifndef MP-ALIPAY + 'responseType', + // #endif + // #ifdef APP-PLUS + 'sslVerify', + // #endif + // #ifdef H5 + 'withCredentials', + // #endif + // #ifdef APP-PLUS + 'firstIpv4', + // #endif + ] + config = {...config, ...mergeKeys(defaultsKeys, globalsConfig, config2)} + } + + return config +} diff --git a/assetMgtH5/js_sdk/luch-request/luch-request/core/settle.js b/assetMgtH5/js_sdk/luch-request/luch-request/core/settle.js new file mode 100644 index 0000000..b2f1659 --- /dev/null +++ b/assetMgtH5/js_sdk/luch-request/luch-request/core/settle.js @@ -0,0 +1,16 @@ +/** + * Resolve or reject a Promise based on response status. + * + * @param {Function} resolve A function that resolves the promise. + * @param {Function} reject A function that rejects the promise. + * @param {object} response The response. + */ +export default function settle(resolve, reject, response) { + const validateStatus = response.config.validateStatus + const status = response.statusCode + if (status && (!validateStatus || validateStatus(status))) { + resolve(response) + } else { + reject(response) + } +} diff --git a/assetMgtH5/js_sdk/luch-request/luch-request/helpers/buildURL.js b/assetMgtH5/js_sdk/luch-request/luch-request/helpers/buildURL.js new file mode 100644 index 0000000..d26dc30 --- /dev/null +++ b/assetMgtH5/js_sdk/luch-request/luch-request/helpers/buildURL.js @@ -0,0 +1,69 @@ +'use strict' + +import * as utils from './../utils' + +function encode(val) { + return encodeURIComponent(val). + replace(/%40/gi, '@'). + replace(/%3A/gi, ':'). + replace(/%24/g, '$'). + replace(/%2C/gi, ','). + replace(/%20/g, '+'). + replace(/%5B/gi, '['). + replace(/%5D/gi, ']') +} + +/** + * Build a URL by appending params to the end + * + * @param {string} url The base of the url (e.g., http://www.google.com) + * @param {object} [params] The params to be appended + * @returns {string} The formatted url + */ +export default function buildURL(url, params) { + /*eslint no-param-reassign:0*/ + if (!params) { + return url + } + + var serializedParams + if (utils.isURLSearchParams(params)) { + serializedParams = params.toString() + } else { + var parts = [] + + utils.forEach(params, function serialize(val, key) { + if (val === null || typeof val === 'undefined') { + return + } + + if (utils.isArray(val)) { + key = key + '[]' + } else { + val = [val] + } + + utils.forEach(val, function parseValue(v) { + if (utils.isDate(v)) { + v = v.toISOString() + } else if (utils.isObject(v)) { + v = JSON.stringify(v) + } + parts.push(encode(key) + '=' + encode(v)) + }) + }) + + serializedParams = parts.join('&') + } + + if (serializedParams) { + var hashmarkIndex = url.indexOf('#') + if (hashmarkIndex !== -1) { + url = url.slice(0, hashmarkIndex) + } + + url += (url.indexOf('?') === -1 ? '?' : '&') + serializedParams + } + + return url +} diff --git a/assetMgtH5/js_sdk/luch-request/luch-request/helpers/combineURLs.js b/assetMgtH5/js_sdk/luch-request/luch-request/helpers/combineURLs.js new file mode 100644 index 0000000..7b9d1ef --- /dev/null +++ b/assetMgtH5/js_sdk/luch-request/luch-request/helpers/combineURLs.js @@ -0,0 +1,14 @@ +'use strict' + +/** + * Creates a new URL by combining the specified URLs + * + * @param {string} baseURL The base URL + * @param {string} relativeURL The relative URL + * @returns {string} The combined URL + */ +export default function combineURLs(baseURL, relativeURL) { + return relativeURL + ? baseURL.replace(/\/+$/, '') + '/' + relativeURL.replace(/^\/+/, '') + : baseURL +} diff --git a/assetMgtH5/js_sdk/luch-request/luch-request/helpers/isAbsoluteURL.js b/assetMgtH5/js_sdk/luch-request/luch-request/helpers/isAbsoluteURL.js new file mode 100644 index 0000000..2a82517 --- /dev/null +++ b/assetMgtH5/js_sdk/luch-request/luch-request/helpers/isAbsoluteURL.js @@ -0,0 +1,14 @@ +'use strict' + +/** + * Determines whether the specified URL is absolute + * + * @param {string} url The URL to test + * @returns {boolean} True if the specified URL is absolute, otherwise false + */ +export default function isAbsoluteURL(url) { + // A URL is considered absolute if it begins with "<scheme>://" or "//" (protocol-relative URL). + // RFC 3986 defines scheme name as a sequence of characters beginning with a letter and followed + // by any combination of letters, digits, plus, period, or hyphen. + return /^([a-z][a-z\d+\-.]*:)?\/\//i.test(url) +} diff --git a/assetMgtH5/js_sdk/luch-request/luch-request/index.d.ts b/assetMgtH5/js_sdk/luch-request/luch-request/index.d.ts new file mode 100644 index 0000000..e939ce1 --- /dev/null +++ b/assetMgtH5/js_sdk/luch-request/luch-request/index.d.ts @@ -0,0 +1,116 @@ +type AnyObject = Record<string | number | symbol, any> +type HttpPromise<T> = Promise<HttpResponse<T>>; +type Tasks = UniApp.RequestTask | UniApp.UploadTask | UniApp.DownloadTask +export interface RequestTask { + abort: () => void; + offHeadersReceived: () => void; + onHeadersReceived: () => void; +} +export interface HttpRequestConfig<T = Tasks> { + /** 璇锋眰鍩哄湴鍧� */ + baseURL?: string; + /** 璇锋眰鏈嶅姟鍣ㄦ帴鍙e湴鍧� */ + url?: string; + + /** 璇锋眰鏌ヨ鍙傛暟锛岃嚜鍔ㄦ嫾鎺ヤ负鏌ヨ瀛楃涓� */ + params?: AnyObject; + /** 璇锋眰浣撳弬鏁� */ + data?: AnyObject; + + /** 鏂囦欢瀵瑰簲鐨� key */ + name?: string; + /** HTTP 璇锋眰涓叾浠栭澶栫殑 form data */ + formData?: AnyObject; + /** 瑕佷笂浼犳枃浠惰祫婧愮殑璺緞銆� */ + filePath?: string; + /** 闇�瑕佷笂浼犵殑鏂囦欢鍒楄〃銆備娇鐢� files 鏃讹紝filePath 鍜� name 涓嶇敓鏁堬紝App銆丠5锛� 2.6.15+锛� */ + files?: Array<{ + name?: string; + file?: File; + uri: string; + }>; + /** 瑕佷笂浼犵殑鏂囦欢瀵硅薄锛屼粎H5锛�2.6.15+锛夋敮鎸� */ + file?: File; + + /** 璇锋眰澶翠俊鎭� */ + header?: AnyObject; + /** 璇锋眰鏂瑰紡 */ + method?: "GET" | "POST" | "PUT" | "DELETE" | "CONNECT" | "HEAD" | "OPTIONS" | "TRACE" | "UPLOAD" | "DOWNLOAD"; + /** 濡傛灉璁句负 json锛屼細灏濊瘯瀵硅繑鍥炵殑鏁版嵁鍋氫竴娆� JSON.parse */ + dataType?: string; + /** 璁剧疆鍝嶅簲鐨勬暟鎹被鍨嬶紝鏀粯瀹濆皬绋嬪簭涓嶆敮鎸� */ + responseType?: "text" | "arraybuffer"; + /** 鑷畾涔夊弬鏁� */ + custom?: AnyObject; + /** 瓒呮椂鏃堕棿锛屼粎寰俊灏忕▼搴忥紙2.10.0锛夈�佹敮浠樺疂灏忕▼搴忔敮鎸� */ + timeout?: number; + /** DNS瑙f瀽鏃朵紭鍏堜娇鐢╥pv4锛屼粎 App-Android 鏀寔 (HBuilderX 2.8.0+) */ + firstIpv4?: boolean; + /** 楠岃瘉 ssl 璇佷功 浠�5+App瀹夊崜绔敮鎸侊紙HBuilderX 2.3.3+锛� */ + sslVerify?: boolean; + /** 璺ㄥ煙璇锋眰鏃舵槸鍚︽惡甯﹀嚟璇侊紙cookies锛変粎H5鏀寔锛圚BuilderX 2.6.15+锛� */ + withCredentials?: boolean; + + /** 杩斿洖褰撳墠璇锋眰鐨則ask, options銆傝鍕垮湪姝ゅ淇敼options銆� */ + getTask?: (task: T, options: HttpRequestConfig<T>) => void; + /** 鍏ㄥ眬鑷畾涔夐獙璇佸櫒 */ + validateStatus?: (statusCode: number) => boolean | void; +} +export interface HttpResponse<T = any> { + config: HttpRequestConfig; + statusCode: number; + cookies: Array<string>; + data: T; + errMsg: string; + header: AnyObject; +} +export interface HttpUploadResponse<T = any> { + config: HttpRequestConfig; + statusCode: number; + data: T; + errMsg: string; +} +export interface HttpDownloadResponse extends HttpResponse { + tempFilePath: string; +} +export interface HttpError { + config: HttpRequestConfig; + statusCode?: number; + cookies?: Array<string>; + data?: any; + errMsg: string; + header?: AnyObject; +} +export interface HttpInterceptorManager<V, E = V> { + use( + onFulfilled?: (config: V) => Promise<V> | V, + onRejected?: (config: E) => Promise<E> | E + ): void; + eject(id: number): void; +} +export abstract class HttpRequestAbstract { + constructor(config?: HttpRequestConfig); + config: HttpRequestConfig; + interceptors: { + request: HttpInterceptorManager<HttpRequestConfig, HttpRequestConfig>; + response: HttpInterceptorManager<HttpResponse, HttpError>; + } + middleware<T = any>(config: HttpRequestConfig): HttpPromise<T>; + request<T = any>(config: HttpRequestConfig<UniApp.RequestTask>): HttpPromise<T>; + get<T = any>(url: string, config?: HttpRequestConfig<UniApp.RequestTask>): HttpPromise<T>; + upload<T = any>(url: string, config?: HttpRequestConfig<UniApp.UploadTask>): HttpPromise<T>; + delete<T = any>(url: string, data?: AnyObject, config?: HttpRequestConfig<UniApp.RequestTask>): HttpPromise<T>; + head<T = any>(url: string, data?: AnyObject, config?: HttpRequestConfig<UniApp.RequestTask>): HttpPromise<T>; + post<T = any>(url: string, data?: AnyObject, config?: HttpRequestConfig<UniApp.RequestTask>): HttpPromise<T>; + put<T = any>(url: string, data?: AnyObject, config?: HttpRequestConfig<UniApp.RequestTask>): HttpPromise<T>; + connect<T = any>(url: string, data?: AnyObject, config?: HttpRequestConfig<UniApp.RequestTask>): HttpPromise<T>; + options<T = any>(url: string, data?: AnyObject, config?: HttpRequestConfig<UniApp.RequestTask>): HttpPromise<T>; + trace<T = any>(url: string, data?: AnyObject, config?: HttpRequestConfig<UniApp.RequestTask>): HttpPromise<T>; + + download(url: string, config?: HttpRequestConfig<UniApp.DownloadTask>): Promise<HttpDownloadResponse>; + + setConfig(onSend: (config: HttpRequestConfig) => HttpRequestConfig): void; +} + +declare class HttpRequest extends HttpRequestAbstract { } +export default HttpRequest; diff --git a/assetMgtH5/js_sdk/luch-request/luch-request/index.js b/assetMgtH5/js_sdk/luch-request/luch-request/index.js new file mode 100644 index 0000000..d8fe348 --- /dev/null +++ b/assetMgtH5/js_sdk/luch-request/luch-request/index.js @@ -0,0 +1,2 @@ +import Request from './core/Request' +export default Request diff --git a/assetMgtH5/js_sdk/luch-request/luch-request/utils.js b/assetMgtH5/js_sdk/luch-request/luch-request/utils.js new file mode 100644 index 0000000..0b5bf21 --- /dev/null +++ b/assetMgtH5/js_sdk/luch-request/luch-request/utils.js @@ -0,0 +1,135 @@ +'use strict' + +// utils is a library of generic helper functions non-specific to axios + +var toString = Object.prototype.toString + +/** + * Determine if a value is an Array + * + * @param {Object} val The value to test + * @returns {boolean} True if value is an Array, otherwise false + */ +export function isArray (val) { + return toString.call(val) === '[object Array]' +} + + +/** + * Determine if a value is an Object + * + * @param {Object} val The value to test + * @returns {boolean} True if value is an Object, otherwise false + */ +export function isObject (val) { + return val !== null && typeof val === 'object' +} + +/** + * Determine if a value is a Date + * + * @param {Object} val The value to test + * @returns {boolean} True if value is a Date, otherwise false + */ +export function isDate (val) { + return toString.call(val) === '[object Date]' +} + +/** + * Determine if a value is a URLSearchParams object + * + * @param {Object} val The value to test + * @returns {boolean} True if value is a URLSearchParams object, otherwise false + */ +export function isURLSearchParams (val) { + return typeof URLSearchParams !== 'undefined' && val instanceof URLSearchParams +} + + +/** + * Iterate over an Array or an Object invoking a function for each item. + * + * If `obj` is an Array callback will be called passing + * the value, index, and complete array for each item. + * + * If 'obj' is an Object callback will be called passing + * the value, key, and complete object for each property. + * + * @param {Object|Array} obj The object to iterate + * @param {Function} fn The callback to invoke for each item + */ +export function forEach (obj, fn) { + // Don't bother if no value provided + if (obj === null || typeof obj === 'undefined') { + return + } + + // Force an array if not already something iterable + if (typeof obj !== 'object') { + /*eslint no-param-reassign:0*/ + obj = [obj] + } + + if (isArray(obj)) { + // Iterate over array values + for (var i = 0, l = obj.length; i < l; i++) { + fn.call(null, obj[i], i, obj) + } + } else { + // Iterate over object keys + for (var key in obj) { + if (Object.prototype.hasOwnProperty.call(obj, key)) { + fn.call(null, obj[key], key, obj) + } + } + } +} + +/** + * 鏄惁涓篵oolean 鍊� + * @param val + * @returns {boolean} + */ +export function isBoolean(val) { + return typeof val === 'boolean' +} + +/** + * 鏄惁涓虹湡姝g殑瀵硅薄{} new Object + * @param {any} obj - 妫�娴嬬殑瀵硅薄 + * @returns {boolean} + */ +export function isPlainObject(obj) { + return Object.prototype.toString.call(obj) === '[object Object]' +} + + + +/** + * Function equal to merge with the difference being that no reference + * to original objects is kept. + * + * @see merge + * @param {Object} obj1 Object to merge + * @returns {Object} Result of all merge properties + */ +export function deepMerge(/* obj1, obj2, obj3, ... */) { + let result = {} + function assignValue(val, key) { + if (typeof result[key] === 'object' && typeof val === 'object') { + result[key] = deepMerge(result[key], val) + } else if (typeof val === 'object') { + result[key] = deepMerge({}, val) + } else { + result[key] = val + } + } + for (let i = 0, l = arguments.length; i < l; i++) { + forEach(arguments[i], assignValue) + } + return result +} + +export function isUndefined (val) { + return typeof val === 'undefined' +} diff --git a/assetMgtH5/js_sdk/luch-request/luch-request/utils/clone.js b/assetMgtH5/js_sdk/luch-request/luch-request/utils/clone.js new file mode 100644 index 0000000..2fee704 --- /dev/null +++ b/assetMgtH5/js_sdk/luch-request/luch-request/utils/clone.js @@ -0,0 +1,264 @@ +/* eslint-disable */ +var clone = (function() { + 'use strict'; + + function _instanceof(obj, type) { + return type != null && obj instanceof type; + } + + var nativeMap; + try { + nativeMap = Map; + } catch(_) { + // maybe a reference error because no `Map`. Give it a dummy value that no + // value will ever be an instanceof. + nativeMap = function() {}; + } + + var nativeSet; + try { + nativeSet = Set; + } catch(_) { + nativeSet = function() {}; + } + + var nativePromise; + try { + nativePromise = Promise; + } catch(_) { + nativePromise = function() {}; + } + + /** + * Clones (copies) an Object using deep copying. + * + * This function supports circular references by default, but if you are certain + * there are no circular references in your object, you can save some CPU time + * by calling clone(obj, false). + * + * Caution: if `circular` is false and `parent` contains circular references, + * your program may enter an infinite loop and crash. + * + * @param `parent` - the object to be cloned + * @param `circular` - set to true if the object to be cloned may contain + * circular references. (optional - true by default) + * @param `depth` - set to a number if the object is only to be cloned to + * a particular depth. (optional - defaults to Infinity) + * @param `prototype` - sets the prototype to be used when cloning an object. + * (optional - defaults to parent prototype). + * @param `includeNonEnumerable` - set to true if the non-enumerable properties + * should be cloned as well. Non-enumerable properties on the prototype + * chain will be ignored. (optional - false by default) + */ + function clone(parent, circular, depth, prototype, includeNonEnumerable) { + if (typeof circular === 'object') { + depth = circular.depth; + prototype = circular.prototype; + includeNonEnumerable = circular.includeNonEnumerable; + circular = circular.circular; + } + // maintain two arrays for circular references, where corresponding parents + // and children have the same index + var allParents = []; + var allChildren = []; + + var useBuffer = typeof Buffer != 'undefined'; + + if (typeof circular == 'undefined') + circular = true; + + if (typeof depth == 'undefined') + depth = Infinity; + + // recurse this function so we don't reset allParents and allChildren + function _clone(parent, depth) { + // cloning null always returns null + if (parent === null) + return null; + + if (depth === 0) + return parent; + + var child; + var proto; + if (typeof parent != 'object') { + return parent; + } + + if (_instanceof(parent, nativeMap)) { + child = new nativeMap(); + } else if (_instanceof(parent, nativeSet)) { + child = new nativeSet(); + } else if (_instanceof(parent, nativePromise)) { + child = new nativePromise(function (resolve, reject) { + parent.then(function(value) { + resolve(_clone(value, depth - 1)); + }, function(err) { + reject(_clone(err, depth - 1)); + }); + }); + } else if (clone.__isArray(parent)) { + child = []; + } else if (clone.__isRegExp(parent)) { + child = new RegExp(parent.source, __getRegExpFlags(parent)); + if (parent.lastIndex) child.lastIndex = parent.lastIndex; + } else if (clone.__isDate(parent)) { + child = new Date(parent.getTime()); + } else if (useBuffer && Buffer.isBuffer(parent)) { + if (Buffer.from) { + // Node.js >= 5.10.0 + child = Buffer.from(parent); + } else { + // Older Node.js versions + child = new Buffer(parent.length); + parent.copy(child); + } + return child; + } else if (_instanceof(parent, Error)) { + child = Object.create(parent); + } else { + if (typeof prototype == 'undefined') { + proto = Object.getPrototypeOf(parent); + child = Object.create(proto); + } + else { + child = Object.create(prototype); + proto = prototype; + } + } + + if (circular) { + var index = allParents.indexOf(parent); + + if (index != -1) { + return allChildren[index]; + } + allParents.push(parent); + allChildren.push(child); + } + + if (_instanceof(parent, nativeMap)) { + parent.forEach(function(value, key) { + var keyChild = _clone(key, depth - 1); + var valueChild = _clone(value, depth - 1); + child.set(keyChild, valueChild); + }); + } + if (_instanceof(parent, nativeSet)) { + parent.forEach(function(value) { + var entryChild = _clone(value, depth - 1); + child.add(entryChild); + }); + } + + for (var i in parent) { + var attrs = Object.getOwnPropertyDescriptor(parent, i); + if (attrs) { + child[i] = _clone(parent[i], depth - 1); + } + + try { + var objProperty = Object.getOwnPropertyDescriptor(parent, i); + if (objProperty.set === 'undefined') { + // no setter defined. Skip cloning this property + continue; + } + child[i] = _clone(parent[i], depth - 1); + } catch(e){ + if (e instanceof TypeError) { + // when in strict mode, TypeError will be thrown if child[i] property only has a getter + // we can't do anything about this, other than inform the user that this property cannot be set. + continue + } else if (e instanceof ReferenceError) { + //this may happen in non strict mode + continue + } + } + + } + + if (Object.getOwnPropertySymbols) { + var symbols = Object.getOwnPropertySymbols(parent); + for (var i = 0; i < symbols.length; i++) { + // Don't need to worry about cloning a symbol because it is a primitive, + // like a number or string. + var symbol = symbols[i]; + var descriptor = Object.getOwnPropertyDescriptor(parent, symbol); + if (descriptor && !descriptor.enumerable && !includeNonEnumerable) { + continue; + } + child[symbol] = _clone(parent[symbol], depth - 1); + Object.defineProperty(child, symbol, descriptor); + } + } + + if (includeNonEnumerable) { + var allPropertyNames = Object.getOwnPropertyNames(parent); + for (var i = 0; i < allPropertyNames.length; i++) { + var propertyName = allPropertyNames[i]; + var descriptor = Object.getOwnPropertyDescriptor(parent, propertyName); + if (descriptor && descriptor.enumerable) { + continue; + } + child[propertyName] = _clone(parent[propertyName], depth - 1); + Object.defineProperty(child, propertyName, descriptor); + } + } + + return child; + } + + return _clone(parent, depth); + } + + /** + * Simple flat clone using prototype, accepts only objects, usefull for property + * override on FLAT configuration object (no nested props). + * + * USE WITH CAUTION! This may not behave as you wish if you do not know how this + * works. + */ + clone.clonePrototype = function clonePrototype(parent) { + if (parent === null) + return null; + + var c = function () {}; + c.prototype = parent; + return new c(); + }; + +// private utility functions + + function __objToStr(o) { + return Object.prototype.toString.call(o); + } + clone.__objToStr = __objToStr; + + function __isDate(o) { + return typeof o === 'object' && __objToStr(o) === '[object Date]'; + } + clone.__isDate = __isDate; + + function __isArray(o) { + return typeof o === 'object' && __objToStr(o) === '[object Array]'; + } + clone.__isArray = __isArray; + + function __isRegExp(o) { + return typeof o === 'object' && __objToStr(o) === '[object RegExp]'; + } + clone.__isRegExp = __isRegExp; + + function __getRegExpFlags(re) { + var flags = ''; + if (re.global) flags += 'g'; + if (re.ignoreCase) flags += 'i'; + if (re.multiline) flags += 'm'; + return flags; + } + clone.__getRegExpFlags = __getRegExpFlags; + + return clone; +})(); + +export default clone diff --git a/assetMgtH5/js_sdk/luch-request/package.json b/assetMgtH5/js_sdk/luch-request/package.json new file mode 100644 index 0000000..fa0f6f0 --- /dev/null +++ b/assetMgtH5/js_sdk/luch-request/package.json @@ -0,0 +1,13 @@ +{ + "id": "luch-request", + "name": "luch-request", + "version": "3.0.7", + "description": "鍩轰簬Promise寮�鍙戠殑璺ㄥ钩鍙般�侀」鐩骇鍒殑璇锋眰搴擄紝瀹冩湁鏇村皬鐨勪綋绉紝鏄撶敤鐨刟pi锛屾柟渚跨畝鍗曠殑鑷畾涔夎兘鍔�", + "keywords": [ + "request", + "axios", + "缃戠粶璇锋眰", + "鎷︽埅鍣�", + "promise" + ] +} \ No newline at end of file diff --git a/assetMgtH5/main.js b/assetMgtH5/main.js index af36c0f..4dec65e 100644 --- a/assetMgtH5/main.js +++ b/assetMgtH5/main.js @@ -12,9 +12,13 @@ import uView from '@/uni_modules/uview-ui' Vue.use(uView) +//鑷畾涔夊鑸爮 import cuCustom from './colorui/components/cu-custom.vue' Vue.component('cu-custom',cuCustom) +import { http } from '@/api/requestConfig.js' // 鍏ㄥ眬鎸傝浇寮曞叆锛岄厤缃浉鍏冲湪璇ndex.js鏂囦欢閲屼慨鏀� +Vue.prototype.$http = http + // #ifdef VUE3 import { createSSRApp } from 'vue' export function createApp() { diff --git a/assetMgtH5/pages/assets/list.vue b/assetMgtH5/pages/assets/list.vue index 27a6c2b..d16e7ea 100644 --- a/assetMgtH5/pages/assets/list.vue +++ b/assetMgtH5/pages/assets/list.vue @@ -66,6 +66,9 @@ ] } }, + onShow() { + this.getAssetList(); + }, methods: { changeHandler(e) { const { @@ -94,6 +97,24 @@ showPicker() { this.show = true; }, + + //璇锋眰 + getAssetList() { + this.$http.get('/assets/approval/search',{params:{pageNum:"1",pageSize:"10",keyStr:''}}) + + .then(res => { + debugger; + let data = res.data; + console.log(JSON.stringify(data.data)) + let tt = data.data; + console.log(tt.length) + + }).catch(err => { + console.log(err.data) + }) + } + + } } </script> -- Gitblit v1.9.1