feat: 新增支持小红书小程序
parent
71e3007389
commit
53f043275c
|
@ -11,6 +11,7 @@ docs/pages/guide/intro.md
|
||||||
|
|
||||||
# Bundle
|
# Bundle
|
||||||
dist/
|
dist/
|
||||||
|
.swc
|
||||||
|
|
||||||
# Typescript build file
|
# Typescript build file
|
||||||
*.tsbuildinfo
|
*.tsbuildinfo
|
||||||
|
|
|
@ -51,6 +51,7 @@ axios-miniprogram 是一款为小程序平台量身定制的轻量级请求库
|
||||||
- [飞书小程序](https://open.feishu.cn/document/uYjL24iN/uMjNzUjLzYzM14yM2MTN?from=axios-miniprogram)
|
- [飞书小程序](https://open.feishu.cn/document/uYjL24iN/uMjNzUjLzYzM14yM2MTN?from=axios-miniprogram)
|
||||||
- [快手小程序](https://mp.kuaishou.com/docs/introduction/quickStart.html?from=axios-miniprogram)
|
- [快手小程序](https://mp.kuaishou.com/docs/introduction/quickStart.html?from=axios-miniprogram)
|
||||||
- [360 小程序](https://mp.360.cn/doc/miniprogram/dev/#/f4b41f0cc5683bce78dfadfa7f3c73e7?from=axios-miniprogram)
|
- [360 小程序](https://mp.360.cn/doc/miniprogram/dev/#/f4b41f0cc5683bce78dfadfa7f3c73e7?from=axios-miniprogram)
|
||||||
|
- [小红书小程序](https://miniapp.xiaohongshu.com/docs/guide/miniIntroduce?from=axios-miniprogram)
|
||||||
|
|
||||||
## 关于在跨端框架中使用时的支持度
|
## 关于在跨端框架中使用时的支持度
|
||||||
|
|
||||||
|
|
|
@ -1,8 +0,0 @@
|
||||||
dist/
|
|
||||||
deploy_versions/
|
|
||||||
.temp/
|
|
||||||
.rn_temp/
|
|
||||||
node_modules/
|
|
||||||
.DS_Store
|
|
||||||
.swc
|
|
||||||
config/**.js
|
|
|
@ -19,7 +19,12 @@ const config = {
|
||||||
},
|
},
|
||||||
sourceRoot: 'src',
|
sourceRoot: 'src',
|
||||||
outputRoot: `dist/${process.env.TARO_ENV}`,
|
outputRoot: `dist/${process.env.TARO_ENV}`,
|
||||||
plugins: ['@tarojs/plugin-html', '@tarojs/plugin-platform-alipay-dd'],
|
plugins: [
|
||||||
|
'@tarojs/plugin-html',
|
||||||
|
'@tarojs/plugin-platform-alipay-dd',
|
||||||
|
'@tarojs/plugin-platform-lark',
|
||||||
|
'@tarojs/plugin-platform-kwai',
|
||||||
|
],
|
||||||
defineConstants: {},
|
defineConstants: {},
|
||||||
copy: {
|
copy: {
|
||||||
patterns: [],
|
patterns: [],
|
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"name": "example",
|
"name": "@examples/taro",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build:weapp": "taro build --type weapp",
|
"build:weapp": "taro build --type weapp",
|
||||||
|
@ -50,6 +50,8 @@
|
||||||
"@tarojs/cli": "3.6.6",
|
"@tarojs/cli": "3.6.6",
|
||||||
"@tarojs/plugin-html": "^3.6.6",
|
"@tarojs/plugin-html": "^3.6.6",
|
||||||
"@tarojs/plugin-platform-alipay-dd": "^0.3.0",
|
"@tarojs/plugin-platform-alipay-dd": "^0.3.0",
|
||||||
|
"@tarojs/plugin-platform-kwai": "^6.0.0",
|
||||||
|
"@tarojs/plugin-platform-lark": "^1.1.4",
|
||||||
"@tarojs/webpack5-runner": "3.6.6",
|
"@tarojs/webpack5-runner": "3.6.6",
|
||||||
"@types/webpack-env": "^1.13.6",
|
"@types/webpack-env": "^1.13.6",
|
||||||
"@vue/babel-plugin-jsx": "^1.0.6",
|
"@vue/babel-plugin-jsx": "^1.0.6",
|
|
@ -1,4 +1,5 @@
|
||||||
{
|
{
|
||||||
|
"miniprogramRoot": "./",
|
||||||
"projectname": "axios-miniprogram",
|
"projectname": "axios-miniprogram",
|
||||||
"setting": {
|
"setting": {
|
||||||
"urlCheck": false,
|
"urlCheck": false,
|
|
@ -0,0 +1,10 @@
|
||||||
|
{
|
||||||
|
"miniprogramRoot": "./",
|
||||||
|
"projectname": "axios-miniprogram",
|
||||||
|
"appid": "ks739467354825138594",
|
||||||
|
"libVersion": "0.2.0",
|
||||||
|
"setting": {
|
||||||
|
"urlCheck": false
|
||||||
|
},
|
||||||
|
"compileType": "miniprogram"
|
||||||
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
export default defineAppConfig({
|
export default defineAppConfig({
|
||||||
pages: ['pages/index/index'],
|
pages: ['home'],
|
||||||
window: {
|
window: {
|
||||||
backgroundTextStyle: 'light',
|
backgroundTextStyle: 'light',
|
||||||
navigationBarBackgroundColor: '#fff',
|
navigationBarBackgroundColor: '#fff',
|
|
@ -2,6 +2,7 @@
|
||||||
import Taro from '@tarojs/taro';
|
import Taro from '@tarojs/taro';
|
||||||
import { ref } from 'vue';
|
import { ref } from 'vue';
|
||||||
import axios from 'axios-miniprogram';
|
import axios from 'axios-miniprogram';
|
||||||
|
import consola from 'consola';
|
||||||
|
|
||||||
const config = ref<string>('');
|
const config = ref<string>('');
|
||||||
const response = ref<string>('');
|
const response = ref<string>('');
|
||||||
|
@ -14,18 +15,18 @@ axios.defaults.adapter = axios.createAdapter({
|
||||||
});
|
});
|
||||||
axios.defaults.baseURL = 'https://jsonplaceholder.typicode.com';
|
axios.defaults.baseURL = 'https://jsonplaceholder.typicode.com';
|
||||||
axios.defaults.errorHandler = (err) => {
|
axios.defaults.errorHandler = (err) => {
|
||||||
console.log('[debug]', (err as any).response);
|
consola.info('[debug]', (err as any).response);
|
||||||
error.value = `<pre>${JSON.stringify(err, null, 2)}</pre>`;
|
error.value = `<pre>${JSON.stringify(err, null, 2)}</pre>`;
|
||||||
Taro.hideLoading();
|
Taro.hideLoading();
|
||||||
Taro.showToast({
|
Taro.showToast({
|
||||||
icon: 'none',
|
icon: 'none',
|
||||||
title: (err as any).response.data?.errMsg ?? '未知错误',
|
title: (err as any).response.data?.errMsg || '未知错误',
|
||||||
});
|
});
|
||||||
return Promise.reject(err);
|
return Promise.reject(err);
|
||||||
};
|
};
|
||||||
|
|
||||||
axios.use(async (ctx, next) => {
|
axios.use(async (ctx, next) => {
|
||||||
console.log('[debug]', ctx);
|
consola.info('[debug]', ctx);
|
||||||
Taro.showLoading({
|
Taro.showLoading({
|
||||||
title: 'Loading...',
|
title: 'Loading...',
|
||||||
});
|
});
|
||||||
|
@ -115,8 +116,12 @@ function uploadRequest() {
|
||||||
{
|
{
|
||||||
name: 'filename',
|
name: 'filename',
|
||||||
filePath: tempFilePaths[0],
|
filePath: tempFilePaths[0],
|
||||||
|
fileType: 'image',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'multipart/form-data',
|
||||||
|
},
|
||||||
upload: true,
|
upload: true,
|
||||||
},
|
},
|
||||||
);
|
);
|
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"extends": ["../tsconfig.json"],
|
"extends": ["../../tsconfig.json"],
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"removeComments": false,
|
"removeComments": false,
|
||||||
"preserveConstEnums": true,
|
"preserveConstEnums": true,
|
|
@ -0,0 +1,20 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<script>
|
||||||
|
var coverSupport = 'CSS' in window && typeof CSS.supports === 'function' && (CSS.supports('top: env(a)') ||
|
||||||
|
CSS.supports('top: constant(a)'))
|
||||||
|
document.write(
|
||||||
|
'<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0' +
|
||||||
|
(coverSupport ? ', viewport-fit=cover' : '') + '" />')
|
||||||
|
</script>
|
||||||
|
<title></title>
|
||||||
|
<!--preload-links-->
|
||||||
|
<!--app-context-->
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="app"><!--app-html--></div>
|
||||||
|
<script type="module" src="/src/main.ts"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -0,0 +1,73 @@
|
||||||
|
{
|
||||||
|
"name": "@examples/uni-app",
|
||||||
|
"private": true,
|
||||||
|
"scripts": {
|
||||||
|
"dev:app": "uni -p app",
|
||||||
|
"dev:app-android": "uni -p app-android",
|
||||||
|
"dev:app-ios": "uni -p app-ios",
|
||||||
|
"dev:custom": "uni -p",
|
||||||
|
"dev:h5": "uni",
|
||||||
|
"dev:h5:ssr": "uni --ssr",
|
||||||
|
"dev:alipay": "uni -p mp-alipay",
|
||||||
|
"dev:swan": "uni -p mp-baidu",
|
||||||
|
"dev:jd": "uni -p mp-jd",
|
||||||
|
"dev:kwai": "uni -p mp-kuaishou",
|
||||||
|
"dev:lark": "uni -p mp-lark",
|
||||||
|
"dev:qq": "uni -p mp-qq",
|
||||||
|
"dev:tt": "uni -p mp-toutiao",
|
||||||
|
"dev:dd": "uni -p mp-alipay",
|
||||||
|
"dev:weapp": "uni -p mp-weixin",
|
||||||
|
"dev:xhs": "uni -p mp-xhs",
|
||||||
|
"dev:quickapp-webview": "uni -p quickapp-webview",
|
||||||
|
"dev:quickapp-webview-huawei": "uni -p quickapp-webview-huawei",
|
||||||
|
"dev:quickapp-webview-union": "uni -p quickapp-webview-union",
|
||||||
|
"build:app": "uni build -p app",
|
||||||
|
"build:app-android": "uni build -p app-android",
|
||||||
|
"build:app-ios": "uni build -p app-ios",
|
||||||
|
"build:custom": "uni build -p",
|
||||||
|
"build:h5": "uni build",
|
||||||
|
"build:h5:ssr": "uni build --ssr",
|
||||||
|
"build:alipay": "uni build -p mp-alipay",
|
||||||
|
"build:swan": "uni build -p mp-baidu",
|
||||||
|
"build:jd": "uni build -p mp-jd",
|
||||||
|
"build:kwai": "uni build -p mp-kuaishou",
|
||||||
|
"build:lark": "uni build -p mp-lark",
|
||||||
|
"build:qq": "uni build -p mp-qq",
|
||||||
|
"build:tt": "uni build -p mp-toutiao",
|
||||||
|
"build:dd": "uni -p mp-alipay",
|
||||||
|
"build:weapp": "uni build -p mp-weixin",
|
||||||
|
"build:xhs": "uni build -p mp-xhs",
|
||||||
|
"build:quickapp-webview": "uni build -p quickapp-webview",
|
||||||
|
"build:quickapp-webview-huawei": "uni build -p quickapp-webview-huawei",
|
||||||
|
"build:quickapp-webview-union": "uni build -p quickapp-webview-union",
|
||||||
|
"type-check": "vue-tsc --noEmit"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@dcloudio/uni-app": "3.0.0-3080720230703001",
|
||||||
|
"@dcloudio/uni-app-plus": "3.0.0-3080720230703001",
|
||||||
|
"@dcloudio/uni-components": "3.0.0-3080720230703001",
|
||||||
|
"@dcloudio/uni-h5": "3.0.0-3080720230703001",
|
||||||
|
"@dcloudio/uni-mp-alipay": "3.0.0-3080720230703001",
|
||||||
|
"@dcloudio/uni-mp-baidu": "3.0.0-3080720230703001",
|
||||||
|
"@dcloudio/uni-mp-jd": "3.0.0-3080720230703001",
|
||||||
|
"@dcloudio/uni-mp-kuaishou": "3.0.0-3080720230703001",
|
||||||
|
"@dcloudio/uni-mp-lark": "3.0.0-3080720230703001",
|
||||||
|
"@dcloudio/uni-mp-qq": "3.0.0-3080720230703001",
|
||||||
|
"@dcloudio/uni-mp-toutiao": "3.0.0-3080720230703001",
|
||||||
|
"@dcloudio/uni-mp-weixin": "3.0.0-3080720230703001",
|
||||||
|
"@dcloudio/uni-mp-xhs": "3.0.0-alpha-3081220230802001",
|
||||||
|
"@dcloudio/uni-quickapp-webview": "3.0.0-3080720230703001",
|
||||||
|
"axios-miniprogram": "workspace:*",
|
||||||
|
"vue": "^3.2.45"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@dcloudio/types": "^3.3.2",
|
||||||
|
"@dcloudio/uni-automator": "3.0.0-3080720230703001",
|
||||||
|
"@dcloudio/uni-cli-shared": "3.0.0-3080720230703001",
|
||||||
|
"@dcloudio/uni-stacktracey": "3.0.0-3080720230703001",
|
||||||
|
"@dcloudio/vite-plugin-uni": "3.0.0-3080720230703001",
|
||||||
|
"@vue/tsconfig": "^0.1.3",
|
||||||
|
"vite": "4.0.4",
|
||||||
|
"vue-tsc": "^1.0.24"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
/// <reference types="vite/client" />
|
||||||
|
|
||||||
|
declare module '*.vue' {
|
||||||
|
import { DefineComponent } from 'vue';
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types
|
||||||
|
const component: DefineComponent<{}, {}, any>;
|
||||||
|
export default component;
|
||||||
|
}
|
|
@ -0,0 +1,202 @@
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import { ref } from 'vue';
|
||||||
|
import axios from 'axios-miniprogram';
|
||||||
|
import consola from 'consola';
|
||||||
|
|
||||||
|
const config = ref<string>('');
|
||||||
|
const response = ref<string>('');
|
||||||
|
const error = ref<string>('');
|
||||||
|
|
||||||
|
axios.defaults.adapter = axios.createAdapter({
|
||||||
|
request: uni.request as any,
|
||||||
|
download: uni.downloadFile,
|
||||||
|
upload: uni.uploadFile as any,
|
||||||
|
});
|
||||||
|
axios.defaults.baseURL = 'https://jsonplaceholder.typicode.com';
|
||||||
|
axios.defaults.errorHandler = (err) => {
|
||||||
|
consola.info('[debug]', (err as any).response);
|
||||||
|
error.value = `<pre>${JSON.stringify(err, null, 2)}</pre>`;
|
||||||
|
uni.hideLoading();
|
||||||
|
uni.showToast({
|
||||||
|
icon: 'none',
|
||||||
|
title: (err as any).response.data?.errMsg || '未知错误',
|
||||||
|
});
|
||||||
|
return Promise.reject(err);
|
||||||
|
};
|
||||||
|
|
||||||
|
axios.use(async (ctx, next) => {
|
||||||
|
consola.info('[debug]', ctx);
|
||||||
|
uni.showLoading({
|
||||||
|
title: 'Loading...',
|
||||||
|
});
|
||||||
|
config.value = `<pre>${JSON.stringify(ctx.req, null, 2)}</pre>`;
|
||||||
|
error.value = '';
|
||||||
|
response.value = '';
|
||||||
|
await next();
|
||||||
|
response.value = `<pre>${JSON.stringify(ctx.res, null, 2)}</pre>`;
|
||||||
|
uni.hideLoading();
|
||||||
|
});
|
||||||
|
|
||||||
|
function getRequest() {
|
||||||
|
axios.get('/users/:id', {
|
||||||
|
id: 1,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function postRequest() {
|
||||||
|
axios.post('/users', {
|
||||||
|
name: 'Leanne Graham',
|
||||||
|
username: 'Bret',
|
||||||
|
email: 'Sincere@april.biz',
|
||||||
|
address: {
|
||||||
|
street: 'Kulas Light',
|
||||||
|
suite: 'Apt. 556',
|
||||||
|
city: 'Gwenborough',
|
||||||
|
zipcode: '92998-3874',
|
||||||
|
geo: { lat: '-37.3159', lng: '81.1496' },
|
||||||
|
},
|
||||||
|
phone: '1-770-736-8031 x56442',
|
||||||
|
website: 'hildegard.org',
|
||||||
|
company: {
|
||||||
|
name: 'Romaguera-Crona',
|
||||||
|
catchPhrase: 'Multi-layered client-server neural-net',
|
||||||
|
bs: 'harness real-time e-markets',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function putRequest() {
|
||||||
|
axios.put('/users/:id', {
|
||||||
|
id: 1,
|
||||||
|
name: 'Leanne Graham',
|
||||||
|
username: 'Bret',
|
||||||
|
email: 'Sincere@april.biz',
|
||||||
|
address: {
|
||||||
|
street: 'Kulas Light',
|
||||||
|
suite: 'Apt. 556',
|
||||||
|
city: 'Gwenborough',
|
||||||
|
zipcode: '92998-3874',
|
||||||
|
geo: { lat: '-37.3159', lng: '81.1496' },
|
||||||
|
},
|
||||||
|
phone: '1-770-736-8031 x56442',
|
||||||
|
website: 'hildegard.org',
|
||||||
|
company: {
|
||||||
|
name: 'Romaguera-Crona',
|
||||||
|
catchPhrase: 'Multi-layered client-server neural-net',
|
||||||
|
bs: 'harness real-time e-markets',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function deleteRequest() {
|
||||||
|
axios.delete('/users/:id', {
|
||||||
|
id: 1,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function downloadRequest() {
|
||||||
|
axios.get(
|
||||||
|
'/users/:id',
|
||||||
|
{
|
||||||
|
id: 1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
download: true,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function uploadRequest() {
|
||||||
|
uni.chooseImage({
|
||||||
|
count: 1,
|
||||||
|
success({ tempFilePaths }) {
|
||||||
|
axios.post(
|
||||||
|
'/users',
|
||||||
|
{
|
||||||
|
name: 'filename',
|
||||||
|
filePath: tempFilePaths[0],
|
||||||
|
fileType: 'image',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'multipart/form-data',
|
||||||
|
},
|
||||||
|
upload: true,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function errorRequest() {
|
||||||
|
axios.get('/users/:id', {
|
||||||
|
id: Infinity,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function failRequest() {
|
||||||
|
axios.post(
|
||||||
|
'/users',
|
||||||
|
{},
|
||||||
|
{
|
||||||
|
upload: true,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
defineExpose({
|
||||||
|
getRequest,
|
||||||
|
postRequest,
|
||||||
|
putRequest,
|
||||||
|
deleteRequest,
|
||||||
|
config,
|
||||||
|
response,
|
||||||
|
error,
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<view>
|
||||||
|
<button class="button" type="primary" @click="getRequest">GET 请求</button>
|
||||||
|
<button class="button" type="primary" @click="postRequest">
|
||||||
|
POST 请求
|
||||||
|
</button>
|
||||||
|
<button class="button" type="primary" @click="putRequest">PUT 请求</button>
|
||||||
|
<button class="button" type="primary" @click="deleteRequest">
|
||||||
|
DELETE 请求
|
||||||
|
</button>
|
||||||
|
<button class="button" type="primary" @click="downloadRequest">
|
||||||
|
DOWNLOAD 请求
|
||||||
|
</button>
|
||||||
|
<button class="button" type="primary" @click="uploadRequest">
|
||||||
|
UPLOAD 请求
|
||||||
|
</button>
|
||||||
|
<button class="button" type="primary" @click="errorRequest">
|
||||||
|
ERROR 请求
|
||||||
|
</button>
|
||||||
|
<button class="button" type="primary" @click="failRequest">
|
||||||
|
FAIL 请求
|
||||||
|
</button>
|
||||||
|
|
||||||
|
config:
|
||||||
|
<view class="code" v-html="config"></view>
|
||||||
|
|
||||||
|
response:
|
||||||
|
<view class="code" v-html="response"></view>
|
||||||
|
|
||||||
|
error:
|
||||||
|
<view class="code" v-html="error"></view>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.button {
|
||||||
|
margin: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.code {
|
||||||
|
padding: 20px;
|
||||||
|
overflow-x: scroll;
|
||||||
|
white-space: pre;
|
||||||
|
}
|
||||||
|
</style>
|
|
@ -0,0 +1,7 @@
|
||||||
|
import { createSSRApp } from 'vue';
|
||||||
|
export function createApp() {
|
||||||
|
const app = createSSRApp({});
|
||||||
|
return {
|
||||||
|
app,
|
||||||
|
};
|
||||||
|
}
|
|
@ -0,0 +1,72 @@
|
||||||
|
{
|
||||||
|
"name": "",
|
||||||
|
"appid": "",
|
||||||
|
"description": "",
|
||||||
|
"versionName": "1.0.0",
|
||||||
|
"versionCode": "100",
|
||||||
|
"transformPx": false,
|
||||||
|
/* 5+App特有相关 */
|
||||||
|
"app-plus": {
|
||||||
|
"usingComponents": true,
|
||||||
|
"nvueStyleCompiler": "uni-app",
|
||||||
|
"compilerVersion": 3,
|
||||||
|
"splashscreen": {
|
||||||
|
"alwaysShowBeforeRender": true,
|
||||||
|
"waiting": true,
|
||||||
|
"autoclose": true,
|
||||||
|
"delay": 0
|
||||||
|
},
|
||||||
|
/* 模块配置 */
|
||||||
|
"modules": {},
|
||||||
|
/* 应用发布信息 */
|
||||||
|
"distribute": {
|
||||||
|
/* android打包配置 */
|
||||||
|
"android": {
|
||||||
|
"permissions": [
|
||||||
|
"<uses-permission android:name=\"android.permission.CHANGE_NETWORK_STATE\"/>",
|
||||||
|
"<uses-permission android:name=\"android.permission.MOUNT_UNMOUNT_FILESYSTEMS\"/>",
|
||||||
|
"<uses-permission android:name=\"android.permission.VIBRATE\"/>",
|
||||||
|
"<uses-permission android:name=\"android.permission.READ_LOGS\"/>",
|
||||||
|
"<uses-permission android:name=\"android.permission.ACCESS_WIFI_STATE\"/>",
|
||||||
|
"<uses-feature android:name=\"android.hardware.camera.autofocus\"/>",
|
||||||
|
"<uses-permission android:name=\"android.permission.ACCESS_NETWORK_STATE\"/>",
|
||||||
|
"<uses-permission android:name=\"android.permission.CAMERA\"/>",
|
||||||
|
"<uses-permission android:name=\"android.permission.GET_ACCOUNTS\"/>",
|
||||||
|
"<uses-permission android:name=\"android.permission.READ_PHONE_STATE\"/>",
|
||||||
|
"<uses-permission android:name=\"android.permission.CHANGE_WIFI_STATE\"/>",
|
||||||
|
"<uses-permission android:name=\"android.permission.WAKE_LOCK\"/>",
|
||||||
|
"<uses-permission android:name=\"android.permission.FLASHLIGHT\"/>",
|
||||||
|
"<uses-feature android:name=\"android.hardware.camera\"/>",
|
||||||
|
"<uses-permission android:name=\"android.permission.WRITE_SETTINGS\"/>"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
/* ios打包配置 */
|
||||||
|
"ios": {},
|
||||||
|
/* SDK配置 */
|
||||||
|
"sdkConfigs": {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
/* 快应用特有相关 */
|
||||||
|
"quickapp": {},
|
||||||
|
/* 小程序特有相关 */
|
||||||
|
"mp-weixin": {
|
||||||
|
"appid": "",
|
||||||
|
"setting": {
|
||||||
|
"urlCheck": false
|
||||||
|
},
|
||||||
|
"usingComponents": true
|
||||||
|
},
|
||||||
|
"mp-alipay": {
|
||||||
|
"usingComponents": true
|
||||||
|
},
|
||||||
|
"mp-baidu": {
|
||||||
|
"usingComponents": true
|
||||||
|
},
|
||||||
|
"mp-toutiao": {
|
||||||
|
"usingComponents": true
|
||||||
|
},
|
||||||
|
"uniStatistics": {
|
||||||
|
"enable": false
|
||||||
|
},
|
||||||
|
"vueVersion": "3"
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
{
|
||||||
|
"pages": [{ "path": "home", "style": {} }],
|
||||||
|
"globalStyle": {
|
||||||
|
"backgroundTextStyle": "light",
|
||||||
|
"navigationBarBackgroundColor": "#fff",
|
||||||
|
"navigationBarTitleText": "axios-miniprogram",
|
||||||
|
"navigationBarTextStyle": "black"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
export {};
|
||||||
|
|
||||||
|
declare module 'vue' {
|
||||||
|
type Hooks = App.AppInstance & Page.PageInstance;
|
||||||
|
type ComponentCustomOptions = Hooks;
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
{
|
||||||
|
"extends": "@vue/tsconfig/tsconfig.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"lib": ["esnext", "dom"],
|
||||||
|
"types": ["@dcloudio/types"],
|
||||||
|
"ignoreDeprecations": "5.0"
|
||||||
|
},
|
||||||
|
"include": ["./src"]
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
import { defineConfig } from 'vite';
|
||||||
|
import uni from '@dcloudio/vite-plugin-uni';
|
||||||
|
|
||||||
|
// https://vitejs.dev/config/
|
||||||
|
export default defineConfig({
|
||||||
|
plugins: [uni()],
|
||||||
|
});
|
|
@ -7,3 +7,4 @@ declare const qh: any;
|
||||||
declare const ks: any;
|
declare const ks: any;
|
||||||
declare const dd: any;
|
declare const dd: any;
|
||||||
declare const jd: any;
|
declare const jd: any;
|
||||||
|
declare const xhs: any;
|
||||||
|
|
40
package.json
40
package.json
|
@ -51,37 +51,37 @@
|
||||||
"docs:deploy": "esno scripts/docs.deploy.ts"
|
"docs:deploy": "esno scripts/docs.deploy.ts"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@commitlint/cli": "^17.4.4",
|
"@commitlint/cli": "^17.7.1",
|
||||||
"@commitlint/config-conventional": "^17.4.4",
|
"@commitlint/config-conventional": "^17.7.0",
|
||||||
"@rollup/plugin-typescript": "^11.1.0",
|
"@rollup/plugin-typescript": "^11.1.2",
|
||||||
"@types/minimist": "^1.2.2",
|
"@types/minimist": "^1.2.2",
|
||||||
"@types/node": "^18.15.5",
|
"@types/node": "^18.17.5",
|
||||||
"@types/semver": "^7.3.13",
|
"@types/semver": "^7.5.0",
|
||||||
"@typescript-eslint/eslint-plugin": "^5.55.0",
|
"@typescript-eslint/eslint-plugin": "^5.62.0",
|
||||||
"@typescript-eslint/parser": "^5.55.0",
|
"@typescript-eslint/parser": "^5.62.0",
|
||||||
"@vitest/coverage-istanbul": "^0.30.0",
|
"@vitest/coverage-istanbul": "^0.30.1",
|
||||||
"chalk": "^5.2.0",
|
"chalk": "^5.3.0",
|
||||||
"consola": "^2.15.3",
|
"consola": "^2.15.3",
|
||||||
"conventional-changelog-cli": "^2.2.2",
|
"conventional-changelog-cli": "^2.2.2",
|
||||||
"cz-git": "1.3.8",
|
"cz-git": "1.3.8",
|
||||||
"czg": "1.3.8",
|
"czg": "1.3.8",
|
||||||
"enquirer": "^2.3.6",
|
"enquirer": "^2.4.1",
|
||||||
"eslint": "^8.36.0",
|
"eslint": "^8.47.0",
|
||||||
"esno": "^0.16.3",
|
"esno": "^0.16.3",
|
||||||
"fast-glob": "^3.2.12",
|
"fast-glob": "^3.3.1",
|
||||||
"jszip": "^3.10.1",
|
"jszip": "^3.10.1",
|
||||||
"lint-staged": "13.2.0",
|
"lint-staged": "13.2.0",
|
||||||
"minimist": "^1.2.8",
|
"minimist": "^1.2.8",
|
||||||
"prettier": "2.8.5",
|
"prettier": "2.8.5",
|
||||||
"rimraf": "^4.4.0",
|
"rimraf": "^4.4.1",
|
||||||
"rollup": "^3.20.0",
|
"rollup": "^3.28.0",
|
||||||
"rollup-plugin-dts": "^5.3.0",
|
"rollup-plugin-dts": "^5.3.1",
|
||||||
"rollup-plugin-esbuild": "^5.0.0",
|
"rollup-plugin-esbuild": "^5.0.0",
|
||||||
"semver": "^7.3.8",
|
"semver": "^7.5.4",
|
||||||
"simple-git-hooks": "^2.8.1",
|
"simple-git-hooks": "^2.9.0",
|
||||||
"tslib": "^2.5.0",
|
"tslib": "^2.6.1",
|
||||||
"typescript": "^5.0.2",
|
"typescript": "^5.1.6",
|
||||||
"vitest": "^0.30.0"
|
"vitest": "^0.30.1"
|
||||||
},
|
},
|
||||||
"simple-git-hooks": {
|
"simple-git-hooks": {
|
||||||
"pre-commit": "pnpm lint-staged && pnpm test && pnpm build -a",
|
"pre-commit": "pnpm lint-staged && pnpm test && pnpm build -a",
|
||||||
|
|
6474
pnpm-lock.yaml
6474
pnpm-lock.yaml
File diff suppressed because it is too large
Load Diff
|
@ -1,3 +1,3 @@
|
||||||
packages:
|
packages:
|
||||||
- docs
|
- docs
|
||||||
- example
|
- examples/*
|
||||||
|
|
|
@ -1,31 +1,37 @@
|
||||||
import enquirer from 'enquirer';
|
import enquirer from 'enquirer';
|
||||||
import consola from 'consola';
|
import consola from 'consola';
|
||||||
import { exec, resolve } from './utils';
|
import { exec, resolve, safeExit } from './utils';
|
||||||
import { safeExit } from './utils';
|
import { readdirSync } from 'fs';
|
||||||
|
|
||||||
const configPath = resolve('example/config');
|
|
||||||
const configTempPath = resolve('example/config/temp');
|
|
||||||
|
|
||||||
safeExit(main);
|
safeExit(main);
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
|
const { framework } = await enquirer.prompt<{ framework: string }>({
|
||||||
|
type: 'select',
|
||||||
|
name: 'framework',
|
||||||
|
message: '请选择多端框架',
|
||||||
|
choices: readdirSync(resolve('examples')),
|
||||||
|
});
|
||||||
|
|
||||||
|
const metas = framework === 'taro' ? taroMetas() : uniAppMetas();
|
||||||
const { platform } = await enquirer.prompt<{ platform: string }>({
|
const { platform } = await enquirer.prompt<{ platform: string }>({
|
||||||
type: 'select',
|
type: 'select',
|
||||||
name: 'platform',
|
name: 'platform',
|
||||||
message: '请选择启动平台',
|
message: '请选择启动平台',
|
||||||
choices: metas(),
|
choices: metas,
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log();
|
console.log();
|
||||||
consola.info(
|
consola.info(
|
||||||
`运行${metas().find((meta) => meta.name === platform)!.message}`,
|
`启动${metas.find((meta) => meta.name === platform)!.message}...`,
|
||||||
);
|
);
|
||||||
exec(`tsc ${configTempPath}/**.ts --outDir ${configPath}`);
|
|
||||||
exec(`pnpm --filter example dev:${platform}`);
|
exec(`pnpm --filter @examples/${framework} dev:${platform}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
function metas() {
|
function taroMetas() {
|
||||||
return [
|
return [
|
||||||
|
{ name: 'h5', message: 'H5' },
|
||||||
{ name: 'weapp', message: '微信小程序' },
|
{ name: 'weapp', message: '微信小程序' },
|
||||||
{ name: 'swan', message: '百度小程序' },
|
{ name: 'swan', message: '百度小程序' },
|
||||||
{ name: 'alipay', message: '支付宝小程序' },
|
{ name: 'alipay', message: '支付宝小程序' },
|
||||||
|
@ -35,6 +41,9 @@ function metas() {
|
||||||
{ name: 'dd', message: '钉钉小程序' },
|
{ name: 'dd', message: '钉钉小程序' },
|
||||||
{ name: 'lark', message: '飞书小程序' },
|
{ name: 'lark', message: '飞书小程序' },
|
||||||
{ name: 'kwai', message: '快手小程序' },
|
{ name: 'kwai', message: '快手小程序' },
|
||||||
{ name: 'h5', message: 'H5' },
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function uniAppMetas() {
|
||||||
|
return [...taroMetas(), { name: 'xhs', message: '小红书小程序' }];
|
||||||
|
}
|
||||||
|
|
|
@ -111,11 +111,11 @@ export interface AxiosAdapterRequestConfig extends AnyObject {
|
||||||
/**
|
/**
|
||||||
* 返回的数据格式
|
* 返回的数据格式
|
||||||
*/
|
*/
|
||||||
dataType?: 'json' | '其他';
|
dataType?: string;
|
||||||
/**
|
/**
|
||||||
* 响应的数据类型
|
* 响应的数据类型
|
||||||
*/
|
*/
|
||||||
responseType?: 'text' | 'arraybuffer';
|
responseType?: string;
|
||||||
/**
|
/**
|
||||||
* 超时时间,单位为毫秒。默认值为 60000
|
* 超时时间,单位为毫秒。默认值为 60000
|
||||||
*/
|
*/
|
||||||
|
@ -338,22 +338,6 @@ export function createAdapter(platform: AxiosAdapterPlatform) {
|
||||||
return request(baseOptions);
|
return request(baseOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
function processUpload(
|
|
||||||
upload: AxiosAdapterUpload,
|
|
||||||
baseOptions: AxiosAdapterBaseOptions,
|
|
||||||
): AxiosAdapterPlatformTask {
|
|
||||||
const options = baseOptions as AxiosAdapterUploadOptions;
|
|
||||||
const { name, filePath, fileType, ...formData } = options.data as AnyObject;
|
|
||||||
options.name = name;
|
|
||||||
options.fileName = name;
|
|
||||||
options.filePath = filePath;
|
|
||||||
options.fileType = fileType;
|
|
||||||
options.formData = formData;
|
|
||||||
|
|
||||||
orgIgnore(options, ['params', 'data']);
|
|
||||||
return upload(options);
|
|
||||||
}
|
|
||||||
|
|
||||||
function processDownload(
|
function processDownload(
|
||||||
download: AxiosAdapterDownload,
|
download: AxiosAdapterDownload,
|
||||||
baseOptions: AxiosAdapterBaseOptions,
|
baseOptions: AxiosAdapterBaseOptions,
|
||||||
|
@ -363,14 +347,17 @@ export function createAdapter(platform: AxiosAdapterPlatform) {
|
||||||
options.filePath = params?.filePath;
|
options.filePath = params?.filePath;
|
||||||
options.success = (_response) => {
|
options.success = (_response) => {
|
||||||
const response = Object.assign(
|
const response = Object.assign(
|
||||||
ignore(_response, 'tempFilePath', 'apFilePath', 'filePath'),
|
ignore(_response, 'tempFilePath', 'apFilePath', 'filePath', 'fileSize'),
|
||||||
{
|
{
|
||||||
data: {
|
data: {
|
||||||
filePath: _response.filePath,
|
filePath: _response.filePath,
|
||||||
tempFilePath:
|
tempFilePath:
|
||||||
_response.tempFilePath ??
|
_response.tempFilePath ??
|
||||||
// response.apFilePath 为支付宝小程序基础库小于 2.7.23 的特有属性。
|
// 支付宝
|
||||||
_response.apFilePath,
|
_response.apFilePath,
|
||||||
|
fileSize:
|
||||||
|
// 飞书
|
||||||
|
_response.fileSize,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
@ -382,5 +369,24 @@ export function createAdapter(platform: AxiosAdapterPlatform) {
|
||||||
return download(options);
|
return download(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function processUpload(
|
||||||
|
upload: AxiosAdapterUpload,
|
||||||
|
baseOptions: AxiosAdapterBaseOptions,
|
||||||
|
): AxiosAdapterPlatformTask {
|
||||||
|
const options = baseOptions as AxiosAdapterUploadOptions;
|
||||||
|
const { name, filePath, fileType, ...formData } = options.data as AnyObject;
|
||||||
|
options.name = name;
|
||||||
|
options.filePath = filePath;
|
||||||
|
options.formData = formData;
|
||||||
|
|
||||||
|
// 支付宝 | 钉钉
|
||||||
|
options.fileName = name;
|
||||||
|
// 支付宝 | 钉钉
|
||||||
|
options.fileType = fileType;
|
||||||
|
|
||||||
|
orgIgnore(options, ['params', 'data']);
|
||||||
|
return upload(options);
|
||||||
|
}
|
||||||
|
|
||||||
return adapter;
|
return adapter;
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,25 +14,46 @@ export function getDefaultAdapter() {
|
||||||
function getPlatform() {
|
function getPlatform() {
|
||||||
const undef = 'undefined';
|
const undef = 'undefined';
|
||||||
|
|
||||||
|
// 微信小程序
|
||||||
if (typeof wx !== undef) {
|
if (typeof wx !== undef) {
|
||||||
return wx;
|
return wx;
|
||||||
} else if (typeof my !== undef) {
|
}
|
||||||
|
// 支付宝小程序
|
||||||
|
else if (typeof my !== undef) {
|
||||||
return my;
|
return my;
|
||||||
} else if (typeof swan !== undef) {
|
}
|
||||||
|
// 百度小程序
|
||||||
|
else if (typeof swan !== undef) {
|
||||||
return swan;
|
return swan;
|
||||||
} else if (typeof tt !== undef) {
|
}
|
||||||
|
// 抖音小程序 | 飞书小程序
|
||||||
|
else if (typeof tt !== undef) {
|
||||||
return tt;
|
return tt;
|
||||||
} else if (typeof qq !== undef) {
|
}
|
||||||
|
// QQ 小程序
|
||||||
|
else if (typeof qq !== undef) {
|
||||||
return qq;
|
return qq;
|
||||||
} else if (typeof qh !== undef) {
|
}
|
||||||
|
// 360 小程序
|
||||||
|
else if (typeof qh !== undef) {
|
||||||
return qh;
|
return qh;
|
||||||
} else if (typeof ks !== undef) {
|
}
|
||||||
|
// 快手小程序
|
||||||
|
else if (typeof ks !== undef) {
|
||||||
return ks;
|
return ks;
|
||||||
} else if (typeof dd !== undef) {
|
}
|
||||||
|
// 钉钉小程序
|
||||||
|
else if (typeof dd !== undef) {
|
||||||
return dd;
|
return dd;
|
||||||
} else if (typeof jd !== undef) {
|
}
|
||||||
|
// 京东小程序
|
||||||
|
else if (typeof jd !== undef) {
|
||||||
return jd;
|
return jd;
|
||||||
}
|
}
|
||||||
|
// 小红书小程序
|
||||||
|
else if (typeof xhs !== undef) {
|
||||||
|
return xhs;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function revisePlatformApiNames(platform?: AnyObject) {
|
function revisePlatformApiNames(platform?: AnyObject) {
|
||||||
|
|
|
@ -200,6 +200,7 @@ describe('src/adapter/createAdapter.ts', () => {
|
||||||
expect(response.data).toMatchInlineSnapshot(`
|
expect(response.data).toMatchInlineSnapshot(`
|
||||||
{
|
{
|
||||||
"filePath": undefined,
|
"filePath": undefined,
|
||||||
|
"fileSize": undefined,
|
||||||
"tempFilePath": "/path/temp/file",
|
"tempFilePath": "/path/temp/file",
|
||||||
}
|
}
|
||||||
`);
|
`);
|
||||||
|
@ -212,6 +213,7 @@ describe('src/adapter/createAdapter.ts', () => {
|
||||||
expect(response.data).toMatchInlineSnapshot(`
|
expect(response.data).toMatchInlineSnapshot(`
|
||||||
{
|
{
|
||||||
"filePath": undefined,
|
"filePath": undefined,
|
||||||
|
"fileSize": undefined,
|
||||||
"tempFilePath": "/path/temp/file",
|
"tempFilePath": "/path/temp/file",
|
||||||
}
|
}
|
||||||
`);
|
`);
|
||||||
|
@ -226,6 +228,7 @@ describe('src/adapter/createAdapter.ts', () => {
|
||||||
expect(response.data).toMatchInlineSnapshot(`
|
expect(response.data).toMatchInlineSnapshot(`
|
||||||
{
|
{
|
||||||
"filePath": "/user/path",
|
"filePath": "/user/path",
|
||||||
|
"fileSize": undefined,
|
||||||
"tempFilePath": "/path/temp/file",
|
"tempFilePath": "/path/temp/file",
|
||||||
}
|
}
|
||||||
`);
|
`);
|
||||||
|
@ -240,6 +243,7 @@ describe('src/adapter/createAdapter.ts', () => {
|
||||||
expect(response.data).toMatchInlineSnapshot(`
|
expect(response.data).toMatchInlineSnapshot(`
|
||||||
{
|
{
|
||||||
"filePath": "/user/path",
|
"filePath": "/user/path",
|
||||||
|
"fileSize": undefined,
|
||||||
"tempFilePath": "/path/temp/file",
|
"tempFilePath": "/path/temp/file",
|
||||||
}
|
}
|
||||||
`);
|
`);
|
||||||
|
|
|
@ -138,7 +138,7 @@ describe('src/core/mergeConfig.ts', () => {
|
||||||
errorHandler: vi.fn(),
|
errorHandler: vi.fn(),
|
||||||
cancelToken: CancelToken.source().token,
|
cancelToken: CancelToken.source().token,
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
responseType: 'json',
|
responseType: 'text',
|
||||||
timeout: 1000,
|
timeout: 1000,
|
||||||
validateStatus: vi.fn(),
|
validateStatus: vi.fn(),
|
||||||
onUploadProgress: vi.fn(),
|
onUploadProgress: vi.fn(),
|
||||||
|
@ -154,7 +154,7 @@ describe('src/core/mergeConfig.ts', () => {
|
||||||
errorHandler: vi.fn(),
|
errorHandler: vi.fn(),
|
||||||
cancelToken: CancelToken.source().token,
|
cancelToken: CancelToken.source().token,
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
responseType: 'json',
|
responseType: 'text',
|
||||||
timeout: 1000,
|
timeout: 1000,
|
||||||
validateStatus: vi.fn(),
|
validateStatus: vi.fn(),
|
||||||
onUploadProgress: vi.fn(),
|
onUploadProgress: vi.fn(),
|
||||||
|
|
Loading…
Reference in New Issue