**
原本开发模板中的util已经存在有字典映射的标签的。但是有点小bug。
**
直接上图
1、第一步 就是要查出来字典数组,可以参考原本ruoyi的手册
在页面引入
import { getDicts } from "@/api/system/dict/data";
页面获取参数
export default {
data() {
return {
xxxxxOptions: [],
.....
...
created() {
//不要用this 页面引入。this 获取不到的。
getDicts("字典类型").then(response => {
this.xxxxxOptions = response.data;
});
},
2、第二部修改,工具类
找到文件所在
修改内部的方法
// 回显数据字典
export function selectDictLabel(datas, value) {
if (value === undefined) {
return "";
}
console.log(datas)
var actions = [];
Object.keys(datas).some((key) => {
if (datas[key].dictValue == ('' + value)) {
//就是value改成dictValue 。要不然一直找不到都是空的。包括标签也是。
actions.push(datas[key].dictLabel);
return true;
}
})
if (actions.length === 0) {
actions.push(value);
}
return actions.join('');
}
在页面中如何使用:
import {
parseTime,
selectDictLabel //主要是这个
} from '@/utils/ruoyi'
Method(){
selectDictLabel , //方法中要定义一下
...
}
表格中使用
<uni-td>
//orderstatusOption 字典数组 , item.status找的value
{{selectDictLabel(orderstatusOption, item.status) }}
</uni-td>