dict.ts 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /**
  2. * 数据字典工具类
  3. */
  4. import { useDictStoreWithOut } from '@/store/modules/dict'
  5. import { ElementPlusInfoType } from '@/types/elementPlus'
  6. const dictStore = useDictStoreWithOut()
  7. /**
  8. * 获取 dictType 对应的数据字典数组
  9. *
  10. * @param dictType 数据类型
  11. * @returns {*|Array} 数据字典数组
  12. */
  13. export interface DictDataType {
  14. dictType: string
  15. label: string
  16. value: string | number | boolean
  17. colorType: ElementPlusInfoType | ''
  18. cssClass: string
  19. }
  20. export const getDictOptions = (dictType: string) => {
  21. return dictStore.getDictByType(dictType) || []
  22. }
  23. export const getIntDictOptions = (dictType: string) => {
  24. const dictOption: DictDataType[] = []
  25. const dictOptions: DictDataType[] = getDictOptions(dictType)
  26. dictOptions.forEach((dict: DictDataType) => {
  27. dictOption.push({
  28. ...dict,
  29. value: parseInt(dict.value + '')
  30. })
  31. })
  32. return dictOption
  33. }
  34. export const getStrDictOptions = (dictType: string) => {
  35. const dictOption: DictDataType[] = []
  36. const dictOptions: DictDataType[] = getDictOptions(dictType)
  37. dictOptions.forEach((dict: DictDataType) => {
  38. dictOption.push({
  39. ...dict,
  40. value: dict.value + ''
  41. })
  42. })
  43. return dictOption
  44. }
  45. export const getBoolDictOptions = (dictType: string) => {
  46. const dictOption: DictDataType[] = []
  47. const dictOptions: DictDataType[] = getDictOptions(dictType)
  48. dictOptions.forEach((dict: DictDataType) => {
  49. dictOption.push({
  50. ...dict,
  51. value: dict.value + '' === 'true'
  52. })
  53. })
  54. return dictOption
  55. }
  56. /**
  57. * 获取指定字典类型的指定值对应的字典对象
  58. * @param dictType 字典类型
  59. * @param value 字典值
  60. * @return DictDataType 字典对象
  61. */
  62. export const getDictObj = (dictType: string, value: any): DictDataType | undefined => {
  63. const dictOptions: DictDataType[] = getDictOptions(dictType)
  64. console.log(dictOptions)
  65. for (const dict of dictOptions) {
  66. if (dict.value === value + '') {
  67. return dict
  68. }
  69. }
  70. }
  71. /**
  72. * 获得字典数据的文本展示
  73. *
  74. * @param dictType 字典类型
  75. * @param value 字典数据的值
  76. * @return 字典名称
  77. */
  78. export const getDictLabel = (dictType: string, value: any): string => {
  79. const dictOptions: DictDataType[] = getDictOptions(dictType)
  80. const dictLabel = ref('')
  81. dictOptions.forEach((dict: DictDataType) => {
  82. if (dict.value === value + '') {
  83. dictLabel.value = dict.label
  84. }
  85. })
  86. return dictLabel.value
  87. }
  88. export enum DICT_TYPE {
  89. USER_TYPE = 'user_type',
  90. COMMON_STATUS = 'common_status',
  91. SYSTEM_TENANT_PACKAGE_ID = 'system_tenant_package_id',
  92. TERMINAL = 'terminal', // 终端
  93. // ========== SYSTEM 模块 ==========
  94. SYSTEM_USER_SEX = 'system_user_sex',
  95. SYSTEM_MENU_TYPE = 'system_menu_type',
  96. SYSTEM_ROLE_TYPE = 'system_role_type',
  97. SYSTEM_DATA_SCOPE = 'system_data_scope',
  98. SYSTEM_NOTICE_TYPE = 'system_notice_type',
  99. SYSTEM_OPERATE_TYPE = 'system_operate_type',
  100. SYSTEM_LOGIN_TYPE = 'system_login_type',
  101. SYSTEM_LOGIN_RESULT = 'system_login_result',
  102. SYSTEM_SMS_CHANNEL_CODE = 'system_sms_channel_code',
  103. SYSTEM_SMS_TEMPLATE_TYPE = 'system_sms_template_type',
  104. SYSTEM_SMS_SEND_STATUS = 'system_sms_send_status',
  105. SYSTEM_SMS_RECEIVE_STATUS = 'system_sms_receive_status',
  106. SYSTEM_ERROR_CODE_TYPE = 'system_error_code_type',
  107. SYSTEM_OAUTH2_GRANT_TYPE = 'system_oauth2_grant_type',
  108. SYSTEM_MAIL_SEND_STATUS = 'system_mail_send_status',
  109. SYSTEM_NOTIFY_TEMPLATE_TYPE = 'system_notify_template_type',
  110. // ========== INFRA 模块 ==========
  111. INFRA_BOOLEAN_STRING = 'infra_boolean_string',
  112. INFRA_JOB_STATUS = 'infra_job_status',
  113. INFRA_JOB_LOG_STATUS = 'infra_job_log_status',
  114. INFRA_API_ERROR_LOG_PROCESS_STATUS = 'infra_api_error_log_process_status',
  115. INFRA_CONFIG_TYPE = 'infra_config_type',
  116. INFRA_CODEGEN_TEMPLATE_TYPE = 'infra_codegen_template_type',
  117. INFRA_CODEGEN_FRONT_TYPE = 'infra_codegen_front_type',
  118. INFRA_CODEGEN_SCENE = 'infra_codegen_scene',
  119. INFRA_FILE_STORAGE = 'infra_file_storage',
  120. // ========== BPM 模块 ==========
  121. BPM_MODEL_CATEGORY = 'bpm_model_category',
  122. BPM_MODEL_FORM_TYPE = 'bpm_model_form_type',
  123. BPM_TASK_ASSIGN_RULE_TYPE = 'bpm_task_assign_rule_type',
  124. BPM_PROCESS_INSTANCE_STATUS = 'bpm_process_instance_status',
  125. BPM_PROCESS_INSTANCE_RESULT = 'bpm_process_instance_result',
  126. BPM_TASK_ASSIGN_SCRIPT = 'bpm_task_assign_script',
  127. BPM_OA_LEAVE_TYPE = 'bpm_oa_leave_type',
  128. // ========== PAY 模块 ==========
  129. PAY_CHANNEL_CODE = 'pay_channel_code_type', // 支付渠道编码类型
  130. PAY_ORDER_STATUS = 'pay_order_status', // 商户支付订单状态
  131. PAY_REFUND_STATUS = 'pay_refund_status', // 退款订单状态
  132. PAY_NOTIFY_STATUS = 'pay_notify_status', // 商户支付回调状态
  133. PAY_NOTIFY_TYPE = 'pay_notify_type', // 商户支付回调状态
  134. // ========== MP 模块 ==========
  135. MP_AUTO_REPLY_REQUEST_MATCH = 'mp_auto_reply_request_match', // 自动回复请求匹配类型
  136. MP_MESSAGE_TYPE = 'mp_message_type', // 消息类型
  137. // ========== MALL - 会员模块 ==========
  138. MEMBER_POINT_BIZ_TYPE = 'member_point_biz_type', // 积分的业务类型
  139. // ========== MALL - 商品模块 ==========
  140. PRODUCT_UNIT = 'product_unit', // 商品单位
  141. PRODUCT_SPU_STATUS = 'product_spu_status', //商品状态
  142. // ========== MALL - 交易模块 ==========
  143. EXPRESS_CHARGE_MODE = 'trade_delivery_express_charge_mode', //快递的计费方式
  144. TRADE_AFTER_SALE_STATUS = 'trade_after_sale_status', // 售后 - 状态
  145. TRADE_AFTER_SALE_WAY = 'trade_after_sale_way', // 售后 - 方式
  146. TRADE_AFTER_SALE_TYPE = 'trade_after_sale_type', // 售后 - 类型
  147. TRADE_ORDER_TYPE = 'trade_order_type', // 订单 - 类型
  148. TRADE_ORDER_STATUS = 'trade_order_status', // 订单 - 状态
  149. TRADE_ORDER_ITEM_AFTER_SALE_STATUS = 'trade_order_item_after_sale_status', // 订单项 - 售后状态
  150. TRADE_DELIVERY_TYPE = 'trade_delivery_type', // 配送方式
  151. // ========== MALL - 营销模块 ==========
  152. PROMOTION_DISCOUNT_TYPE = 'promotion_discount_type', // 优惠类型
  153. PROMOTION_PRODUCT_SCOPE = 'promotion_product_scope', // 营销的商品范围
  154. PROMOTION_COUPON_TEMPLATE_VALIDITY_TYPE = 'promotion_coupon_template_validity_type', // 优惠劵模板的有限期类型
  155. PROMOTION_COUPON_STATUS = 'promotion_coupon_status', // 优惠劵的状态
  156. PROMOTION_COUPON_TAKE_TYPE = 'promotion_coupon_take_type', // 优惠劵的领取方式
  157. PROMOTION_ACTIVITY_STATUS = 'promotion_activity_status', // 优惠活动的状态
  158. PROMOTION_CONDITION_TYPE = 'promotion_condition_type' // 营销的条件类型枚举
  159. }