index.uts 1.4 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
import {
    ShareWithSystem,
    ShareWithSystemOptions,
    ShareWithSystemSuccess,
	ShareWithSystemFail,
} from "../interface.uts";
import { ShareWithSystemFailImpl } from '../unierror.uts';

export const shareWithSystem : ShareWithSystem = function (options : ShareWithSystemOptions) {
	
	ShareManager.options = options
	
	if (options.href == null
		&& options.imageUrl == null
		&& options.imagePaths == null
		&& options.summary == null
		&& options.videoPaths == null
		&& options.audioPaths == null
		&& options.filePaths == null) {
		ShareManager.failedAction(1310601, null)
		return
	}
	
	UniShareWithSystem.sendWithSystem(UTSAndroid.getTopPageActivity()!,options.type, options.summary, 
	options.href, options.imageUrl, options.imagePaths,options.videoPaths,options.filePaths,options.audioPaths,
		function () {
			options.success?.(new ShareWithSystemSuccess())
		},
		function (code:number,err:string) {
			ShareManager.failedAction(code, err)
		},
		function () {
			options.complete?.(new Any())
		})
}
class ShareManager {
	static options : ShareWithSystemOptions | null= null

	static failedAction(errCode : number, errMsg ?: string | null) {
		let err = new ShareWithSystemFailImpl(errCode, errMsg);
		this.options?.fail?.(err)
		this.options?.complete?.(err)
	}

	static successAction() {
		let success = new ShareWithSystemSuccess()
		this.options?.success?.(success)
		this.options?.complete?.(success)
	}
}