applicationDialog.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. <template>
  2. <div>
  3. <!-- 申请方案弹窗 -->
  4. <el-dialog
  5. :close-on-click-modal="false"
  6. :visible.sync="show"
  7. @close="dialogClose"
  8. @opened="dialogOpened"
  9. class="application-scheme-dialog"
  10. center>
  11. <i></i>
  12. <p>免费获得课程开发解决方案</p>
  13. <el-form :model="formData" status-icon :rules="rules" ref="ruleTelForm" class="application-scheme-form">
  14. <el-form-item prop="tel">
  15. <el-input v-model="formData.tel" placeholder="请输入手机号" class="dialog-input-tel"></el-input>
  16. </el-form-item>
  17. <div id="your-dom-id" class="nc-container"></div>
  18. <el-form-item prop="verification">
  19. <div class="verification">
  20. <el-input v-model="formData.verification" placeholder="请输入验证码" class="dialog-input-code"></el-input>
  21. <el-button @click="checkVerification" :disabled="btnTextDisabled" class="dialog-code-btn">{{ btnText }}
  22. </el-button>
  23. </div>
  24. </el-form-item>
  25. </el-form>
  26. <div class="application-scheme-btn" @click="applyFor">申请方案</div>
  27. <!-- <span>免费热线:400-052-2130</span>-->
  28. <!-- <a-->
  29. <!-- href="https://p.qiao.baidu.com/cps/chat?siteId=17930048&userId=40179606&siteToken=e767a987c8404575246ab0084fb2c9bd"-->
  30. <!-- target="_blank">在线客服</a>-->
  31. </el-dialog>
  32. <el-dialog
  33. :close-on-click-modal="false"
  34. :visible.sync="apply_success_dl"
  35. @closed="dialogResultClose"
  36. class="application-scheme-result-dialog"
  37. center
  38. >
  39. <img :src="success_img" class="success_icon">
  40. <h3>恭喜您申请成功</h3>
  41. <p>请保持手机畅通,稍后客服会和您联系</p>
  42. <div class="my-btn confirm-btn" @click="confirmBtn">确定</div>
  43. </el-dialog>
  44. </div>
  45. </template>
  46. <script>
  47. export default {
  48. name: "application",
  49. props: {
  50. visible: {
  51. type: Boolean,
  52. require: true
  53. }
  54. },
  55. data() {
  56. return {
  57. success_img: require(`~/static/productImage/p60.png`),
  58. show: false,
  59. formData: {
  60. tel: '',
  61. verification: '',
  62. },
  63. rules: {
  64. tel: [
  65. {trigger: 'blur', required: true, message: '请输入手机号'},
  66. ],
  67. verification: [
  68. {trigger: 'blur', required: true, message: '请输入验证码'},
  69. ],
  70. },
  71. btnTextDisabled: false,
  72. btnText: '获取验证码',
  73. countdown: 60, // 60秒倒计时
  74. sliderData: {},
  75. appKey: 'FFFF0N00000000007EC0',
  76. apply_success: false,
  77. apply_success_dl: false,
  78. }
  79. },
  80. watch: {
  81. visible: {
  82. handler(newVal) {
  83. this.show = newVal;
  84. },
  85. immediate: true
  86. }
  87. },
  88. methods: {
  89. /**
  90. * 串联加载指定的脚本
  91. * 串联加载[异步]逐个加载,每个加载完成后加载下一个
  92. * 全部加载完成后执行回调
  93. * @param array|string 指定的脚本们
  94. * @param function 成功后回调的函数
  95. * @return array 所有生成的脚本元素对象数组
  96. * 异步加载js后运行回调函数callback / scripts 为数组或字符串
  97. */
  98. seriesLoadScripts(scripts, callback) {
  99. if (typeof (scripts) != 'object') {
  100. var scripts = [scripts];
  101. }
  102. var HEAD = document.getElementsByTagName('head').item(0) || document.documentElement;
  103. var s = new Array(), last = scripts.length - 1, recursiveLoad = function (i) { //递归
  104. s[i] = document.createElement('script');
  105. s[i].setAttribute('type', 'text/javascript');
  106. s[i].onload = s[i].onreadystatechange = function () { //Attach handlers for all browsers
  107. if (!/*@cc_on!@*/0 || this.readyState == 'loaded' || this.readyState == 'complete') {
  108. this.onload = this.onreadystatechange = null;
  109. this.parentNode.removeChild(this);
  110. if (i != last) {
  111. recursiveLoad(i + 1);
  112. } else if (typeof (callback) == 'function') {
  113. callback();
  114. }
  115. }
  116. };
  117. s[i].setAttribute('src', scripts[i]);
  118. HEAD.appendChild(s[i]);
  119. };
  120. recursiveLoad(0);
  121. },
  122. dialogResultClose() {
  123. this.apply_success = false;
  124. this.apply_success_dl = false;
  125. this.$emit('apply_success', true);
  126. },
  127. dialogOpened() {
  128. // 初始化拖拽条
  129. this.initSlide();
  130. },
  131. dialogClose() {
  132. this.show = false;
  133. this.countdown = -1;
  134. this.$refs.ruleTelForm.resetFields();
  135. __nc.reset();
  136. if (this.apply_success === true) {
  137. this.apply_success_dl = true;
  138. }
  139. this.$emit('update:visible', false);
  140. },
  141. // 倒计时60秒
  142. setTime() {
  143. if (this.countdown === 0) {
  144. this.btnTextDisabled = false;
  145. this.btnText = '获取验证码';
  146. this.countdown = 60;
  147. } else if (this.countdown === -1) {
  148. this.btnTextDisabled = false;
  149. this.btnText = '获取验证码';
  150. this.countdown = 60;
  151. } else {
  152. this.btnTextDisabled = true;
  153. this.btnText = '重新发送(' + this.countdown + 's)';
  154. this.countdown--;
  155. setTimeout(() => {
  156. this.setTime();
  157. }, 1000);
  158. }
  159. },
  160. checkVerification() {
  161. if (this.sliderData.appkey === undefined) {
  162. this.$message.error('请先通过滑块校验');
  163. return;
  164. }
  165. const {tel: phone} = this.formData;
  166. this.$axios.$post(`/develop/exists`, {phone}).then(res => {
  167. if (res.code === 0 && res.data) {
  168. const {appkey, scene, csessionid: sessionid, sig, token} = this.sliderData;
  169. let req = {appkey, scene, sig, token, sessionid, phone, type: 1}
  170. this.$axios.$post('/sendCode', req).then(res => {
  171. if (res.code === 0 && res.data) {
  172. this.setTime();
  173. } else {
  174. this.$message.error(res.msg || '手机号已存在');
  175. }
  176. })
  177. } else {
  178. this.$message.error(res.msg || '手机号已存在');
  179. }
  180. })
  181. },
  182. applyFor() {
  183. this.$refs.ruleTelForm.validate((valid) => {
  184. if (valid) {
  185. const {tel: phone, verification: code} = this.formData;
  186. // 请求后台
  187. const options = {phone, code};
  188. this.$axios.$post('/develop/add', options).then(res => {
  189. if (res.code === 0 && res.data) {
  190. this.show = false;
  191. this.apply_success = true;
  192. } else {
  193. this.$message.error('申请失败');
  194. }
  195. });
  196. }
  197. });
  198. },
  199. confirmBtn() {
  200. this.$emit('success_confirm', true);
  201. this.apply_success_dl = false;
  202. },
  203. initSlide() {
  204. const nc_token = [this.appKey, (new Date()).getTime(), Math.random()].join(':');
  205. const NC_Opt = {
  206. //声明滑动验证需要渲染的目标元素ID。
  207. renderTo: '#your-dom-id',
  208. //应用类型标识。它和使用场景标识(scene字段)一起决定了滑动验证的业务场景与后端对应使用的策略模型。您可以在人机验证控制台的配置管理页签找到对应的appkey字段值,请务必正确填写。
  209. appkey: this.appKey,
  210. //使用场景标识。它和应用类型标识(appkey字段)一起决定了滑动验证的业务场景与后端对应使用的策略模型。您可以在人机验证控制台的配置管理页签找到对应的scene值,请务必正确填写。
  211. scene: 'nc_message',
  212. //滑动验证码的主键,请勿将该字段定义为固定值。确保每个用户每次打开页面时,其token值都是不同的。系统默认的格式为:”您的appkey”+”时间戳”+”随机数”。
  213. token: nc_token,
  214. //滑动条的宽度。
  215. customWidth: 300,
  216. //业务键字段,可为空。为便于线上问题的排查,建议您按照线上问题定位文档中推荐的方法配置该字段值。
  217. trans: {'key1': 'code0'},
  218. //通过Dom的ID属性自动填写trans业务键,可为空。建议您按照线上问题定位文档中推荐的方法配置该字段值。
  219. elementID: ['usernameID'],
  220. //是否自定义配置底层采集组件。如无特殊场景,请使用默认值(0),即不自定义配置底层采集组件。
  221. is_Opt: 0,
  222. //语言。PC端Web页面场景默认支持18国语言,详细配置方法请参见自定义文案与多语言文档。
  223. language: 'cn',
  224. //是否启用。一般情况,保持默认值(true)即可。
  225. isEnabled: true,
  226. //内部网络请求的超时时间。一般情况建议保持默认值(3000ms)。
  227. timeout: 3000,
  228. //允许服务器超时重复次数,默认5次。超过重复次数后将触发报错。
  229. times: 5,
  230. //用于自定义滑动验证各项请求的接口地址。一般情况,请勿配置该参数。
  231. apimap: {
  232. // 'analyze': '//a.com/nocaptcha/analyze.jsonp',
  233. // 'get_captcha': '//b.com/get_captcha/ver3',
  234. // 'get_captcha': '//pin3.aliyun.com/get_captcha/ver3'
  235. // 'get_img': '//c.com/get_img',
  236. // 'checkcode': '//d.com/captcha/checkcode.jsonp',
  237. // 'umid_Url': '//e.com/security/umscript/3.2.1/um.js',
  238. // 'uab_Url': '//aeu.alicdn.com/js/uac/909.js',
  239. // 'umid_serUrl': 'https://g.com/service/um.json'
  240. },
  241. //前端滑动验证通过时会触发该回调参数。您可以在该回调参数中将请求标识(token)、会话ID(sessionid)、签名串(sig)字段记录下来,随业务请求一同发送至您的服务端调用验签。
  242. callback: (data) => {
  243. this.sliderData = Object.assign({}, data, {
  244. appkey: NC_Opt.appkey,
  245. scene: NC_Opt.scene,
  246. });
  247. console.log(this.sliderData);
  248. },
  249. };
  250. let date11 = () => {
  251. let _date = new Date();
  252. let year = _date.getFullYear().toString();
  253. let month = _date.getMonth().toString();
  254. let day = _date.getDate().toString();
  255. let a = _date.getHours().toString();
  256. let b = _date.getMinutes().toString();
  257. let c = _date.getSeconds().toString();
  258. return year + month + day + a + b + c;
  259. };
  260. let c = date11();
  261. const scripts = [
  262. `https://g.alicdn.com/sd/ncpc/nc.js?t=${c}`,
  263. ];
  264. this.seriesLoadScripts(scripts, function () {
  265. var nc = new noCaptcha(NC_Opt);
  266. nc.upLang('cn', {
  267. _startTEXT: '请按住滑块,拖动到最右边',
  268. _yesTEXT: '验证通过',
  269. _error300: '哎呀,出错了,点击<a href="javascript:__nc.reset()">刷新</a>再来一次',
  270. _errorNetwork: '网络不给力,请<a href="javascript:__nc.reset()">点击刷新</a>',
  271. });
  272. });
  273. },
  274. }
  275. }
  276. </script>
  277. <style lang="scss" scoped>
  278. .verification {
  279. display: flex;
  280. justify-content: space-between;
  281. .dialog-code-btn {
  282. background: #00b96b;
  283. span {
  284. color : #fff !important;
  285. }
  286. }
  287. }
  288. .application-scheme-dialog .el-dialog__body {
  289. .dialog-code-btn {
  290. background: #00b96b;
  291. span {
  292. color : #fff !important;
  293. }
  294. }
  295. }
  296. .application-scheme-dialog .el-dialog__body .application-scheme-btn {
  297. background: #00b96b;
  298. color: #fff;
  299. }
  300. </style>