Browse Source

组件

master
1549469775 3 years ago
parent
commit
ea80a49a78
  1. 1
      package.json
  2. 3
      packages/components/button/aaa.css
  3. 21
      packages/components/button/index.vue
  4. 85
      packages/components/send/index.vue
  5. 11
      packages/hooks/package.json
  6. 5
      packages/hooks/useNamespace.ts
  7. 1
      tsconfig.json

1
package.json

@ -29,6 +29,7 @@
"@princess-ui/components": "workspace:*", "@princess-ui/components": "workspace:*",
"@princess-ui/docs": "workspace:*", "@princess-ui/docs": "workspace:*",
"@princess-ui/playground": "workspace:*", "@princess-ui/playground": "workspace:*",
"@princess-ui/hooks": "workspace:*",
"@princess-ui/share": "workspace:*", "@princess-ui/share": "workspace:*",
"@princess-ui/theme-chalk": "workspace:*", "@princess-ui/theme-chalk": "workspace:*",
"@types/gulp": "^4.0.9", "@types/gulp": "^4.0.9",

3
packages/components/button/aaa.css

@ -1,3 +0,0 @@
div{
background-color: rebeccapurple;
}

21
packages/components/button/index.vue

@ -1,6 +1,6 @@
<template> <template>
<div> <div class="ps-button">
sada{{ color }} <slot>{{text}}</slot>
</div> </div>
</template> </template>
@ -9,22 +9,7 @@ import { defineComponent, PropType } from "vue"
export default defineComponent({ export default defineComponent({
props: { props: {
color: { text: String,
type: String as PropType<'blue' | 'red'>,
required: true
},
aaa: {
type: String as PropType<'dd' | 'red'>,
required: true
},
}, },
}) })
</script> </script>
<style>
@import "./aaa.css";
div {
color: red;
}
</style>

85
packages/components/send/index.vue

@ -1,15 +1,82 @@
<template> <template>
<div> <button @click="onClick" :disabled="isDisabled" :loading="isLoading" type="button" size="small">
send {{ text }}
</div> </button>
</template> </template>
<script setup lang="ts"> <script lang="ts" setup>
import { onBeforeUnmount, ref, watchEffect } from "vue"
const props = withDefaults(
defineProps<{
duration?: number
initText?: string
runText?: string
loadingText?: string
resetText?: string
}>(),
{
runText: "{%s}s 后重新发送",
initText: "获取验证码",
loadingText: "正在发送",
resetText: "重新获取",
duration: 60,
},
)
const emits = defineEmits<{
(event: "update:modelValue", show: boolean): void
(event: "send", start: () => void, done: (isDone: boolean) => void): void
}>()
</script> const text = ref(props.initText)
const isDisabled = ref(false)
const isLoading = ref(false)
let number = props.duration
let timeID: any
onBeforeUnmount(() => {
stop()
})
<style> function stop() {
div{ clearInterval(timeID)
color: gold number = props.duration
text.value = props.resetText
isLoading.value = false
isDisabled.value = false
emits("update:modelValue", false)
}
//
function getText(second: string | number): string {
return props.runText.replace(/\{([^{]*?)%s(.*?)\}/g, String(second))
}
function run() {
isLoading.value = false
text.value = getText(number)
clearInterval(timeID)
timeID = setInterval(() => {
number--
text.value = getText(number)
if (number <= 0) {
stop()
}
}, 1000)
} }
</style>
function onClick() {
emits(
"send",
() => {
isDisabled.value = true
isLoading.value = true
text.value = props.loadingText
},
(isDone: boolean) => {
if (isDone) {
run()
} else {
stop()
}
},
)
}
</script>

11
packages/hooks/package.json

@ -0,0 +1,11 @@
{
"name": "@princess-ui/hooks",
"version": "1.0.0",
"description": "",
"main": "index.ts",
"module": "index.ts",
"scripts": {},
"keywords": [],
"author": "",
"license": "ISC"
}

5
packages/hooks/useNamespace.ts

@ -0,0 +1,5 @@
export function useNamespace(text: string) {
return {
}
}

1
tsconfig.json

@ -6,6 +6,7 @@
"noImplicitAny": false, "noImplicitAny": false,
"declaration": true, "declaration": true,
"sourceMap": true, "sourceMap": true,
"jsx": "preserve",
"moduleResolution": "Node", "moduleResolution": "Node",
"lib": ["ES2018", "DOM", "DOM.Iterable"], "lib": ["ES2018", "DOM", "DOM.Iterable"],
"allowSyntheticDefaultImports": true "allowSyntheticDefaultImports": true

Loading…
Cancel
Save