提交 5dbb3f21 编写于 作者: fxy060608's avatar fxy060608

fix: add passive

上级 64c168c4
...@@ -3,7 +3,7 @@ export const API_CONNECT_SOCKET = 'connectSocket' ...@@ -3,7 +3,7 @@ export const API_CONNECT_SOCKET = 'connectSocket'
export type API_TYPE_CONNECT_SOCKET = typeof uni.connectSocket export type API_TYPE_CONNECT_SOCKET = typeof uni.connectSocket
export const ConnectSocketOptions: ApiOptions<API_TYPE_CONNECT_SOCKET> = { export const ConnectSocketOptions: ApiOptions<API_TYPE_CONNECT_SOCKET> = {
formatArgs: { formatArgs: {
header(value, params) { header(value: Record<string, any>, params: Record<string, any>) {
params.header = value || {} params.header = value || {}
}, },
method(value, params) { method(value, params) {
......
...@@ -40,7 +40,7 @@ export function useHover(props: UseHoverOptions) { ...@@ -40,7 +40,7 @@ export function useHover(props: UseHoverOptions) {
}, parseInt(props.hoverStayTime as string)) }, parseInt(props.hoverStayTime as string))
}) })
} }
function onTouchstart(evt: TouchEvent) { function onTouchstartPassive(evt: TouchEvent) {
// TODO detect scrolling // TODO detect scrolling
if ((evt as any)._hoverPropagationStopped) { if ((evt as any)._hoverPropagationStopped) {
return return
...@@ -77,7 +77,7 @@ export function useHover(props: UseHoverOptions) { ...@@ -77,7 +77,7 @@ export function useHover(props: UseHoverOptions) {
return { return {
hovering, hovering,
binding: { binding: {
onTouchstart, onTouchstartPassive,
onTouchend, onTouchend,
onTouchcancel, onTouchcancel,
}, },
......
...@@ -1286,9 +1286,10 @@ function initPublicPage(route) { ...@@ -1286,9 +1286,10 @@ function initPublicPage(route) {
} }
function initPage(vm) { function initPage(vm) {
const route = vm.$route; const route = vm.$route;
const page = initPublicPage(route);
vm.$vm = vm; vm.$vm = vm;
vm.$page = initPublicPage(route); vm.$page = page;
currentPagesMap.set(normalizeRouteKey(route.path, vm.$page.id), vm); currentPagesMap.set(normalizeRouteKey(page.path, page.id), vm);
} }
function normalizeRouteKey(path, id2) { function normalizeRouteKey(path, id2) {
return path + SEP + id2; return path + SEP + id2;
...@@ -2006,7 +2007,7 @@ function useHover(props) { ...@@ -2006,7 +2007,7 @@ function useHover(props) {
}, parseInt(props.hoverStayTime)); }, parseInt(props.hoverStayTime));
}); });
} }
function onTouchstart(evt) { function onTouchstartPassive(evt) {
if (evt._hoverPropagationStopped) { if (evt._hoverPropagationStopped) {
return; return;
} }
...@@ -2041,7 +2042,7 @@ function useHover(props) { ...@@ -2041,7 +2042,7 @@ function useHover(props) {
return { return {
hovering, hovering,
binding: { binding: {
onTouchstart, onTouchstartPassive,
onTouchend, onTouchend,
onTouchcancel onTouchcancel
} }
...@@ -12387,7 +12388,7 @@ function usePageRefresh(refreshRef) { ...@@ -12387,7 +12388,7 @@ function usePageRefresh(refreshRef) {
refreshControllerElemStyle.clip = "rect(" + (45 - y) + "px,45px,45px,-5px)"; refreshControllerElemStyle.clip = "rect(" + (45 - y) + "px,45px,45px,-5px)";
refreshControllerElemStyle.transform = "translate3d(-50%, " + y + "px, 0)"; refreshControllerElemStyle.transform = "translate3d(-50%, " + y + "px, 0)";
} }
function onTouchstart(ev) { function onTouchstartPassive(ev) {
const touch = ev.changedTouches[0]; const touch = ev.changedTouches[0];
touchId = touch.identifier; touchId = touch.identifier;
startY = touch.pageY; startY = touch.pageY;
...@@ -12397,7 +12398,7 @@ function usePageRefresh(refreshRef) { ...@@ -12397,7 +12398,7 @@ function usePageRefresh(refreshRef) {
canRefresh = true; canRefresh = true;
} }
} }
function onTouchmove(ev) { function onTouchmovePassive(ev) {
if (!canRefresh) { if (!canRefresh) {
return; return;
} }
...@@ -12500,8 +12501,8 @@ function usePageRefresh(refreshRef) { ...@@ -12500,8 +12501,8 @@ function usePageRefresh(refreshRef) {
const timeout = setTimeout(restoreTransitionEnd, 350); const timeout = setTimeout(restoreTransitionEnd, 350);
} }
return { return {
onTouchstart, onTouchstartPassive,
onTouchmove, onTouchmovePassive,
onTouchend, onTouchend,
onTouchcancel: onTouchend onTouchcancel: onTouchend
}; };
......
...@@ -113,7 +113,7 @@ export function usePageRefresh(refreshRef: Ref) { ...@@ -113,7 +113,7 @@ export function usePageRefresh(refreshRef: Ref) {
refreshControllerElemStyle.transform = 'translate3d(-50%, ' + y + 'px, 0)' refreshControllerElemStyle.transform = 'translate3d(-50%, ' + y + 'px, 0)'
} }
function onTouchstart(ev: TouchEvent) { function onTouchstartPassive(ev: TouchEvent) {
const touch = ev.changedTouches[0] const touch = ev.changedTouches[0]
touchId = touch.identifier touchId = touch.identifier
startY = touch.pageY startY = touch.pageY
...@@ -124,7 +124,7 @@ export function usePageRefresh(refreshRef: Ref) { ...@@ -124,7 +124,7 @@ export function usePageRefresh(refreshRef: Ref) {
} }
} }
function onTouchmove(ev: TouchEvent) { function onTouchmovePassive(ev: TouchEvent) {
if (!canRefresh) { if (!canRefresh) {
return return
} }
...@@ -258,8 +258,8 @@ export function usePageRefresh(refreshRef: Ref) { ...@@ -258,8 +258,8 @@ export function usePageRefresh(refreshRef: Ref) {
} }
return { return {
onTouchstart, onTouchstartPassive,
onTouchmove, onTouchmovePassive,
onTouchend, onTouchend,
onTouchcancel: onTouchend, onTouchcancel: onTouchend,
} }
......
...@@ -73,10 +73,11 @@ function initPublicPage(route: RouteLocationNormalizedLoaded) { ...@@ -73,10 +73,11 @@ function initPublicPage(route: RouteLocationNormalizedLoaded) {
export function initPage(vm: ComponentPublicInstance) { export function initPage(vm: ComponentPublicInstance) {
const route = vm.$route const route = vm.$route
const page = initPublicPage(route)
;(vm as any).$vm = vm ;(vm as any).$vm = vm
;(vm as any).$page = initPublicPage(route) ;(vm as any).$page = page
currentPagesMap.set( currentPagesMap.set(
normalizeRouteKey(route.path, vm.$page.id), normalizeRouteKey(page.path, page.id),
(vm as unknown) as Page.PageInstance (vm as unknown) as Page.PageInstance
) )
} }
......
import fs from 'fs'
import path from 'path'
import { parse } from 'jsonc-parser'
import { Plugin } from 'vite' import { Plugin } from 'vite'
import { VitePluginUniResolvedOptions } from '..' import { VitePluginUniResolvedOptions } from '..'
...@@ -7,14 +11,23 @@ import { createDefine } from './define' ...@@ -7,14 +11,23 @@ import { createDefine } from './define'
import { createServer } from './server' import { createServer } from './server'
import { createBuild } from './build' import { createBuild } from './build'
import { createOptimizeDeps } from './optimizeDeps' import { createOptimizeDeps } from './optimizeDeps'
function resolveBase(inputDir: string) {
const manifest = parse(
fs.readFileSync(path.join(inputDir, 'manifest.json'), 'utf8')
)
return (manifest.h5 && manifest.h5.router && manifest.h5.router.base) || '/'
}
export function createConfig( export function createConfig(
options: VitePluginUniResolvedOptions options: VitePluginUniResolvedOptions
): Plugin['config'] { ): Plugin['config'] {
return (config, env) => { return (config, env) => {
if (config.root) { const root = config.root || process.cwd()
options.root = config.root const inputDir = process.env.UNI_INPUT_DIR || path.resolve(root, 'src')
} const outputDir = process.env.UNI_OUTPUT_DIR || path.resolve(root, 'dist')
options.root = root
options.base = resolveBase(inputDir)
options.inputDir = inputDir
options.outputDir = outputDir
options.command = env.command options.command = env.command
return { return {
base: options.base, base: options.base,
......
...@@ -18,7 +18,7 @@ export function uniCopyPlugin({ ...@@ -18,7 +18,7 @@ export function uniCopyPlugin({
{ {
src: path.resolve(inputDir, 'uni_modules/*/' + PUBLIC_DIR), src: path.resolve(inputDir, 'uni_modules/*/' + PUBLIC_DIR),
dest: outputDir, dest: outputDir,
rename: (name, extension, fullPath) => { rename: (_name, _extension, fullPath) => {
return path.relative(inputDir, fullPath) return path.relative(inputDir, fullPath)
}, },
}, },
......
...@@ -87,7 +87,7 @@ export function resolvePlugins( ...@@ -87,7 +87,7 @@ export function resolvePlugins(
) )
addPlugin(plugins, uniMainJsPlugin(options), 1, 'pre') addPlugin(plugins, uniMainJsPlugin(options), 1, 'pre')
addPlugin(plugins, uniPagesJsonPlugin(config, options), 1, 'pre') addPlugin(plugins, uniPagesJsonPlugin(config, options), 1, 'pre')
addPlugin(plugins, uniManifestJsonPlugin(options), 1, 'pre') addPlugin(plugins, uniManifestJsonPlugin(config, options), 1, 'pre')
addPlugin( addPlugin(
plugins, plugins,
......
import fs from 'fs' import fs from 'fs'
import path from 'path' import path from 'path'
import slash from 'slash'
import { parse } from 'jsonc-parser' import { parse } from 'jsonc-parser'
import { Plugin } from 'vite' import { Plugin, ResolvedConfig } from 'vite'
import { VitePluginUniResolvedOptions } from '../..' import { VitePluginUniResolvedOptions } from '../..'
import slash from 'slash'
import { FEATURE_DEFINES } from '../../utils'
const MANIFEST_JSON_JS = 'manifest.json.js' const MANIFEST_JSON_JS = 'manifest.json.js'
...@@ -31,6 +32,7 @@ const defaultNetworkTimeout = { ...@@ -31,6 +32,7 @@ const defaultNetworkTimeout = {
const defaultQQMapKey = 'XVXBZ-NDMC4-JOGUS-XGIEE-QVHDZ-AMFV2' const defaultQQMapKey = 'XVXBZ-NDMC4-JOGUS-XGIEE-QVHDZ-AMFV2'
export function uniManifestJsonPlugin( export function uniManifestJsonPlugin(
config: ResolvedConfig,
options: VitePluginUniResolvedOptions options: VitePluginUniResolvedOptions
): Plugin { ): Plugin {
const manifestJsonPath = slash(path.join(options.inputDir, 'manifest.json')) const manifestJsonPath = slash(path.join(options.inputDir, 'manifest.json'))
...@@ -43,11 +45,14 @@ export function uniManifestJsonPlugin( ...@@ -43,11 +45,14 @@ export function uniManifestJsonPlugin(
}, },
transform(code, id) { transform(code, id) {
if (id.endsWith(MANIFEST_JSON_JS)) { if (id.endsWith(MANIFEST_JSON_JS)) {
const define = config.define! as FEATURE_DEFINES
const manifest = JSON.parse(code) const manifest = JSON.parse(code)
const { debug, h5 } = manifest const { debug, h5 } = manifest
const appid = (manifest.appid || '').replace('__UNI__', '') const appid = (manifest.appid || '').replace('__UNI__', '')
const router = { ...defaultRouter, ...((h5 && h5.router) || {}) } const router = { ...defaultRouter, ...((h5 && h5.router) || {}) }
const async = { ...defaultAsync, ...((h5 && h5.async) || {}) } const async = define.__UNI_FEATURE_PAGES__
? { ...defaultAsync, ...((h5 && h5.async) || {}) }
: {}
const networkTimeout = { const networkTimeout = {
...defaultNetworkTimeout, ...defaultNetworkTimeout,
......
...@@ -54,7 +54,7 @@ function parsePagesJson( ...@@ -54,7 +54,7 @@ function parsePagesJson(
options: VitePluginUniResolvedOptions options: VitePluginUniResolvedOptions
) { ) {
const pagesJson = normalizePagesJson(jsonStr, options.platform) const pagesJson = normalizePagesJson(jsonStr, options.platform)
const definePagesCode = generatePagesDefineCode(pagesJson) const definePagesCode = generatePagesDefineCode(pagesJson, config)
const uniRoutesCode = generateRoutes(pagesJson) const uniRoutesCode = generateRoutes(pagesJson)
const uniConfigCode = generateConfig(pagesJson, options) const uniConfigCode = generateConfig(pagesJson, options)
const manifestJsonPath = slash( const manifestJsonPath = slash(
...@@ -129,7 +129,18 @@ function generatePageDefineCode(pageOptions: UniApp.PagesJsonPageOptions) { ...@@ -129,7 +129,18 @@ function generatePageDefineCode(pageOptions: UniApp.PagesJsonPageOptions) {
}.vue?mpType=page').then(comp=>setupPage(comp))},AsyncComponentOptions))` }.vue?mpType=page').then(comp=>setupPage(comp))},AsyncComponentOptions))`
} }
function generatePagesDefineCode(pagesJson: UniApp.PagesJson) { function generatePagesDefineCode(
pagesJson: UniApp.PagesJson,
config: ResolvedConfig
) {
const define = config.define! as FEATURE_DEFINES
if (!define.__UNI_FEATURE_PAGES__) {
// single page
const pagePath = pagesJson.pages[0].path
return `import {default as ${normalizePageIdentifier(
pagePath
)}} from './${pagePath}.vue?mpType=page'`
}
const { pages } = pagesJson const { pages } = pagesJson
return ( return (
`const AsyncComponentOptions = { `const AsyncComponentOptions = {
......
import fs from 'fs'
import path from 'path'
import { parse } from 'jsonc-parser'
import { Plugin, ResolvedConfig, ViteDevServer } from 'vite' import { Plugin, ResolvedConfig, ViteDevServer } from 'vite'
import { initEnv } from './env' import { initEnv } from './env'
...@@ -27,32 +23,16 @@ export interface VitePluginUniResolvedOptions extends VitePluginUniOptions { ...@@ -27,32 +23,16 @@ export interface VitePluginUniResolvedOptions extends VitePluginUniOptions {
export * from './vue' export * from './vue'
function resolveBase(inputDir: string) {
const manifest = parse(
fs.readFileSync(path.join(inputDir, 'manifest.json'), 'utf8')
)
return (manifest.h5 && manifest.h5.router && manifest.h5.router.base) || '/'
}
export default function uniPlugin( export default function uniPlugin(
rawOptions: VitePluginUniOptions = {} rawOptions: VitePluginUniOptions = {}
): Plugin { ): Plugin {
const inputDir =
process.env.UNI_INPUT_DIR ||
rawOptions.inputDir ||
path.resolve(process.cwd(), 'src')
const outputDir =
process.env.UNI_OUTPUT_DIR ||
rawOptions.outputDir ||
path.resolve(process.cwd(), 'dist')
const options: VitePluginUniResolvedOptions = { const options: VitePluginUniResolvedOptions = {
...rawOptions, ...rawOptions,
root: process.cwd(), root: process.cwd(),
base: resolveBase(inputDir), base: '/',
assetsDir: 'assets', assetsDir: 'assets',
inputDir, inputDir: '',
outputDir, outputDir: '',
command: 'serve', command: 'serve',
platform: 'h5', platform: 'h5',
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册