怎么把自己写的js方法和引入的外部链接写在一个js中

怎么把自己写的js方法和引入的外部链接写在一个js中

外部链接

<script src="https://sales-int.com/ldi/mp.js">script>
<script src="https://sales-int.com/ldi/mp/tp.js">script>

自己写的js

// home页
function doShare() {
   var is_agent = parseInt(hxcjs.getUrlString("is_agent"));
   var data={
      "sales_agent":sales_agent,
      "mode":mode,
      "product_no":product_no,
      "page_url":location.href.split('#')[0]
   };
   var url = 
      "common/blank.html?mode=" + mode +
      "&product_no=" + product_no +
      "&is_agent=" + is_agent +
      "&sales_channel_detail=" + sales_channel_detail +
      "&appid=" + appid +
      "&is_self=1&sales_agent=" + sales_agent +
      "&special_apply_no=" + special_apply_no +
      "&security_sign1=" + security_sign1 +
      "&system_source=" + system_source
      if (seed_no!="") {
         data.is_share=4;
         url+="&seed_no="+seed_no;
      }else{
         data.is_share=1;
      }
   if (hxcjs.getUrlString("product_no").split("_")[1] == "YINGXIAO" && hxcjs.getUrlString("product_no").split("_")[0] == "CJB3") {
      $(".hktshare").show()
   } else {
      $(".hktshare").hide()
   }
   var launchBtn = document.getElementById('launch-btn'); //头像 
   if (is_agent == 1) {
      if (product_no.split("_")[1] == "EMT") {
         launchBtn.setAttribute("path", `pages/index/index?source=wtProductB&to=h5tp&sourceType=wt&agentCode=${sales_agent}&identity=salesman&linkUrl=${encodeURIComponent(commonurl_front+url)}`);
      } else if (product_no.split("_")[1] == "YINGXIAO") {
         launchBtn.setAttribute("path", `pages/index/index?source=wtProduct&to=h5tp&sourceType=wt&agentCode=${sales_agent}&identity=salesman&linkUrl=${encodeURIComponent(commonurl_front+url)}`);
      }
   } else {
      if (product_no.split("_")[1] == "EMT") {
         launchBtn.setAttribute("path", `pages/index/index?source=wtProductB&to=h5tp&sourceType=wt&agentCode=${sales_agent}&identity=user&linkUrl=${encodeURIComponent(commonurl_front+url)}`);
      } else if (product_no.split("_")[1] == "YINGXIAO") {
         launchBtn.setAttribute("path", `pages/index/index?source=wtProduct&to=h5tp&sourceType=wt&agentCode=${sales_agent}&identity=user&linkUrl=${encodeURIComponent(commonurl_front+url)}`);
      }
   }
   hktajax()
}
// 自助页面
function loShare() {
   var is_agent = parseInt(hxcjs.getUrlString("is_agent"));
   var url = 
   "blank.html?product_no=" + hxcjs.getUrlString("product_no") + 
   "&seed_no=" + return_appid.seed_no +
   "&sales_agent=" + hxcjs.getUrlString("sales_agent") + 
   "&mode=" + mini_mode + 
   "&appid=" + hxcjs.getUrlString("appid") + 
   "&custid=" + hxcjs.getUrlString("custid") + 
   "&sales_channel_detail=" + hxcjs.getUrlString("sales_channel_detail") +
   "&consult_code=" + hxcjs.getUrlString("consult_code") +
   "&special_apply_no=" + special_apply_no + 
   "&security_sign1=" + security_sign1 + 
   "&system_source=" + system_source;
   if (hxcjs.getUrlString("product_no").split("_")[1] == "YINGXIAO") {
      $(".hktshare").show()
   } else {
      $(".hktshare").hide()
   }
   var launchBtn = document.getElementById('launch-btn'); //头像 
   if (is_agent == 1) {
      if (product_no.split("_")[1] == "EMT") {
         launchBtn.setAttribute("path", `pages/index/index?source=wtProductB&to=h5tp&sourceType=wt&agentCode=${sales_agent}&identity=salesman&linkUrl=${encodeURIComponent(commonurl_front+url)}`);
      } else if (product_no.split("_")[1] == "YINGXIAO") {
         launchBtn.setAttribute("path", `pages/index/index?source=wtProduct&to=h5tp&sourceType=wt&agentCode=${sales_agent}&identity=salesman&linkUrl=${encodeURIComponent(commonurl_front+url)}`);
      }
   } else if (is_agent == 0) {
      if (product_no.split("_")[1] == "EMT") {
         launchBtn.setAttribute("path", `pages/index/index?source=wtProductB&to=h5tp&sourceType=wt&agentCode=${sales_agent}&identity=user&linkUrl=${encodeURIComponent(commonurl_front+url)}`);
      } else if (product_no.split("_")[1] == "YINGXIAO") {
         launchBtn.setAttribute("path", `pages/index/index?source=wtProduct&to=h5tp&sourceType=wt&agentCode=${sales_agent}&identity=user&linkUrl=${encodeURIComponent(commonurl_front+url)}`);
      }
   }
   hktajax()
}
// 信息页面
function goShare() {
   if (product_code.split("_")[1] == "YINGXIAO" && product_code.split("_")[0] == "CJB3") {
      $(".hktshare").show()
   } else {
      $(".hktshare").hide()
   }
   var launchBtn = document.getElementById("launch-btn"); //头像
   console.log("客户", is_agentg);
   console.log("产品", product_code);
   var url =
      "common/blank.html?order_no=" + order_no +
      "&mode=" + mode +
      "&sales_agent=" + sales_agent +
      "&plan_no=" + plan_no +
      "&product_no=" + product_code +
      "&appid=" + hxcjs.getUrlString("appid") +
      "&sales_channel_detail=" + hxcjs.getUrlString("sales_channel_detail") +
      "&zxuserid=" + hxcjs.getUrlString("zxuserid") +
      "&seed_no=" + return_appid.seed_no +
      "&security_sign1=" + security_sign1 +
      "&system_source=" + system_source;
   if (is_agentg == "N") {
      if (product_code.split("_")[1] == "EMT") {
         launchBtn.setAttribute("path", `pages/index/index?source=wtProductB&to=h5tp&sourceType=wt&agentCode=${sales_agent}&identity=salesman&linkUrl=${encodeURIComponent(commonurl_front+url)}`);
      } else if (product_code.split("_")[1] == "YINGXIAO") {
         launchBtn.setAttribute("path", `pages/index/index?source=wtProduct&to=h5tp&sourceType=wt&agentCode=${sales_agent}&identity=salesman&linkUrl=${encodeURIComponent(commonurl_front+url)}`);
      }
   } else if (is_agentg == "Y") {
      if (product_code.split("_")[1] == "EMT") {
         launchBtn.setAttribute("path", `pages/index/index?source=wtProductB&to=h5tp&sourceType=wt&agentCode=${sales_agent}&identity=user&linkUrl=${encodeURIComponent(commonurl_front+url)}`);
      } else if (product_code.split("_")[1] == "YINGXIAO") {
         launchBtn.setAttribute("path", `pages/index/index?source=wtProduct&to=h5tp&sourceType=wt&agentCode=${sales_agent}&identity=user&linkUrl=${encodeURIComponent(commonurl_front+url)}`);
      }
   }
   hktajax()
}
function hktajax() {
   $.ajax({
      url: "https://uc-dev-bg.ihxlife.com/api/v1/wechatt",
      data: {
         pageUrl: location.href.split("#")[0],
      },
      type: "GET",
      success: function (sdata) {
         var configData = {
            debug: false, 
            appId: sdata.data.app_id,
            timestamp: sdata.data.timestamp,
            nonceStr: sdata.data.nonceStr,
            signature: sdata.data.signature,
            jsApiList: [
               "showOptionMenu",
               "onMenuShareTimeline",
               "onMenuShareAppMessage",
               "hideMenuItems",
            ], // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
            openTagList: ["wx-open-launch-weapp"],
         };
         // 加载微信SDK引入js
         wx.config(configData);
         wx.ready(function () {
            //alert('JS-SDK注册成功!可以使用了');
            wx.showOptionMenu();
            // console.log('link', link)
         });
      },
   });
}

