Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@sweetui/sweet-mobile

Package Overview
Dependencies
Maintainers
3
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sweetui/sweet-mobile - npm Package Compare versions

Comparing version 2.0.2 to 2.1.0

i18n/index.js

2

index.js
import sweetStore from './store';
import SWXHR from './xhr';
import SWTOOL from './tool';
import sweetI18n from './i18n';
export { sweetI18n };
export { sweetStore };
export { SWXHR };
export { SWTOOL };

2

package.json
{
"name": "@sweetui/sweet-mobile",
"version": "2.0.2",
"version": "2.1.0",
"description": "Sweet Mobile Core",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -1,54 +0,1 @@

import Vue from 'vue';
import VueI18n from 'vue-i18n';
Vue.use(VueI18n);
export default {
// 获取语言包
getLang({ state }, lang) {
lang = lang || state.language;
return import ('@/locale/' + lang + '.json');
},
// 初始化语言
initLang({ state, commit, dispatch }, lang) {
lang = lang || state.language;
const getInitLang = dispatch('getLang', lang);
return Promise.all([getInitLang])
.then(([sysLang]) => {
return dispatch('mergeLang', { lang, sysLang })
.then(() => {
const i18n = new VueI18n({
locale: lang,
fallbackLocale: 'zh-CN',
messages: state.locale
});
return i18n;
});
});
},
// 切换语言
updateLang({ state, commit, dispatch }, { lang, i18n }) {
window.localStorage.setItem('userLang', lang);
commit('SET_LANG', lang);
const getSysLang = dispatch('getLang', lang);
return Promise.all([getSysLang])
.then(([sysLang]) => {
return dispatch('mergeLang', { lang, sysLang }).then(messages => {
i18n.locale = lang;
i18n.mergeLocaleMessage(lang, messages[lang]);
});
});
},
// 合并语言
mergeLang({ state, commit, dispatch }, { lang, sysLang }) {
const messages = {};
messages[lang] = sysLang;
commit('SET_LOCALE', Object.assign({}, state.locale, messages));
return messages;
}
};
export default {}

@@ -10,6 +10,6 @@ import Vue from 'vue';

export default new Vuex.Store({
strict: process.env.NODE_ENV !== 'production',
state,
mutations,
actions
strict: process.env.NODE_ENV !== 'production',
state,
mutations,
actions
});

@@ -1,8 +0,1 @@

export default {
SET_LOCALE(state, locale) {
state.locale = locale;
},
SET_LANG(state, lang) {
state.language = lang;
}
};
export default {}

@@ -1,6 +0,1 @@

const language = window.localStorage.getItem('userLang') || (window.navigator.language || window.navigator.browserLanguage);
export default {
language,
locale: {}
};
export default {};
{
"name": "sweet-plugin-tool",
"version": "2.0.1",
"version": "2.1.0",
"description": "sweet 前端工具类库",

@@ -5,0 +5,0 @@ "main": "index.js",

import axios from 'axios';
const SWXHR = function(Vue, options, store, tool) {
this.Vue = Vue;
// 注册
this._reg(store, tool);
var that = this,
deOptions = {
config: {
baseURL: '',
timeout: 0,
headers: {},
maxStatus: 500
},
intercept: {
// 请求前
request(p) {
return p;
},
// 请求后
response(response) {
return response;
}
}
};
// this.OPTIONS = {
// config: Object.assign(deOptions.config, options.config),
// intercept: Object.assign(deOptions.intercept, options.intercept)
// };
this.OPTIONS = this.SWTOOL.object.extend(true, deOptions, options);
that.axios = axios.create(this.OPTIONS.config);
// 添加请求拦截器
that._setInterceptors();
const SWXHR = function (Vue, options, store, tool) {
this.Vue = Vue;
// 注册
this._reg(store, tool);
var that = this,
deOptions = {
config: {
// baseURL: '',
timeout: 0,
headers: {},
maxStatus: 500
},
intercept: {
// 请求前
request(p) {
return p;
},
// 请求后
response(response) {
return response;
}
}
};
// this.OPTIONS = {
// config: Object.assign(deOptions.config, options.config),
// intercept: Object.assign(deOptions.intercept, options.intercept)
// };
this.OPTIONS = this.SWTOOL.object.extend(true, deOptions, options);
that.axios = axios.create(this.OPTIONS.config);
// 添加请求拦截器
that._setInterceptors();
};
SWXHR.prototype = {
install(Vue) {
if (this.install.installed) return;
this.install.installed = true;
Vue.prototype.SWXHR = this;
},
_reg(store, tool) {
// 注册工具类
if (tool) {
this.SWTOOL = tool.SWTOOL;
}
if (store) {
store.SWXHR = this;
store.SWTOOL = this.SWTOOL;
}
},
_setInterceptors() {
var intercept = this.OPTIONS.intercept,
request = intercept.request,
response = intercept.response,
defaultError = function(error) {
// 对请求错误做些什么
return Promise.reject(error);
};
install(Vue) {
if (this.install.installed) return;
this.install.installed = true;
Vue.prototype.SWXHR = this;
},
_reg(store, tool) {
// 注册工具类
if (tool) {
this.SWTOOL = tool.SWTOOL;
}
if (store) {
store.SWXHR = this;
store.SWTOOL = this.SWTOOL;
}
},
_setInterceptors() {
var intercept = this.OPTIONS.intercept,
request = intercept.request,
response = intercept.response,
defaultError = function (error) {
// 对请求错误做些什么
return Promise.reject(error);
};
if (request && typeof request === 'function')
this.axios.interceptors.request.use(request, defaultError);
if (request && typeof request === 'function')
this.axios.interceptors.request.use(request, defaultError);
if (response && typeof response === 'function')
this.axios.interceptors.response.use(response, defaultError);
},
_getAxios(type, args) {
var url = args[0],
data = args[1] ? args[1] : {};
if (!url) return;
return this.axios[type.toLowerCase()](url, data);
},
GET() {
return this._getAxios('GET', arguments);
},
POST() {
return this._getAxios('POST', arguments);
},
DELETE() {
return this._getAxios('DELETE', arguments);
},
PUT() {
return this._getAxios('PUT', arguments);
},
ALL() {
return this.axios.all(arguments);
},
SPREAD() {
return this.axios.spread(arguments);
if (response && typeof response === 'function')
this.axios.interceptors.response.use(response, defaultError);
},
_getAxios(type, args) {
var url = args[0],
data = args[1] ? args[1] : {};
if (!url) return;
// 在server.config.js中寻找匹配前缀的代理
for (const [prefix, target] of Object.entries(this.OPTIONS.config.proxy)) {
if (url.startsWith(prefix)) {
url = target + url.replace(prefix, '')
break
}
}
return this.axios[type.toLowerCase()](url, data);
},
GET() {
return this._getAxios('GET', arguments);
},
POST() {
return this._getAxios('POST', arguments);
},
DELETE() {
return this._getAxios('DELETE', arguments);
},
PUT() {
return this._getAxios('PUT', arguments);
},
ALL() {
return this.axios.all(arguments);
},
SPREAD() {
return this.axios.spread(arguments);
}
};
export default SWXHR;
{
"name": "sweet-plugin-xhr",
"version": "2.0.1",
"version": "2.1.0",
"description": "基于axios第三方ajax组件封装的sweet 2.x 版本的组件",

@@ -5,0 +5,0 @@ "main": "index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc