index.uts 2.5 KB
Newer Older
DCloud-yyl's avatar
DCloud-yyl 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
import { AppBaseInfoDeviceUtil } from './device/AppBaseInfoDeviceUtil.uts';
import { UTSiOS } from "DCloudUTSFoundation";
import {
	GetAppBaseInfoOptions,
	GetAppBaseInfo,
	GetAppBaseInfoResult
} from '../interface.uts'

export const getAppBaseInfo : GetAppBaseInfo = (config : GetAppBaseInfoOptions | null) : GetAppBaseInfoResult => {
	let filter : Array<string> = [];
	if (config != null && config!.filter != null) {
		filter = config!.filter;
	}

	if (config == null || filter.length == 0) {
		const defaultFilter = [
			"appId",
			"appName",
			"appVersion",
			"appVersionCode",
			"appLanguage",
			"language",
			"version",
			"appWgtVersion",
			"hostLanguage",
			"hostVersion",
			"hostName",
			"hostPackageName",
			"hostSDKVersion",
			"hostTheme",
		];
		filter = defaultFilter;
	}
	return getBaseInfo(filter);
}

function getBaseInfo(filterArray : Array<string>) : GetAppBaseInfoResult {
	let result : GetAppBaseInfoResult = {};
	if (filterArray.indexOf("appId") != -1) {
		result.appId = AppBaseInfoDeviceUtil.getAppID();
	}
	if (filterArray.indexOf("appName") != -1) {
		result.appName = AppBaseInfoDeviceUtil.getAppName();
	}
	if (UTSiOS.isUniMp()) {
		if (filterArray.indexOf("hostPackageName") != -1) {
			result.hostPackageName = AppBaseInfoDeviceUtil.getHostPackageName();
		}
		if (filterArray.indexOf("hostVersion") != -1) {
			result.hostVersion = AppBaseInfoDeviceUtil.getHostVersion();
		}
		if (filterArray.indexOf("hostName") != -1) {
			result.hostName = AppBaseInfoDeviceUtil.getHostName();
		}
		if (filterArray.indexOf("hostTheme") != -1) {
			result.hostTheme = AppBaseInfoDeviceUtil.getHostTheme();
		}
		if (filterArray.indexOf("hostLanguage") != -1) {
			result.hostLanguage = AppBaseInfoDeviceUtil.getHostLanguage();
		}
	}
	
	if (filterArray.indexOf("appVersion") != -1) {
		result.appVersion = AppBaseInfoDeviceUtil.getAppVersion();
	}
	if (filterArray.indexOf("appVersionCode") != -1) {
		result.appVersionCode = AppBaseInfoDeviceUtil.getAppVersionCode();
	}
	
	if (filterArray.indexOf("appLanguage") != -1) {
		result.appLanguage = AppBaseInfoDeviceUtil.getOsLanguageNormal();
	}
	if (filterArray.indexOf("language") != -1) {
		result.language = AppBaseInfoDeviceUtil.getOsLanguage();
	}
	if (filterArray.indexOf("version") != -1) {
		result.version = AppBaseInfoDeviceUtil.getAppInnerVersion();
	}
	if (filterArray.indexOf("appWgtVersion") != -1) {
		result.appWgtVersion = AppBaseInfoDeviceUtil.getAppWgtVersion();
	}

	return result;
}