Skip to content

Commit

Permalink
fix: 修复h5部分组件样式错误
Browse files Browse the repository at this point in the history
  • Loading branch information
yang1206 committed Jul 9, 2023
1 parent 9a0f95e commit cfb1e4b
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 66 deletions.
2 changes: 1 addition & 1 deletion example/package.json
Expand Up @@ -79,7 +79,7 @@
"unocss": "^0.53.1",
"unocss-applet": "^0.5.3",
"unplugin-auto-import": "^0.16.4",
"vite": "4.3.9",
"vite": "4.4.2",
"vue-tsc": "1.6.5"
}
}
1 change: 1 addition & 0 deletions example/src/components.d.ts
Expand Up @@ -84,6 +84,7 @@ declare module '@vue/runtime-core' {
NutSkeleton: typeof import('uniapp-nutui/components/skeleton/skeleton.vue')['default']
NutSku: typeof import('uniapp-nutui/components/sku/sku.vue')['default']
NutSkuHeader: typeof import('uniapp-nutui/components/skuheader/skuheader.vue')['default']
NutSkuOperate: typeof import('uniapp-nutui/components/skuoperate/skuoperate.vue')['default']
NutStep: typeof import('uniapp-nutui/components/step/step.vue')['default']
NutSteps: typeof import('uniapp-nutui/components/steps/steps.vue')['default']
NutSticky: typeof import('uniapp-nutui/components/sticky/sticky.vue')['default']
Expand Down
2 changes: 1 addition & 1 deletion example/vite.config.ts
Expand Up @@ -7,7 +7,7 @@ import UniPages from '@uni-helper/vite-plugin-uni-pages'
import UniManifest from '@uni-helper/vite-plugin-uni-manifest'
import UniLayouts from '@uni-helper/vite-plugin-uni-layouts'
import unocss from 'unocss/vite'
import { NutResolver } from '../packages/nutui/src'
import { NutResolver } from 'uniapp-nutui'

// https://vitejs.dev/config/
export default defineConfig({
Expand Down
8 changes: 7 additions & 1 deletion packages/nutui/components/popover/popover.vue
Expand Up @@ -94,7 +94,13 @@ function getRootPosition() {
if (width) {
if (['bottom', 'top'].includes(direction)) {
const h = direction === 'bottom' ? height + cross : -(conentHeight + cross)
let h
// #ifdef H5
h = 0
// #endif
// #ifndef H5
h = direction === 'bottom' ? height + cross : -(conentHeight + cross)
// #endif
popoverstyles.value.top = `${top + h}px`
if (!skew)
Expand Down
25 changes: 24 additions & 1 deletion packages/nutui/src/resolver/index.ts
@@ -1,5 +1,28 @@
import type { ComponentResolver } from '@uni-helper/vite-plugin-uni-components'

const processShim: typeof process
= typeof process !== 'undefined' ? process : ({} as typeof process)
const envShim = processShim.env || ({} as typeof process.env)

type PLATFORM =
| 'h5'
| 'app'
| 'mp-alipay'
| 'mp-baidu'
| 'mp-kuaishou'
| 'mp-lark'
| 'mp-qq'
| 'mp-toutiao'
| 'mp-weixin'
| 'quickapp-webview'
| 'quickapp-webview-huawei'
| 'quickapp-webview-union'

/** Value of `process.env.UNI_PLATFORM` */
export const platform = envShim.UNI_PLATFORM as PLATFORM
/** Detect if `process.env.UNI_PLATFORM` is `H5` */
export const isH5 = platform === 'h5'

export function NutResolver(): ComponentResolver {
return {
type: 'component',
Expand All @@ -12,7 +35,7 @@ export function NutResolver(): ComponentResolver {
return {
name,
from: component,
// sideEffects: style,
sideEffects: isH5 ? style : '',
}
}
},
Expand Down

0 comments on commit cfb1e4b

Please sign in to comment.