New Huajishe Check ChaoXing
This commit is contained in:
17
HuajisheCheckChaoXing/miniprogram_npm/tdesign-miniprogram/message-item/index.d.ts
vendored
Normal file
17
HuajisheCheckChaoXing/miniprogram_npm/tdesign-miniprogram/message-item/index.d.ts
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
/// <reference types="miniprogram-api-typings" />
|
||||
/// <reference types="miniprogram-api-typings" />
|
||||
/// <reference types="miniprogram-api-typings" />
|
||||
import { MessageProps } from '../message/message.interface';
|
||||
declare type Context = WechatMiniprogram.Page.TrivialInstance | WechatMiniprogram.Component.TrivialInstance;
|
||||
interface MessageActionOptionsType extends Optional<MessageProps> {
|
||||
context?: Context;
|
||||
selector?: string;
|
||||
}
|
||||
declare const _default: {
|
||||
info(options: MessageActionOptionsType): WechatMiniprogram.Component.TrivialInstance;
|
||||
success(options: MessageActionOptionsType): WechatMiniprogram.Component.TrivialInstance;
|
||||
warning(options: MessageActionOptionsType): WechatMiniprogram.Component.TrivialInstance;
|
||||
error(options: MessageActionOptionsType): WechatMiniprogram.Component.TrivialInstance;
|
||||
hide(options: MessageActionOptionsType): void;
|
||||
};
|
||||
export default _default;
|
||||
@@ -0,0 +1,46 @@
|
||||
var __rest = (this && this.__rest) || function (s, e) {
|
||||
var t = {};
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
||||
t[p] = s[p];
|
||||
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
||||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
||||
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
||||
t[p[i]] = s[p[i]];
|
||||
}
|
||||
return t;
|
||||
};
|
||||
import { MessageType } from '../message/message.interface';
|
||||
import { getInstance } from '../common/utils';
|
||||
const showMessage = function (options, theme = MessageType.info) {
|
||||
const { context, selector = '#t-message' } = options, otherOptions = __rest(options, ["context", "selector"]);
|
||||
const instance = getInstance(context, selector);
|
||||
if (instance) {
|
||||
instance.resetData(() => {
|
||||
instance.setData(Object.assign({ theme }, otherOptions), instance.show.bind(instance));
|
||||
});
|
||||
return instance;
|
||||
}
|
||||
console.error('未找到组件,请确认 selector && context 是否正确');
|
||||
};
|
||||
export default {
|
||||
info(options) {
|
||||
return showMessage(options, MessageType.info);
|
||||
},
|
||||
success(options) {
|
||||
return showMessage(options, MessageType.success);
|
||||
},
|
||||
warning(options) {
|
||||
return showMessage(options, MessageType.warning);
|
||||
},
|
||||
error(options) {
|
||||
return showMessage(options, MessageType.error);
|
||||
},
|
||||
hide(options) {
|
||||
const { context, selector = '#t-message' } = Object.assign({}, options);
|
||||
const instance = getInstance(context, selector);
|
||||
if (!instance) {
|
||||
return;
|
||||
}
|
||||
instance.hide();
|
||||
},
|
||||
};
|
||||
39
HuajisheCheckChaoXing/miniprogram_npm/tdesign-miniprogram/message-item/message-item.d.ts
vendored
Normal file
39
HuajisheCheckChaoXing/miniprogram_npm/tdesign-miniprogram/message-item/message-item.d.ts
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
/// <reference types="miniprogram-api-typings" />
|
||||
import { SuperComponent, ComponentsOptionsType } from '../common/src/index';
|
||||
import { MessageProps } from '../message/message.interface';
|
||||
export default class Message extends SuperComponent {
|
||||
externalClasses: string[];
|
||||
options: ComponentsOptionsType;
|
||||
properties: MessageProps;
|
||||
data: {
|
||||
prefix: string;
|
||||
classPrefix: string;
|
||||
loop: number;
|
||||
animation: any[];
|
||||
showAnimation: any[];
|
||||
wrapTop: number;
|
||||
fadeClass: string;
|
||||
};
|
||||
closeTimeoutContext: number;
|
||||
nextAnimationContext: number;
|
||||
resetAnimation: WechatMiniprogram.Animation;
|
||||
observers: {
|
||||
marquee(val: any): void;
|
||||
'icon, theme'(icon: any, theme: any): void;
|
||||
link(v: any): void;
|
||||
closeBtn(v: any): void;
|
||||
};
|
||||
lifetimes: {
|
||||
ready(): void;
|
||||
detached(): void;
|
||||
};
|
||||
memoInitialData(): void;
|
||||
resetData(cb: () => void): void;
|
||||
checkAnimation(): void;
|
||||
clearMessageAnimation(): void;
|
||||
show(offsetHeight?: number): void;
|
||||
hide(): void;
|
||||
reset(): void;
|
||||
handleClose(): void;
|
||||
handleLinkClick(): void;
|
||||
}
|
||||
@@ -0,0 +1,187 @@
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
import { SuperComponent, wxComponent } from '../common/src/index';
|
||||
import config from '../common/config';
|
||||
import props from '../message/props';
|
||||
import { getRect, unitConvert, calcIcon, isObject } from '../common/utils';
|
||||
const { prefix } = config;
|
||||
const name = `${prefix}-message`;
|
||||
const SHOW_DURATION = 500;
|
||||
const THEME_ICON = {
|
||||
info: 'info-circle-filled',
|
||||
success: 'check-circle-filled',
|
||||
warning: 'info-circle-filled',
|
||||
error: 'error-circle-filled',
|
||||
};
|
||||
let Message = class Message extends SuperComponent {
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
this.externalClasses = [
|
||||
`${prefix}-class`,
|
||||
`${prefix}-class-content`,
|
||||
`${prefix}-class-icon`,
|
||||
`${prefix}-class-link`,
|
||||
`${prefix}-class-close-btn`,
|
||||
];
|
||||
this.options = {
|
||||
multipleSlots: true,
|
||||
};
|
||||
this.properties = Object.assign({}, props);
|
||||
this.data = {
|
||||
prefix,
|
||||
classPrefix: name,
|
||||
loop: -1,
|
||||
animation: [],
|
||||
showAnimation: [],
|
||||
wrapTop: -999,
|
||||
fadeClass: '',
|
||||
};
|
||||
this.closeTimeoutContext = 0;
|
||||
this.nextAnimationContext = 0;
|
||||
this.resetAnimation = wx.createAnimation({
|
||||
duration: 0,
|
||||
timingFunction: 'linear',
|
||||
});
|
||||
this.observers = {
|
||||
marquee(val) {
|
||||
if (JSON.stringify(val) === '{}' || JSON.stringify(val) === 'true') {
|
||||
this.setData({
|
||||
marquee: {
|
||||
speed: 50,
|
||||
loop: -1,
|
||||
delay: 0,
|
||||
},
|
||||
});
|
||||
}
|
||||
},
|
||||
'icon, theme'(icon, theme) {
|
||||
this.setData({
|
||||
_icon: calcIcon(icon, THEME_ICON[theme]),
|
||||
});
|
||||
},
|
||||
link(v) {
|
||||
const _link = isObject(v) ? Object.assign({}, v) : { content: v };
|
||||
this.setData({ _link });
|
||||
},
|
||||
closeBtn(v) {
|
||||
this.setData({
|
||||
_closeBtn: calcIcon(v, 'close'),
|
||||
});
|
||||
},
|
||||
};
|
||||
this.lifetimes = {
|
||||
ready() {
|
||||
this.memoInitialData();
|
||||
},
|
||||
detached() {
|
||||
this.clearMessageAnimation();
|
||||
},
|
||||
};
|
||||
}
|
||||
memoInitialData() {
|
||||
this.initialData = Object.assign(Object.assign({}, this.properties), this.data);
|
||||
}
|
||||
resetData(cb) {
|
||||
this.setData(Object.assign({}, this.initialData), cb);
|
||||
}
|
||||
checkAnimation() {
|
||||
const { marquee } = this.properties;
|
||||
if (!marquee || marquee.loop === 0) {
|
||||
return;
|
||||
}
|
||||
const speeding = marquee.speed;
|
||||
if (this.data.loop > 0) {
|
||||
this.data.loop -= 1;
|
||||
}
|
||||
else if (this.data.loop === 0) {
|
||||
this.setData({ animation: this.resetAnimation.translateX(0).step().export() });
|
||||
return;
|
||||
}
|
||||
if (this.nextAnimationContext) {
|
||||
this.clearMessageAnimation();
|
||||
}
|
||||
const warpID = `#${name}__text-wrap`;
|
||||
const nodeID = `#${name}__text`;
|
||||
Promise.all([getRect(this, nodeID), getRect(this, warpID)]).then(([nodeRect, wrapRect]) => {
|
||||
this.setData({
|
||||
animation: this.resetAnimation.translateX(wrapRect.width).step().export(),
|
||||
}, () => {
|
||||
const durationTime = ((nodeRect.width + wrapRect.width) / speeding) * 1000;
|
||||
const nextAnimation = wx
|
||||
.createAnimation({
|
||||
duration: durationTime,
|
||||
})
|
||||
.translateX(-nodeRect.width)
|
||||
.step()
|
||||
.export();
|
||||
setTimeout(() => {
|
||||
this.nextAnimationContext = setTimeout(this.checkAnimation.bind(this), durationTime);
|
||||
this.setData({ animation: nextAnimation });
|
||||
}, 20);
|
||||
});
|
||||
});
|
||||
}
|
||||
clearMessageAnimation() {
|
||||
clearTimeout(this.nextAnimationContext);
|
||||
this.nextAnimationContext = 0;
|
||||
}
|
||||
show(offsetHeight = 0) {
|
||||
const { duration, marquee, offset, id } = this.properties;
|
||||
this.setData({
|
||||
visible: true,
|
||||
loop: marquee.loop || this.data.loop,
|
||||
fadeClass: `${name}__fade`,
|
||||
wrapTop: unitConvert(offset[0]) + offsetHeight,
|
||||
});
|
||||
this.reset();
|
||||
this.checkAnimation();
|
||||
if (duration && duration > 0) {
|
||||
this.closeTimeoutContext = setTimeout(() => {
|
||||
this.hide();
|
||||
this.triggerEvent('duration-end', { self: this });
|
||||
}, duration);
|
||||
}
|
||||
const wrapID = id ? `#${id}` : `#${name}`;
|
||||
getRect(this, wrapID).then((wrapRect) => {
|
||||
this.setData({ height: wrapRect.height }, () => {
|
||||
this.setData({
|
||||
fadeClass: ``,
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
hide() {
|
||||
this.reset();
|
||||
this.setData({
|
||||
fadeClass: `${name}__fade`,
|
||||
});
|
||||
setTimeout(() => {
|
||||
this.setData({ visible: false, animation: [] });
|
||||
}, SHOW_DURATION);
|
||||
if (typeof this.onHide === 'function') {
|
||||
this.onHide();
|
||||
}
|
||||
}
|
||||
reset() {
|
||||
if (this.nextAnimationContext) {
|
||||
this.clearMessageAnimation();
|
||||
}
|
||||
clearTimeout(this.closeTimeoutContext);
|
||||
this.closeTimeoutContext = 0;
|
||||
}
|
||||
handleClose() {
|
||||
this.hide();
|
||||
this.triggerEvent('close-btn-click');
|
||||
}
|
||||
handleLinkClick() {
|
||||
this.triggerEvent('link-click');
|
||||
}
|
||||
};
|
||||
Message = __decorate([
|
||||
wxComponent()
|
||||
], Message);
|
||||
export default Message;
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"component": true,
|
||||
"styleIsolation": "apply-shared",
|
||||
"usingComponents": {
|
||||
"t-icon": "../icon/icon",
|
||||
"t-link": "../link/link"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<wxs src="./message-item.wxs" module="_this"></wxs>
|
||||
<wxs src="../common/utils.wxs" module="_" />
|
||||
<import src="../common/template/icon.wxml" />
|
||||
<block wx:if="{{visible}}">
|
||||
<view
|
||||
class="{{classPrefix}} class {{prefix}}-class {{classPrefix}}--{{theme}} {{fadeClass}}"
|
||||
style="{{_._style([_this.getMessageStyles(zIndex, offset, wrapTop), style, customStyle])}}"
|
||||
animation="{{showAnimation}}"
|
||||
id="{{id || classPrefix}}"
|
||||
aria-role="alert"
|
||||
>
|
||||
<view class="{{classPrefix}}__icon--left">
|
||||
<slot name="icon" />
|
||||
<template wx:if="{{_icon}}" is="icon" data="{{tClass: prefix + '-class-icon', ariaHidden: true, ..._icon }}" />
|
||||
</view>
|
||||
<view
|
||||
class="{{classPrefix}}__text-wrap {{marquee ? classPrefix + '__text-nowrap' : ''}}"
|
||||
style="text-align: {{align}}"
|
||||
id="{{classPrefix}}__text-wrap"
|
||||
>
|
||||
<view class="{{classPrefix}}__text {{prefix}}-class-content" id="{{classPrefix}}__text" animation="{{animation}}">
|
||||
<block wx:if="{{content}}">{{content}}</block>
|
||||
<slot name="content" />
|
||||
<slot />
|
||||
</view>
|
||||
</view>
|
||||
<t-link
|
||||
wx:if="{{_link && _link.content}}"
|
||||
class="{{classPrefix}}__link {{prefix}}-class-link"
|
||||
style="{{_._style([_link.style, _link.customStyle])}}"
|
||||
disabled="{{_link.disabled || false}}"
|
||||
hover="{{_link.hover || true}}"
|
||||
theme="{{_link.theme || 'primary'}}"
|
||||
size="{{_link.size || 'medium'}}"
|
||||
prefixIcon="{{_link.prefixIcon || false}}"
|
||||
suffixIcon="{{_link.suffixIcon || false}}"
|
||||
underline="{{_link.underline || false}}"
|
||||
content="{{_link.content || ''}}"
|
||||
navigatorProps="{{_link.navigatorProps || null}}"
|
||||
bind:complete="handleLinkClick"
|
||||
/>
|
||||
<slot name="link" />
|
||||
<view class="{{classPrefix}}__icon--right" bind:tap="handleClose">
|
||||
<slot name="close-btn" />
|
||||
<template
|
||||
wx:if="{{_closeBtn}}"
|
||||
is="icon"
|
||||
data="{{tClass: prefix + '-class-close-btn', ariaRole: 'button', ariaLabel: '关闭', ..._closeBtn }}"
|
||||
/>
|
||||
</view>
|
||||
</view>
|
||||
</block>
|
||||
@@ -0,0 +1,29 @@
|
||||
var isEmptyObj = function (obj) {
|
||||
return JSON.stringify(obj) === '{}';
|
||||
};
|
||||
|
||||
var changeNumToStr = function (arr) {
|
||||
return arr.map(function (item) {
|
||||
return typeof item === 'number' ? item + 'rpx' : item;
|
||||
});
|
||||
};
|
||||
|
||||
var getMessageStyles = function (zIndex, offset, wrapTop) {
|
||||
var arr = changeNumToStr(offset || [0, 0]);
|
||||
var left = arr[1] || 0;
|
||||
var right = arr[1] || 0;
|
||||
|
||||
var zIndexStyle = zIndex ? 'z-index:' + zIndex + ';' : '';
|
||||
var styleOffset = '';
|
||||
|
||||
styleOffset += 'top:' + wrapTop + 'px;';
|
||||
styleOffset += 'left:' + left + ';';
|
||||
styleOffset += 'right:' + right + ';';
|
||||
|
||||
return zIndexStyle + styleOffset;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
getMessageStyles: getMessageStyles,
|
||||
isEmptyObj: isEmptyObj,
|
||||
};
|
||||
@@ -0,0 +1,91 @@
|
||||
.t-float-left {
|
||||
float: left;
|
||||
}
|
||||
.t-float-right {
|
||||
float: right;
|
||||
}
|
||||
@keyframes tdesign-fade-out {
|
||||
from {
|
||||
opacity: 1;
|
||||
}
|
||||
to {
|
||||
opacity: 0;
|
||||
}
|
||||
}
|
||||
.hotspot-expanded.relative {
|
||||
position: relative;
|
||||
}
|
||||
.hotspot-expanded::after {
|
||||
content: '';
|
||||
display: block;
|
||||
position: absolute;
|
||||
left: 0;
|
||||
top: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
transform: scale(1.5);
|
||||
}
|
||||
.t-message {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
transition: opacity 0.3s, transform 0.4s, top 0.4s;
|
||||
display: flex;
|
||||
justify-content: flex-start;
|
||||
height: 96rpx;
|
||||
align-items: center;
|
||||
z-index: 15000;
|
||||
padding: 0 32rpx;
|
||||
box-sizing: border-box;
|
||||
border-radius: var(--td-message-border-radius, var(--td-radius-default, 12rpx));
|
||||
line-height: 1;
|
||||
background-color: var(--td-message-bg-color, var(--td-bg-color-container, var(--td-font-white-1, #ffffff)));
|
||||
box-shadow: var(--td-message-box-shadow, var(--td-shadow-1, 0 1px 10px rgba(0, 0, 0, 0.05), 0 4px 5px rgba(0, 0, 0, 0.08), 0 2px 4px -1px rgba(0, 0, 0, 0.12)));
|
||||
}
|
||||
.t-message__text {
|
||||
display: inline-block;
|
||||
color: var(--td-message-content-font-color, var(--td-text-color-primary, var(--td-font-gray-1, rgba(0, 0, 0, 0.9))));
|
||||
font-size: var(--td-font-size-base, 28rpx);
|
||||
line-height: 44rpx;
|
||||
}
|
||||
.t-message__text-wrap {
|
||||
flex: 1 1 auto;
|
||||
overflow-x: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
.t-message__text-nowrap {
|
||||
word-break: keep-all;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.t-message--info {
|
||||
color: var(--td-message-info-color, var(--td-brand-color, var(--td-primary-color-7, #0052d9)));
|
||||
}
|
||||
.t-message--success {
|
||||
color: var(--td-message-success-color, var(--td-success-color, var(--td-success-color-5, #2ba471)));
|
||||
}
|
||||
.t-message--warning {
|
||||
color: var(--td-message-warning-color, var(--td-warning-color, var(--td-warning-color-5, #e37318)));
|
||||
}
|
||||
.t-message--error {
|
||||
color: var(--td-message-error-color, var(--td-error-color, var(--td-error-color-6, #d54941)));
|
||||
}
|
||||
.t-message__icon--left,
|
||||
.t-message__icon--right {
|
||||
font-size: 44rpx;
|
||||
}
|
||||
.t-message__icon--left:not(:empty) {
|
||||
margin-right: var(--td-spacer, 16rpx);
|
||||
}
|
||||
.t-message__icon--right {
|
||||
color: var(--td-message-close-icon-color, var(--td-text-color-placeholder, var(--td-font-gray-3, rgba(0, 0, 0, 0.4))));
|
||||
}
|
||||
.t-message__icon--right:not(:empty),
|
||||
.t-message__link {
|
||||
flex: 0 0 auto;
|
||||
margin-left: var(--td-spacer, 16rpx);
|
||||
}
|
||||
.t-message__fade {
|
||||
opacity: 0;
|
||||
transform: translateY(-100%);
|
||||
}
|
||||
Reference in New Issue
Block a user