first commit
This commit is contained in:
40
uni_modules/tdesign-uniapp/components/message-item/index.js
Normal file
40
uni_modules/tdesign-uniapp/components/message-item/index.js
Normal file
@@ -0,0 +1,40 @@
|
||||
import { MessageType } from '../message/message.interface';
|
||||
import { getInstance } from '../common/utils';
|
||||
|
||||
|
||||
const showMessage = function (options, theme = MessageType.info) {
|
||||
const { context, selector = '#t-message', ...otherOptions } = options;
|
||||
const instance = getInstance(context, selector);
|
||||
|
||||
if (instance) {
|
||||
instance.resetData(() => {
|
||||
instance.setData({ 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' } = { ...options };
|
||||
const instance = getInstance(context, selector);
|
||||
if (!instance) {
|
||||
return;
|
||||
}
|
||||
instance.hide();
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user