12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- export default function (adUnitId) {
- this.Ad = false;
- if (wx.createInterstitialAd) {
- this.Ad = wx.createInterstitialAd({
- adUnitId: adUnitId
- })
- }
- this.show = function (opt) {
- var defaul_opt = {
- show_suc: function () {
- console.log('interstitial ad show suc');
- },
- show_fail: function (err) {
- console.log('interstitial ad show fail', err);
- },
- close: function () {
- console.log('interstitial ad close');
- }
- }
- opt = {
- ...defaul_opt,
- ...opt
- };
- if (!this.Ad) {
- opt.show_fail('this ad is false');
- return false;
- }
- this.Ad.show().then(function () {
- opt.show_suc();
- }).catch(function (err) {
- opt.show_fail(err);
- });
- //on close
- this.Ad.offClose();
- this.Ad.onClose(function () {
- opt.close();
- })
- }
- }
|