import BaseApiCodeTransform from "@stocks/base/transforms/api-code" ; import { ERROR_API_CODE } from "@utils/constant" ; import { COMMON_SH , COMMON_SZ , COMMON_HK , COMMON_US } from "@stocks/base/utils/constant" ; import { TENCENT_SZ , TENCENT_SH , TENCENT_HK , TENCENT_US } from "@stocks/tencent/utils/constant" ; /**
 * 【腾讯】股票代码转换统一代码
 */ class TencentApiCodeTransform extends BaseApiCodeTransform { param code public transform ( code ) { if ( code . indexOf ( TENCENT_SZ ) === 0 ) { return this . SZTransform ( code ) ; } if ( code . indexOf ( TENCENT_SH ) === 0 ) { return this . SHTransform ( code ) ; } if ( code . indexOf ( TENCENT_HK ) === 0 ) { return this . HKTransform ( code ) ; } if ( code . indexOf ( TENCENT_US ) === 0 ) { return this . USTransform ( code ) ; } throw new Error ( ERROR_API_CODE ) ; } param codes public transforms ( codes ) { return super . transforms ( codes ) ; } param code public SZTransform ( code ) { if ( ! code . includes ( TENCENT_SZ ) ) { throw new Error ( ERROR_API_CODE ) ; } return COMMON_SZ + code . replace ( TENCENT_SZ , "" ) ; } param code public SHTransform ( code ) { if ( ! code . includes ( TENCENT_SH ) ) { throw new Error ( ERROR_API_CODE ) ; } return COMMON_SH + code . replace ( TENCENT_SH , "" ) ; } param code public HKTransform ( code ) { if ( ! code . includes ( TENCENT_HK ) ) { throw new Error ( ERROR_API_CODE ) ; } return COMMON_HK + code . replace ( TENCENT_HK , "" ) ; } param code public USTransform ( code ) { if ( ! code . includes ( TENCENT_US ) ) { throw new Error ( ERROR_API_CODE ) ; } return COMMON_US + code . replace ( TENCENT_US , "" ) ; } } export default TencentApiCodeTransform ;