• vue 前端 问题整理


    列表显示字典数据(方案1)

    template里面的vue代码

    1. <el-table-column label="性别" align="center" prop="sex">
    2. <template #default="scope">
    3. <!-- <dict-tag :options=sysUserSex :value="scope.row.sex"/>-->
    4. {{dictDataLabel( scope.row.sex,sysUserSex )}}
    5. </template>
    6. </el-table-column>
    7. <el-table-column label="婚姻状况" align="center" prop="maritalStatus">
    8. <template #default="scope">
    9. <!-- <dict-tag :options="sys_status" :value="scope.row.maritalStatus"/>-->
    10. {{dictDataLabel( scope.row.maritalStatus,maritalStatusList )}}
    11. </template>
    12. </el-table-column>
    13. <el-table-column label="民族" align="center" prop="nation">
    14. <template #default="scope">
    15. <!-- <dict-tag :options="sys_user_sex" :value="scope.row.nation"/>-->
    16. {{dictDataLabel( scope.row.nation,nationList )}}
    17. </template>
    18. </el-table-column>
    19. <el-table-column label="政治面貌" align="center" prop="politicalOutlook">
    20. <template #default="scope">
    21. <!-- <dict-tag :options="sys_status" :value="scope.row.politicalOutlook"/>-->
    22. {{dictDataLabel( scope.row.politicalOutlook,politicalOutlookList )}}
    23. </template>
    24. </el-table-column>

    获取数据(手动查询字典数据)

    1. // 查询字典集合,
    2. const sysUserSex = ref();
    3. dictByType();
    4. // 手动查询字典数据
    5. function dictByType(){
    6. selectDictByKey( 'sys_user_sex' ).then(res => {
    7. sysUserSex.value = res.data;
    8. })
    9. }
    10. // 查询字典集合,
    11. const maritalStatusList = ref();
    12. maritalStatusByType();
    13. function maritalStatusByType(){
    14. selectDictByKey( 'marital_status' ).then(res => {
    15. maritalStatusList.value = res.data;
    16. })
    17. }
    18. // 查询字典集合,
    19. const nationList = ref();
    20. nationListByType();
    21. function nationListByType(){
    22. selectDictByKey( 'nation' ).then(res => {
    23. nationList.value = res.data;
    24. })
    25. }
    26. // 查询字典集合,
    27. const politicalOutlookList = ref();
    28. politicalOutlookListByType();
    29. function politicalOutlookListByType(){
    30. selectDictByKey( 'political_outlook' ).then(res => {
    31. politicalOutlookList.value = res.data;
    32. })
    33. }
    34. // 获取字典数据和业务表的数据比对,如果是同一个key,会显示对应字典的value
    35. function dictDataLabel(dataValue, dataList) {
    36. if (dataValue) {
    37. let dictData = dataList;
    38. let item = dictData.find(item => item.dictValue == dataValue)
    39. if (item) {
    40. return item.dictLabel;
    41. }
    42. }
    43. }

    // 获取字典数据和业务表的数据比对,如果是同一个key,会显示对应字典的value

    1. function dictDataLabel( dataValue ,dataList ){
    2. if( dataValue ){
    3. let dictData = dataList ;
    4. let item = dictData.find( item=>item.dictValue == dataValue )
    5. if( item){
    6. return item.dictLabel;
    7. }
    8. }
    9. }

    校验文件上传大小

    1. <el-row justify="center">
    2. <el-col :span="24">
    3. <el-form-item class="display-flex" label="企业LOGO" prop="companyLogoUr">
    4. <el-upload
    5. class="avatar-uploader logo-img"
    6. :action=action
    7. :show-file-list="false"
    8. :on-success="uploadImgCompanyLogoUr"
    9. >
    10. <el-image v-if="companyLogoUr" :src="companyLogoUr" class="avatar logo-img"/>
    11. <el-icon v-else class="avatar-uploader-icon logo-img">
    12. <Plus/>
    13. </el-icon>
    14. </el-upload>
    15. </el-form-item>
    16. </el-col>
    17. </el-row>
    18. // 上传前校检格式和大小
    19. function handleBeforeUpload(file) {
    20. // 校验文件名长度
    21. if( file.name.length > 50 ){
    22. ElMessage.error('上传文件名长度不能超过50个汉字!')
    23. return false
    24. }
    25. // 校检文件大小
    26. if( file.size / 1024 / 1024 > 10 ) {
    27. ElMessage.error('上传图片大小不能超过 10MB!')
    28. return false
    29. }
    30. return true;
    31. }

    若依树结构下载选择添加

    添加下拉框的标签; dictOptionsShowAppType是数据

    1. <el-form-item label="app移动端渲染类型" prop="showAppType">
    2. <treeselect v-model="form.showAppType" :options="dictOptionsShowAppType" :show-count="true" placeholder="请选择app移动端渲染类型" />
    3. </el-form-item>

    定义数据: dictOptionsShowAppType: undefined,

    引入jd

    1. import { getToken } from "@/utils/auth";
    2. import Treeselect from "@riophae/vue-treeselect";
    3. import "@riophae/vue-treeselect/dist/vue-treeselect.css";
    4. import { dictTreeSelect,dictListSelect } from '@/api/lowCode/modelDict'

    获取数据

    1. getDictTreeShowAppType() {
    2. let param = {
    3. dictCode: 'render_type',
    4. }
    5. dictTreeSelect(param).then(response => {
    6. this.dictOptionsShowAppType = response.data;
    7. });
    8. },
    9. // 查询下拉树结构
    10. export function dictTreeSelect(query) {
    11. return request({
    12. url: '/system/modelDict/dictTree',
    13. method: 'get',
    14. params: query
    15. })
    16. }

    自定义form表单下拉树结构添加数据后,列表显示id或者key,不显示树的名字(方案2)

    解决方案: modelCategory是列表显示字段;sexFormat定义点击事件

    1. <el-table-column label="模型分类" prop='modelCategory' :formatter="sexFormat" >
    2. </el-table-column>
    3. <el-table-column label="模型类型" prop='modelType' :formatter="sexFormatModelType" >
    4. </el-table-column>

    先查询字典树的所有列表数据,注意是列表,不是树结构

    1. dictListOptions: [],
    2. /** 查询所有字典数据列表 */
    3. getDictList() {
    4. dictListSelect().then(response => {
    5. this.dictListOptions = response.data;
    6. });
    7. },
    8. // 编辑字典和列表返回的id或者字典key去比较,如果相同则发返回对应字典的dictLabel名字,然后渲染到列表
    9. sexFormat(row) {
    10. let obj = ''
    11. this.dictListOptions.forEach((item) => {
    12. if (row.modelCategory == item.id) {
    13. obj = item.dictLabel
    14. }
    15. })
    16. return obj
    17. },
    18. // 编辑字典和列表返回的id或者字典key去比较,如果相同则发返回对应字典的dictLabel名字,然后渲染到列表
    19. sexFormatModelType(row) {
    20. let obj = ''
    21. this.dictListOptions.forEach((item) => {
    22. if (row.modelType == item.id) {
    23. obj = item.dictLabel
    24. }
    25. })
    26. return obj
    27. },

    后端自定义树结构

    control代码
    /**
     * 获取字典树列表
     */
    @GetMapping("/dictTree")
    public AjaxResult deptTree(LowModelDict dept)  {
        return success(lowModelDictService.selectLowModelDictTreeList(dept));
    }
    

    service实现类

    @Override
        public List selectLowModelDictTreeList(LowModelDict dept) {
            // 如果不传父级结构,指定一个父级结构
            if( StringUtils.isBlank( dept.getDictCode() )){
                dept.setDictCode("increment_type");
            }
            // 查询单条父级数据
            LowModelDict lowModelDict = lowModelDictMapper.selectOneModelDict(dept);
            // 查询全部数据
            List depts = lowModelDictMapper.selectLowModelDictList(dept);
            List treeSelects = buildDeptTreeSelect(depts, lowModelDict );
            return treeSelects;
        }
    
    
    
        public List buildDeptTreeSelect(List depts, LowModelDict lowModelDict ) {
            List deptTrees = buildDeptTree(depts , lowModelDict );
            return deptTrees.stream().map(TreeSelect::new).collect(Collectors.toList());
        }
    
    
        public List buildDeptTree(List depts, LowModelDict lowModelDict) {
            List returnList = new ArrayList();
    //        List tempList = depts.stream().map(LowModelDict::getId).collect(Collectors.toList());  // 获取所有的树结构数据
            Long id = lowModelDict.getId();
            for (LowModelDict dept : depts) {
                // 如果是顶级节点, 遍历该父节点的所有子节点
    //            if (!tempList.contains(dept.getParentId())) {  // 获取所有的树结构数据
    //            if ( id.longValue() == dept.getParentId().longValue() ) {   // 不包括父级
                if (   id.longValue() == dept.getId().longValue() ) {    // 包括父级
                    recursionFn(depts, dept);
                    returnList.add(dept);
                }
            }
            if (returnList.isEmpty()) {
                returnList = depts;
            }
            return returnList;
        }
    
        /**
         * 递归列表
         */
        private void recursionFn(List list, LowModelDict t) {
            // 得到子节点列表
            List childList = getChildList(list, t);
            t.setChildren(childList);
            for (LowModelDict tChild : childList) {
                if (hasChild(list, tChild)) {
                    recursionFn(list, tChild);
                }
            }
        }
    
    
        private boolean hasChild(List list, LowModelDict t) {
            return getChildList(list, t).size() > 0;
        }
    
        /**
         * 得到子节点列表
         */
        private List getChildList(List list, LowModelDict t) {
            List tlist = new ArrayList();
            Iterator it = list.iterator();
            while (it.hasNext()) {
                LowModelDict n = (LowModelDict) it.next();
                if (StringUtils.isNotNull(n.getParentId()) && n.getParentId().longValue() == t.getId().longValue()) {
                    tlist.add(n);
                }
            }
            return tlist;
        }
    
    

    mapper接口

    /**
     * 查询数据字典列表
     *
     * @param lowModelDict 数据字典
     * @return 数据字典集合
     */
    public List selectLowModelDictList(LowModelDict lowModelDict);
    // 查询单条父级数据
    LowModelDict selectOneModelDict(LowModelDict lowModelDict);

     xml的sql

    // 查询单条父级数据
    

    查询数据字典列表

    
        select id, parent_id, dict_code, dict_label, dict_sort, dict_flag, dict_1, dict_2, dict_3, dict_4, dict_5, dict_seq, status, create_by, create_date, update_by, update_date, remarks from low_model_dict
    
    
    

    实体类;注意这里是继承 BaseEntity 

    1. package com.ruoyi.common.core.domain.entity;
    2. import com.ruoyi.common.annotation.Excel;
    3. import com.ruoyi.common.core.domain.BaseEntity;
    4. import com.ruoyi.common.core.domain.TreeEntity;
    5. import org.apache.commons.lang3.builder.ToStringBuilder;
    6. import org.apache.commons.lang3.builder.ToStringStyle;
    7. import java.util.ArrayList;
    8. import java.util.Date;
    9. import java.util.List;
    10. /**
    11. * 数据字典对象 low_model_dict
    12. *
    13. * @author ruoyi
    14. * @date 2023-10-24
    15. */
    16. public class LowModelDict extends BaseEntity {
    17. private static final long serialVersionUID = 1L;
    18. /**
    19. * 字典编号主键
    20. */
    21. private Long id;
    22. /** 父部门ID */
    23. private Long parentId;
    24. /**
    25. * 字典代码 唯一
    26. */
    27. @Excel(name = "字典代码 唯一")
    28. private String dictCode;
    29. /**
    30. * 字典名称
    31. */
    32. @Excel(name = "字典名称")
    33. private String dictLabel;
    34. /**
    35. * 字典顺序
    36. */
    37. private Long dictSort;
    38. /**
    39. * 字典标记 1 有效 0 失效
    40. */
    41. private Long dictFlag;
    42. /**
    43. * 扩展字段1
    44. */
    45. private String dict1;
    46. /**
    47. * 扩展字段2
    48. */
    49. private String dict2;
    50. /**
    51. * 扩展字段3
    52. */
    53. private String dict3;
    54. /**
    55. * 扩展字段4
    56. */
    57. private String dict4;
    58. /**
    59. * 扩展字段5
    60. */
    61. private String dict5;
    62. /**
    63. * 字典序列
    64. */
    65. @Excel(name = "字典序列")
    66. private String dictSeq;
    67. /**
    68. * 状态(0正常 1删除 2停用)
    69. */
    70. private String status;
    71. /**
    72. * 创建时间
    73. */
    74. private Date createDate;
    75. /**
    76. * 更新时间
    77. */
    78. private Date updateDate;
    79. /**
    80. * 备注信息
    81. */
    82. private String remarks;
    83. private List<LowModelDict> children = new ArrayList<LowModelDict>();
    84. public List<LowModelDict> getChildren() {
    85. return children;
    86. }
    87. public void setChildren(List<LowModelDict> children) {
    88. this.children = children;
    89. }
    90. public Long getParentId() {
    91. return parentId;
    92. }
    93. public void setParentId(Long parentId) {
    94. this.parentId = parentId;
    95. }
    96. public void setId(Long id) {
    97. this.id = id;
    98. }
    99. public Long getId() {
    100. return id;
    101. }
    102. public void setDictCode(String dictCode) {
    103. this.dictCode = dictCode;
    104. }
    105. public String getDictCode() {
    106. return dictCode;
    107. }
    108. public void setDictLabel(String dictLabel) {
    109. this.dictLabel = dictLabel;
    110. }
    111. public String getDictLabel() {
    112. return dictLabel;
    113. }
    114. public void setDictSort(Long dictSort) {
    115. this.dictSort = dictSort;
    116. }
    117. public Long getDictSort() {
    118. return dictSort;
    119. }
    120. public void setDictFlag(Long dictFlag) {
    121. this.dictFlag = dictFlag;
    122. }
    123. public Long getDictFlag() {
    124. return dictFlag;
    125. }
    126. public void setDict1(String dict1) {
    127. this.dict1 = dict1;
    128. }
    129. public String getDict1() {
    130. return dict1;
    131. }
    132. public void setDict2(String dict2) {
    133. this.dict2 = dict2;
    134. }
    135. public String getDict2() {
    136. return dict2;
    137. }
    138. public void setDict3(String dict3) {
    139. this.dict3 = dict3;
    140. }
    141. public String getDict3() {
    142. return dict3;
    143. }
    144. public void setDict4(String dict4) {
    145. this.dict4 = dict4;
    146. }
    147. public String getDict4() {
    148. return dict4;
    149. }
    150. public void setDict5(String dict5) {
    151. this.dict5 = dict5;
    152. }
    153. public String getDict5() {
    154. return dict5;
    155. }
    156. public void setDictSeq(String dictSeq) {
    157. this.dictSeq = dictSeq;
    158. }
    159. public String getDictSeq() {
    160. return dictSeq;
    161. }
    162. public void setStatus(String status) {
    163. this.status = status;
    164. }
    165. public String getStatus() {
    166. return status;
    167. }
    168. public void setCreateDate(Date createDate) {
    169. this.createDate = createDate;
    170. }
    171. public Date getCreateDate() {
    172. return createDate;
    173. }
    174. public void setUpdateDate(Date updateDate) {
    175. this.updateDate = updateDate;
    176. }
    177. public Date getUpdateDate() {
    178. return updateDate;
    179. }
    180. public void setRemarks(String remarks) {
    181. this.remarks = remarks;
    182. }
    183. public String getRemarks() {
    184. return remarks;
    185. }
    186. @Override
    187. public String toString() {
    188. return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
    189. .append("id", getId())
    190. .append("parentId", getParentId())
    191. .append("dictCode", getDictCode())
    192. .append("dictLabel", getDictLabel())
    193. .append("dictSort", getDictSort())
    194. .append("dictFlag", getDictFlag())
    195. .append("dict1", getDict1())
    196. .append("dict2", getDict2())
    197. .append("dict3", getDict3())
    198. .append("dict4", getDict4())
    199. .append("dict5", getDict5())
    200. .append("dictSeq", getDictSeq())
    201. .append("status", getStatus())
    202. .append("createBy", getCreateBy())
    203. .append("createDate", getCreateDate())
    204. .append("updateBy", getUpdateBy())
    205. .append("updateDate", getUpdateDate())
    206. .append("remarks", getRemarks())
    207. .toString();
    208. }
    209. }

     主键是 Long 类型的时候数据库字段是 bigint 由于长度超过16;返回前端会有精度丢失,导致后端返回的时间id和前端接受的实际id不一致,导致修改失败,需要在启动类添加配置代码

    // 处理Long 类型 返回前端精度丢失问题
    @Bean
    public ObjectMapper jacksonObjectMapper(Jackson2ObjectMapperBuilder builder) {
        ObjectMapper objectMapper = builder.createXmlMapper(false).build();
        SimpleModule simpleModule = new SimpleModule();
        simpleModule.addSerializer(Long.class, ToStringSerializer.instance);
        objectMapper.registerModule(simpleModule);
        return objectMapper;
    }

    若依框架集成 MybatisPlusConfig 添加依赖

     commin 模块 pom.xml

    
    
    
        com.baomidou
        mybatis-plus-boot-starter
    

     最外层的pom.xml

    
    
    
        com.baomidou
        mybatis-plus-boot-starter
        ${mybatis-plus.version}
    
    
    
    
        com.github.pagehelper
        pagehelper-spring-boot-starter
        ${pagehelper.boot.version}
        
            
                org.mybatis
                mybatis
            
        
    

    注释原来 MyBatisConfig

    添加 MybatisPlus 的配置类 MybatisPlusConfig

    1. package com.ruoyi.framework.config;
    2. import com.baomidou.mybatisplus.annotation.DbType;
    3. import com.baomidou.mybatisplus.core.config.GlobalConfig;
    4. import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
    5. import com.baomidou.mybatisplus.extension.plugins.inner.BlockAttackInnerInterceptor;
    6. import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
    7. import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
    8. import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean;
    9. import org.springframework.context.annotation.Bean;
    10. import org.springframework.context.annotation.Configuration;
    11. import org.springframework.transaction.annotation.EnableTransactionManagement;
    12. import javax.sql.DataSource;
    13. import java.io.IOException;
    14. /**
    15. * Mybatis Plus 配置
    16. *
    17. * @author ruoyi
    18. */
    19. @EnableTransactionManagement(proxyTargetClass = true)
    20. @Configuration
    21. public class MybatisPlusConfig {
    22. @Bean
    23. public MybatisPlusInterceptor mybatisPlusInterceptor() {
    24. MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
    25. // 分页插件
    26. interceptor.addInnerInterceptor(paginationInnerInterceptor());
    27. // 乐观锁插件
    28. interceptor.addInnerInterceptor(optimisticLockerInnerInterceptor());
    29. // 阻断插件
    30. interceptor.addInnerInterceptor(blockAttackInnerInterceptor());
    31. return interceptor;
    32. }
    33. /**
    34. * 分页插件,自动识别数据库类型 https://baomidou.com/guide/interceptor-pagination.html
    35. */
    36. public PaginationInnerInterceptor paginationInnerInterceptor() {
    37. PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor();
    38. // 设置数据库类型为mysql
    39. paginationInnerInterceptor.setDbType(DbType.MYSQL);
    40. // 设置最大单页限制数量,默认 500 条,-1 不受限制
    41. paginationInnerInterceptor.setMaxLimit(-1L);
    42. return paginationInnerInterceptor;
    43. }
    44. /**
    45. * 乐观锁插件 https://baomidou.com/guide/interceptor-optimistic-locker.html
    46. */
    47. public OptimisticLockerInnerInterceptor optimisticLockerInnerInterceptor() {
    48. return new OptimisticLockerInnerInterceptor();
    49. }
    50. /**
    51. * 如果是对全表的删除或更新操作,就会终止该操作 https://baomidou.com/guide/interceptor-block-attack.html
    52. */
    53. public BlockAttackInnerInterceptor blockAttackInnerInterceptor() {
    54. return new BlockAttackInnerInterceptor();
    55. }
    56. }

    修改  BaseEntity 类 ;移除部分不用的字段;不移除 mp 查询会报错;因为数据库没相关字段 @TableField(exist = false)

    修改配置 application.yml 文件;移除mybatis的配置,添加mybatisPlus的配置

    1. # MyBatis配置
    2. #mybatis:
    3. # # 搜索指定包别名
    4. # typeAliasesPackage: com.ruoyi.**.domain
    5. # # 配置mapper的扫描,找到所有的mapper.xml映射文件
    6. # mapperLocations: classpath*:mapper/**/*Mapper.xml
    7. # # 加载全局的配置文件
    8. # configLocation: classpath:mybatis/mybatis-config.xml
    9. # MyBatis Plus配置
    10. mybatis-plus:
    11. # 搜索指定包别名
    12. typeAliasesPackage: com.ruoyi.**.domain.**
    13. # 配置mapper的扫描,找到所有的mapper.xml映射文件
    14. mapperLocations: classpath*:mapper/**/*Mapper.xml
    15. # 加载全局的配置文件
    16. configLocation: classpath:mybatis/mybatis-config.xml
    17. # PageHelper分页插件
    18. pagehelper:
    19. helperDialect: mysql
    20. supportMethodsArguments: true
    21. params: count=countSql

    集成 mybatisplus 的分页查询 IPage

    基础实体类继承分页参数类;BaseEntity extends PageDomain

    注意、注意、注意 

    PageDomain 分页类要移除相关字段,数据库表没有相关字段,否则mp查询报错

    集成创建时间、创建人、修改时间、修改人等自动填充

    添加依赖 ruoyi-framework 

    
    
        org.slf4j
        slf4j-api
        1.7.25
    
    
        org.slf4j
        slf4j-log4j12
        1.7.25
    
    
        org.projectlombok
        lombok
        1.18.22
    

    添加自动填充配置类 MyMetaObjectHandler;注意 createTime、createDate等字段在实体类要配置注解;

    1. package com.ruoyi.framework.config;
    2. import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
    3. import com.ruoyi.common.utils.SecurityUtils;
    4. import lombok.extern.slf4j.Slf4j;
    5. import org.apache.ibatis.reflection.MetaObject;
    6. import org.springframework.stereotype.Component;
    7. import java.util.Date;
    8. @Component
    9. @Slf4j
    10. public class MyMetaObjectHandler implements MetaObjectHandler {
    11. @Override
    12. public void insertFill(MetaObject metaObject) {
    13. String operator = null;
    14. try {
    15. operator = SecurityUtils.getUsername();
    16. } catch (Exception e) {
    17. log.error(e.getMessage(), e);
    18. }
    19. this.setFieldValByName("createBy", operator, metaObject);
    20. this.setFieldValByName("createDate", new Date(), metaObject);
    21. this.setFieldValByName("updateBy", operator, metaObject);
    22. this.setFieldValByName("updateDate", new Date(), metaObject);
    23. this.setFieldValByName("createTime", new Date(), metaObject);
    24. this.setFieldValByName("updateTime", new Date(), metaObject);
    25. }
    26. @Override
    27. public void updateFill(MetaObject metaObject) {
    28. String operator = null;
    29. try {
    30. operator = SecurityUtils.getUsername();
    31. } catch (Exception e) {
    32. log.error(e.getMessage(), e);
    33. }
    34. this.setFieldValByName("updateBy", operator, metaObject);
    35. this.setFieldValByName("updateData", new Date(), metaObject);
    36. }
    37. }

    基础实体类 BaseEntity 字段要添加注解;

      @TableField(value = "create_time",fill = FieldFill.INSERT)  // 要和数据库一致

    如果业务实体类 LowModelCode  里面有需要自动填充的字段;也要添加注解

      @TableField(value = "create_time",fill = FieldFill.INSERT)  // 要和数据库一致

    一个vue文件里面执行方法(包括有异步的情况)

    在 onMounted 里面先执行 singleLogin 登录方法,等登录成功后再执行 init() 初始化的方法,登录的同时判断是否有token ,有直接返回,没有就执行登录方法获取token

    1. onMounted(() => {
    2. singleLogin().then(() => {
    3. // singleLogin 执行完毕后再执行 init()
    4. init();
    5. });
    6. });
    7. // 登录
    8. function singleLogin() {
    9. return new Promise((resolve, reject) => {
    10. if (getToken() == undefined || getToken() == null || getToken() == '') {
    11. let param = {
    12. "encryptionStr": getEncryptionStr()
    13. }
    14. singlePointLogin(param).then(res => {
    15. setToken(res.token);
    16. // 注意:在此上下文中,可能无法使用 "this" 来引用当前组件实例
    17. // 如果需要,可以修改为适当的方式引用组件实例
    18. resolve();
    19. }).catch(error => {
    20. // 如果登录过程中发生错误,可以在这里处理
    21. reject(error);
    22. });
    23. } else {
    24. // 如果已经有 Token,直接 resolve
    25. resolve();
    26. }
    27. });
    28. }

    若依前端 form表单多tab页

    1. <!--人脸识别服务tab页-->
    2. <el-tab-pane label="人脸识别服务配置" name="successUrl" v-if="callbackUrl">
    3. <el-form-item label="成功回调" prop="successUrl" required>
    4. <el-input v-model="form.successUrl" placeholder="请输入人脸识别成功回调地址" />
    5. </el-form-item>
    6. <el-form-item label="失败回调" prop="failedUrl" required>
    7. <el-input v-model="form.failedUrl" placeholder="请输入人脸识别失败回调地址" />
    8. </el-form-item>
    9. </el-tab-pane>
    10. js 代码
    11. 定义
    12. const callbackUrl = ref(false);
    13. // 取消按钮 未保存,去掉已经选择的人脸服务数据 使 人脸识别服务tab页 变为默认空值
    14. function cancel() {
    15. open.value = false;
    16. callbackUrl.value=false;
    17. reset();
    18. }
    19. 点击下拉框 动态获取数据,并根据是否选中人脸服务 决定是否显示 人脸识别服务tab页
    20. function getChangeClick(data) {
    21. let ids = form.value.serviceArr?.map(item => item.value);
    22. getChargeType(ids).then(res => {
    23. listDict.value = res.data.list;
    24. isExitEiis.value=res.data.isExitEiis;
    25. });
    26. let label = form.value.serviceArr?.map(item => item.label);
    27. if( label.includes('人脸识别') || label.includes('人脸识别服务') || label.includes('人脸') ){
    28. callbackUrl.value=true;
    29. }else {
    30. callbackUrl.value=false;
    31. }
    32. }
    33. 修改按钮操作 根据返回数据判断是否已经选择人脸服务选项 决定是否显示 人脸识别服务tab页
    34. function handleUpdate(row) {
    35. reset();
    36. const _id = row.id || ids.value;
    37. getAppinfo(_id).then((response) => {
    38. form.value = response.data;
    39. let label = form.value.serviceArr?.map(item => item.label);
    40. if( label.includes('人脸识别') || label.includes('人脸识别服务') || label.includes('人脸') ){
    41. callbackUrl.value=true;
    42. }else {
    43. callbackUrl.value=false;
    44. }
    45. open.value = true;
    46. title.value = "修改企业应用";
    47. listDict.value = response.data.listDict;
    48. });
    49. callbackUrl.value=true;
    50. }

  • 相关阅读:
    04 随机梯度下降
    全网最全Python系列教程(非常详细)---数值篇讲解(学Python入门必收藏)
    几个数组相关常见算法题
    哪些不得不记下的汇编指令
    【操作系统】进程控制
    MIUI13 USB调试Android应用失败INSTALL_FAILED_USER_RESTRICTED
    牛客 2024 【牛客&赛文X】春招冲刺 ONT73 体育课测验(二) 【中等 图/拓扑排序 Java,Go,PHP】
    react写一个从下往上划出的弹框弹窗组件
    vue+three.js中使用Ammo.js
    医生接诊时间难分配?看DHTMLX Scheduler如何助力门诊管理系统优化升级
  • 原文地址:https://blog.csdn.net/qq_36961226/article/details/132752248