1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- /* eslint-disable no-underscore-dangle */
- /* eslint-disable no-param-reassign */
- /* eslint-disable no-unused-vars */
- /* eslint-disable no-shadow */
- import Vue from 'vue';
- import _ from 'lodash';
- // import { Message } from 'element-ui';
- const Plugin = {
- install(Vue, options) {
- // 4. 添加实例方法
- Vue.prototype.$checkRes = (res, okText, errText) => {
- let _okText = okText;
- let _errText = errText;
- if (!_.isFunction(okText) && _.isObject(okText) && okText != null) {
- ({ okText: _okText, errText: _errText } = okText);
- }
- const { errcode = 0, errmsg } = res || {};
- if (errcode === 0) {
- if (_.isFunction(_okText)) {
- return _okText();
- }
- if (_okText) {
- // Vue.prototype.$u.toast({
- // text: _okText,
- // type: 'success',
- // });
-
- }
- return true;
- }
- if (_.isFunction(_errText)) {
- return _errText();
- }
- // Vue.prototype.$u.toast({
- // text: _errText || errmsg,
- // type: 'error',
- // });
- return false;
- };
- },
- };
- Vue.use(Plugin);
|