registerDialog.vue 11 KB

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