123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- <template>
- <div class="xtx-confirm">
- <div class="wrapper" ref="target">
- <div class="header" v-if="options.title">
- <h3>{{ options.title }}</h3>
- <a href="JavaScript:;" class="iconfont icon-close-new" @click="cancelCallback"></a>
- </div>
- <div class="body">
- <div class="typeImg">
- <img
- style="height: 48px; width: 48px"
- v-if="options.type == 'success'"
- src="@/assets/images/icon/success.png"
- alt=""
- />
- <img
- style="height: 48px; width: 48px"
- v-else-if="options.type == 'warn'"
- src="@/assets/images/icon/warn.png"
- alt=""
- />
- <img
- style="height: 48px; width: 48px"
- v-else
- src="@/assets/images/icon/error.png"
- alt=""
- />
- </div>
- <span>{{ options.text }}</span>
- </div>
- <div class="footer">
- <!-- <button @click="cancelCallback" size="mini" type="gray">取消</button> -->
- <button @click="confirmCallback" size="mini" type="primary">{{t('confirm')}}</button>
- </div>
- </div>
- </div>
- </template>
-
- <script lang="ts">
- // 注意:当前组件不是在 #app 下进行渲染,无法使用 #app 下的环境(全局组件,全局指令,原型属性函数)
- import { ref } from 'vue'
- import { useI18n } from 'vue-i18n'
- // import { onClickOutside } from '@vueuse/core'
- export default {
- name: 'showConfirm',
- props: {
- type: {
- type: String,
- default: 'success'
- },
- options: {
- type: Object,
- default: () => {
- return {
- title: '',
- text: '',
- type: 'success',
- callback: () => {}
- }
- }
- },
- // 关闭方法
- close: {
- type: Function,
- default: () => {}
- },
- // 取消按钮
- // cancelCallback: {
- // type: Function,
- // default: () => {}
- // }
- },
- setup(props) {
- // 点击 target 目标元素外部相当于点击了取消
- const { t } = useI18n()
- const target = ref(null)
- // onClickOutside(target, () => {
- // props.cancelCallback()
- // })
- function cancelCallback() {
- props.close()
- }
- function confirmCallback() {
- props.options.callback()
- props.close()
- }
- return { options:props.options,target,confirmCallback,cancelCallback, t }
- }
- }
- </script>
- <style scoped lang="less">
- .xtx-confirm {
- position: fixed;
- left: 0;
- top: 0;
- width: 100%;
- height: 100%;
- z-index: 8888;
- background: rgba(0, 0, 0, 0.5);
- .wrapper {
- width: calc(100% - 40px);
- max-width: 400px;
- border-radius: 10px 10px 10px 10px;
- background: #fff;
- border-radius: 4px;
- position: absolute;
- top: 50%;
- left: 50%;
- transform: translate(-50%, -50%);
- .header,
- .footer {
- height: 50px;
- line-height: 50px;
- padding: 0 20px;
- text-align: center;
- }
- .body {
- padding: 30px 40px;
- font-size: 16px;
- font-family: PingFang SC-Regular, PingFang SC;
- font-weight: 400;
- color: #202020;
- line-height: 19px;
- text-align: center;
- .icon-warning {
- color: red;
- margin-right: 3px;
- font-size: 16px;
- }
- .typeImg {
- margin-bottom: 20px;
- }
- }
- .footer {
- // text-align: right;
- border-top: 1px solid #ebebeb;
- padding: 20px;
- .xtx-button {
- margin-left: 20px;
- }
- button {
- height: 40px;
- background: #29b2ff;
- border-radius: 4px 4px 4px 4px;
- opacity: 1;
- font-size: 14px;
- font-family: PingFang SC-Regular, PingFang SC;
- font-weight: 400;
- color: #ffffff;
- border: none;
- padding: 10px 50px;
- text-align: center;
- margin: 0 15px;
- }
- }
- .header {
- position: relative;
- h3 {
- font-weight: normal;
- font-size: 18px;
- }
- a {
- position: absolute;
- right: 15px;
- top: 15px;
- font-size: 20px;
- width: 20px;
- height: 20px;
- line-height: 20px;
- text-align: center;
- color: #999;
- &:hover {
- color: #666;
- }
- }
- }
- }
- }
- </style>
-
-
|