mixins 方法混入
sofast-web
├── src
│ ├── mixins
│ │ ├── dictionary.js // 字典共通方法混入
│ │ ├── exportXlsx.js // 导入导出共通方法混入
│ │ ├── file.js // 获取文件全地址
│ │ ├── lang.js // 国际化引用共通方法混入
PS:以下混入中只有dictionary.js中的方法是全局混入,可以直接使用,其他方法需要自行引入
mixins Methods
访问路径 | 方法名称 | 说明 | 参数 | 是否是全局混入 |
---|---|---|---|---|
sofast-web/mixins/dictionary.js | getDictSelectOptions | 根据type获取下拉选项列表 | type(String) | 是 |
sofast-web/mixins/dictionary.js | getDictLabel | 获取字典名称 | type(String),value(String) | 是 |
sofast-web/mixins/dictionary.js | replaceFu | 对字符串中的部分字符进行替换 | replaceStr(String), searchStr(String) | 是 |
sofast-web/mixins/exportXlsx.js | exportData | 导出.xlsx的文件 | action(Function), params(Object), filename(String) | 否 |
sofast-web/mixins/file.js | getFileFullUrl | 获取文件全地址 | url(String) | 否 |
sofast-web/mixins/file.js | getAvatarPreviewUrl | 获取头像预览地址 | url(String) | 否 |
sofast-web/mixins/lang.js | $L_Label | 返回国际化中自定义的组件的标签名 | key(String), format | 否 |
sofast-web/mixins/lang.js | $L_Msg | 返回国际化中自定义的组件的提示信息 | key(String), format | 否 |
sofast-web/mixins/lang.js | $C_Label | 返回国际化中通用的标签名 | key(String), format | 否 |
sofast-web/mixins/lang.js | $C_Msg | 返回国际化中通用的提示信息 | key(String), format | 否 |
sofast-web/mixins/dictionary.js
(1) getDictSelectOptions(type) 根据type获取下拉选项列表
参数:
type:系统管理下的字典管理中保存的数据编码;
(2) getDictLabel(type,value) 获取字典名称
参数:
type:系统管理下的字典管理中保存的数据编码;
value:状态的具体状态值(如:true)或者分类类型的具体分类的值;
(3) replaceFu(replaceStr, searchStr)
参数:
replaceStr: 需要被替换的字符串 searchStr:匹配的正则
sofast-web/mixins/exportXlsx.js
(1)exportData(action, params, filename) 导出文件
参数:
action:是一个function,异步调用api获取所有要下载的数据;
params:发送ajax请求要携带的参数;
filename:为导出的Excel文件起的名字;
sofast-web/mixins/file.js
(1) getFileFullUrl(url) 获取文件全地址
参数:
url:文件相对路径;
(2) getAvatarPreviewUrl(url) 获取头像预览地址
参数:
url:头像相对路径;
sofast-web/mixins/lang.js
(1) $L_Label(key, format) 返回国际化中自定义的组件的标签名
参数:
key:要从国际化中获取标签值的键名;
format:message中占位符的对应替代信息(使用参考下方format的使用);
(2) $L_Msg(key, format) 返回国际化中自定义的组件的提示信息
参数:
key:要从国际化中获取提示信息的键名;
format:message中占位符的对应替代信息;
(3) $C_Label(key, format) 返回国际化中通用的标签名
参数:
key:要从国际化中获取标签值的键名;
format:message中占位符的对应替代信息;
(4) $C_Msg(key, format) 返回国际化中通用的标签名
参数:
key:要从国际化中获取标签值的键名;
format:message中占位符的替代信息;
(5) format参数的使用
语言环境
const messages = {
en: {
common: {
en: {
label: {
hello: '{0}',
vue: '{1}'
},
message: {
helloWorld: '{0} world',
helloVue: '{1} vue'
}
}
},
customModule: {
en: {
label: {
customProperty: '{0}'
},
message: {
customMessage: '{0} message'
}
}
}
}
}
模板如下:
<p>{{ $L_label('customProperty', ['demoProperty']) }}</p>
<p>{{ $C_label('hello', ['Hello']) }}</p>
<p>{{ $L_Msg('customMessage', ['demo']) }}</p>
<p>{{ $C_Msg('helloWorld', ['hello']) }}</p>
输出如下:
<p>demoProperty</p>
<p>Hello</p>
<p>demo message</p>
<p>hello world</p>
列表格式也接受类似数组的对象:
<p>{{ $C_Label('customProperty', {'0': 'demoProperty'}) }}</p>
<p>{{ $C_Label('hello', {'0': 'Hello'}) }}</p>
<p>{{ $C_Msg('customMessage', {'0': 'demo'}) }}</p>
<p>{{ $C_Msg('helloWorld', {'0': 'hello'}) }}</p>
输出如下:
<p>demoProperty</p>
<p>Hello</p>
<p>demo message</p>
<p>hello world</p>
(5) 不传第二个参数的使用
语言环境
const messages = {
en: {
common: {
en: {
label: {
hello: 'hello',
vue: 'vue'
},
message: {
helloWorld: 'hello world',
helloVue: 'hello vue'
}
}
},
customModule: {
en: {
label: {
customProperty: 'CustomProperty'
},
message: {
customMessage: 'CustomMessage'
}
}
}
}
}
模板如下:
<p>{{ $L_label('customProperty') }}</p>
<p>{{ $C_label('hello') }}</p>
<p>{{ $L_Msg('customMessage') }}</p>
<p>{{ $C_Msg('helloWorld') }}</p>
输出如下:
<p>customProperty</p>
<p>hello</p>
<p>CustomMessage</p>
<p>hello world</p>