你把外部链接的js复制进来就好了

不知道你这个问题是否已经解决, 如果还没有解决的话:
  • 你可以参考下这个问题的回答, 看看是否对你有帮助, 链接: https://ask.csdn.net/questions/679095
  • 这篇博客也不错, 你可以看下js时间案例(里面涉及的方法都在js相关操作中)
  • 除此之外, 这篇博客: 用最简单的例子讲解js中解决异步的方法中的 解决js异步的方法有很多种,今天就讲解一下如何解决js中的异步问题。 部分也许能够解决你的问题, 你可以仔细阅读以下内容或者直接跳转源博客中阅读:

    在讲解异步解决办法之前我们需要知道什么是异步。定时器、AJAX、事件绑定等都会引起js的异步行为,今天用js中的定时器为例来讲解,看下题。

    考虑下题中输出的结果为:

        function getData() {
    		setTimeout(function() {
    			let name = '张三';
    			return name;
    		}, 1000);
    	}
    	console.log(getData());
    

    这里就有很多人会说输出的结果为张三,那就说明你还没有真正理解异步。其实真正的输出结果为:undefined。这是因为setTimeout方法为异步方法。如果不明白为什么会这样,这里我讲一下js的执行机制大家就会更加明白了。

    js执行机制:
    (1).所有同步任务都在主线程上执行,形成一个执行栈(execution context stack);
    (2).主线程之外,还存在一个"任务队列"(task queue),只要异步任务有了运行结果,就在"任务队列"之中放置一个事件;
    (3).一旦"执行栈"中的所有同步任务执行完毕,系统就会读取"任务队列",看看里面有哪些事件,那些对应的异步任务,于是结束等待状态,进入执行栈,开始执行;
    (4).主线程不断重复上面的第三步;

    解决异步的方法一(回调函数):

      function getData(callback) {
      	setTimeout(function() {
      		let name = '张三';
      		callback(name);
      	}, 1000);
      }
      getData(function(aaa){
        console.log(aaa); //等待一秒之后输出 张三
      })
    

    解决异步的方法二(es6的Promise):

    function getData(resolve, reject){
        setTimeout(function() {
    		var name="张三";
    		resolve(name);
    	}, 1000);
    };
    
    var p = new Promise(getData);
    p.then(function(data){
    	console.log(data);//等待一秒之后输出 张三
    })
    

    解决异步的方法三(es7的async/await):
    async用于申明一个异步的function,而await用于等待一个异步方法执行完成。

       async function getData(){ //通过async封装异步方法
    	   return new Promise((resolve, reject) => {
    			setTimeout(function() {
    				var name = '张三';
    				resolve(name);
    			}, 1000);
    		})
    	}
    		
        async function main(){
    		var data = await getData();
    		console.log(data);//等待一秒之后输出 张三
    	}
    	main();
    

    以上就是处理异步最常用的三种方法,不过第一种的回调函数方法是es6之前的处理方法,容易造成回调地狱,不易维护,不建议过多使用。


如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^