12345678910111213141516171819202122232425262728293031323334353637 |
- /* 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 { Toast } from 'vant';
- const vm = new Vue({});
- 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 = 200, errmsg } = res || {};
- if (errcode === 200) {
- if (_.isFunction(_okText)) {
- return _okText();
- }
- if (_okText) {
- Toast({ type: 'success', message: _okText });
- }
- return true;
- }
- if (_.isFunction(_errText)) {
- return _errText();
- }
- Toast({ type: 'danger', message: errText });
- return false;
- };
- },
- };
- Vue.use(Plugin);
|