APICloud (seven): clear cache, exit the system, return to the previous level, pull down to refresh the page, return to the top

1. Clear the cache :

/**
 *This method is used to clear the cache of the last week
 *  **/
function clearCache(){
	api.actionSheet({
		title:"The system will permanently delete all data of this application, including downloaded files, temporary photo files, webpage cache files, etc. It may take some time to clear. Please wait patiently.",
		cancelTitle:"Cancel",
		destructiveTitle: "OK"    			
    }, function (ret, err) {
    	if(ret.buttonIndex==1){//OK button
    		//progress bar prompt
    		api.showProgress({
    			animationType:"fade",//The animation type of the progress prompt box
    			title: 'Efforts to clear...',
			    modal: true
            });
            // start clearing
            api.clearCache({
    			timeThreshold:7//How many days ago to clear the cache
            }, function (ret, err) {
            	api.hideProgress();//The progress bar is hidden	            	
            	api.toast({
			        msg: 'Clear complete'
			    });
            });                    
    	}
    });    		
}
Before clearing the cache, you can first check how much storage space the APP occupies through the phone settings, and then use the phone's own method to clear the cache to see how much cache is finally cleared. Then use the clearCache() method that comes with APICloud to clear it to see if the two results are the same. Use this to test whether this method really clears the cache. 2. Exit the system :
//This method is used to exit the system
function quitTheSystem(){
	api.closeWidget({
	    id: api.appId
    });
}
This ID is also the ID of the widget root node in config.xml and the ID of the mobile APP. 3. Return to the previous level :
/**
 * This method is used to return the page
 *  **/
function comeBack(){
	api.historyBack({
    }, function (ret, err) {
    	if (!ret.status) {
        	api.closeWin();
    	}
    });
}
4. Pull down to refresh the page :
apiready=function(){
	refreshList();
}

//This method is used to pull down to refresh
function refreshList(){
	api.setRefreshHeaderInfo ({
		visible:true,//Whether it is visible, if it is set to false, the drop-down area cannot be hidden and the refresh interface is black, and nothing can be seen.
		bgColor: '#ccc',//background color
		textColor: '#fff',//text color
		textDown: 'Pull-down refresh...',//Pull-down text description, default value: Drop-down can refresh
		textUp: 'Release refresh...',//Text description when release, default value: release can refresh
		textLoading: 'Loading..',//Text description of loading status
		//textTime:'',,//Update time text description, the default format is: last update + date time
		showTime:true//Whether to display the update time
	}, function (ret, err) {
	  	//alert("Pull-down refresh succeeded");
		api.refreshHeaderLoadDone();//Restore the default state
	
		//Reload the current page
	    window.location.reload();
	});
}
5. Return to the top : First add a div floating in the lower right corner of the page, put a picture (like a picture of a rocket) in the div, and then add an event to the picture, which will automatically go to the top when clicked. Logically, the monitoring of the scroll bar should be added. If there is a scroll bar on the page, the "back to top" icon needs to be displayed, otherwise the icon will not be displayed or hidden. What I wrote here is relatively simple, and it has been shown. The specific code is as follows: div: <div class="return_top" onclick="returnToTop();"><img src="images/return_top3.png"></div>

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326525287&siteId=291194637