import BaseCommonCodeTransform from "@stocks/base/transforms/common-code" ; import { ERROR_API_CODE } from "@utils/constant" ; import { SINA_SZ , SINA_SH , SINA_HK , SINA_US } from "@stocks/sina/utils/constant" ; import { COMMON_SH , COMMON_SZ , COMMON_HK , COMMON_US } from "@stocks/base/utils/constant" ; /**
 * 【新浪】股票代码转换统一代码
 */ class SinaCommonCodeTransform extends BaseCommonCodeTransform { param code public transform ( code ) { if ( code . indexOf ( SINA_SZ ) === 0 ) { return this . SZTransform ( code ) ; } if ( code . indexOf ( SINA_SH ) === 0 ) { return this . SHTransform ( code ) ; } if ( code . indexOf ( SINA_HK ) === 0 ) { return this . HKTransform ( code ) ; } if ( code . indexOf ( SINA_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 . indexOf ( SINA_SZ ) !== 0 ) { throw new Error ( ERROR_API_CODE ) ; } return COMMON_SZ + code . replace ( SINA_SZ , "" ) ; } param code public SHTransform ( code ) { if ( code . indexOf ( SINA_SH ) !== 0 ) { throw new Error ( ERROR_API_CODE ) ; } return COMMON_SH + code . replace ( SINA_SH , "" ) ; } param code public HKTransform ( code ) { if ( code . indexOf ( SINA_HK ) !== 0 ) { throw new Error ( ERROR_API_CODE ) ; } return COMMON_HK + code . replace ( SINA_HK , "" ) ; } param code public USTransform ( code ) { if ( code . indexOf ( SINA_US ) !== 0 ) { throw new Error ( ERROR_API_CODE ) ; } return COMMON_US + code . replace ( SINA_US , "" ) . toLowerCase ( ) ; } } export default SinaCommonCodeTransform ;