From d1448cb0ef10f358bb7bddb4e1ec268515e0b787 Mon Sep 17 00:00:00 2001 From: gaoluyang <2820782392@qq.com> Date: 星期二, 15 七月 2025 11:46:57 +0800 Subject: [PATCH] 项目初始化 --- config/request.js | 62 +++++++++++++++++++++++++++++++ 1 files changed, 62 insertions(+), 0 deletions(-) diff --git a/config/request.js b/config/request.js new file mode 100644 index 0000000..828ce00 --- /dev/null +++ b/config/request.js @@ -0,0 +1,62 @@ +const http = uni.$u.http; + +/** + * 娣峰叆榛樿涓�у寲閰嶇疆 + * @param {*} config + * @returns + */ +function mixinCustom (config) { + config.custom = Object.assign({ + auth: true, + toast: true, + catch: true, + loading: true + }, config.custom || {}); + return config; +} + +/** + * 鏍煎紡鍖杇et璇锋眰url鍙傛暟锛屽皢瀵硅薄瑙f瀽涓哄瓧绗︿覆 + * @param {*} url + * @param {*} params + * @returns + */ +function urlFormater (url, params) { + if (params) { + let paramList = []; + for (let key in params) { + paramList.push(key + '=' + params[key]) + } + return url.indexOf('?') > -1 ? (url + '&' + paramList.join('&')) : (url + '?' + paramList.join('&')) + } + return url; +} + +const request = { + // post鎻愪氦 + post (url, params, config = {}) { + config = mixinCustom(config) + return http.post(url, params, config); + }, + // get鎻愪氦 + get (url, params, config = {}) { + config = mixinCustom(config) + let path = urlFormater(url, params) + return http.get(path, config); + }, + + // put鎻愪氦 + put (url, params, config = {}) { + config = mixinCustom(config) + return http.put(url, params, config); + }, + + // delete鎻愪氦 + delete (url, params, config = {}) { + config = mixinCustom(config) + return http.delete(url, params, config); + }, + +}; + +export default request; \ No newline at end of file -- Gitblit v1.9.3