reg.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. <template>
  2. <view class="page">
  3. <view class="header">
  4. <view class="left">
  5. <!-- <image class="img" mode="widthFix" src="../../static/login/close.png"></image> -->
  6. </view>
  7. </view>
  8. <view class="tbody">
  9. <view>
  10. <image class="img" mode="widthFix" src="../../static/logo.png"></image>
  11. </view>
  12. <!-- <view class="name">昵称:</view>
  13. <view class="item">
  14. <input type="text" class="input" v-model="nickname" maxlength="30" placeholder="请输入您的昵称" />
  15. </view> -->
  16. <view class="name">手机号码:</view>
  17. <view class="item">
  18. <input type="text" class="input" v-model="mobile" maxlength="11" placeholder="请输入手机号码" />
  19. </view>
  20. <view class="name">验证码:</view>
  21. <view class="item">
  22. <input type="text" class="input" v-model="code" maxlength="6" placeholder="请输入验证码" />
  23. <view class="btn" v-if="captchaTime === 0" @click="getCode">获取验证码</view>
  24. <view class="btn" v-if="captchaTime > 0">{{captchaTime}}秒后重试</view>
  25. </view>
  26. <view class="name">登录密码:</view>
  27. <view class="item">
  28. <input type="password" class="input" v-model="password" maxlength="50" placeholder="请输入登录密码" />
  29. </view>
  30. <view class="name">确认密码:</view>
  31. <view class="item">
  32. <input type="password" class="input" v-model="password2" maxlength="50" placeholder="请再次输入登录密码" />
  33. </view>
  34. <view class="other_list">
  35. <text class="left" v-if="false">忘记密码</text>
  36. <text class="left" v-else></text>
  37. <text class="right" @click="goPage('/pages/login/login')">已有账号?去登录</text>
  38. </view>
  39. <view class="agree">
  40. <view class="agree2" @click="agreeChk()">
  41. <image mode="widthFix" src="../../static/login/sel_no.png" v-if="is_agree == 0"></image>
  42. <image mode="widthFix" src="../../static/login/sel_yes.png" v-if="is_agree == 1"></image>
  43. <text>我已阅读并同意</text>
  44. </view>
  45. <text class="xy" @click="goPage('yhxy')">
  46. 隐私协议
  47. </text>
  48. 》和《
  49. <text class="xy" @click="goPage('yszc')">
  50. 用户使用协议
  51. </text>
  52. </view>
  53. <text class="btn_submit" @click="toReg">注册</text>
  54. </view>
  55. <view class="blankHeight"></view>
  56. <!-- 提示框 -->
  57. <DialogBox ref="DialogBox"></DialogBox>
  58. </view>
  59. </template>
  60. <script>
  61. import pubc from '@/common/public.js'
  62. export default {
  63. components: {},
  64. data() {
  65. return {
  66. title: '',
  67. sel: 1,
  68. is_agree: 0,
  69. mobile: '',
  70. password: '',
  71. password2: '',
  72. code: '',
  73. ycode: '',
  74. nickname: '',
  75. captchaTime: 0,
  76. is_web3: 0,
  77. push_token: '',
  78. lat: '',
  79. lng: '',
  80. }
  81. },
  82. onLoad(params) {
  83. this.ycode = params.ycode || '111111';
  84. this.is_web3 = this.$isWeb3;
  85. setTimeout(function() {
  86. uni.setNavigationBarColor({
  87. frontColor: '#ffffff',
  88. backgroundColor: '#00000000',
  89. animation: {
  90. duration: 400,
  91. timingFunc: 'easeIn'
  92. }
  93. })
  94. }, 200);
  95. let that = this;
  96. // #ifdef APP-PLUS
  97. // 尝试使用全局存储的推送token
  98. if (getApp().globalData.push_token) {
  99. that.push_token = getApp().globalData.push_token;
  100. console.log("使用全局推送token:", that.push_token);
  101. } else {
  102. // 这里不再主动获取,依赖App.vue中的获取结果
  103. // 避免重复调用可能导致的问题
  104. console.log("等待全局推送token初始化");
  105. // 开发环境可以设置一个默认值,避免接口报错
  106. that.push_token = '';
  107. }
  108. // #endif
  109. },
  110. onShow() {
  111. let that = this;
  112. // #ifdef APP-PLUS
  113. // uni.getLocation({
  114. // type: 'wgs84',
  115. // success: function(res) {
  116. // that.lat = res.latitude;
  117. // that.lng = res.longitude;
  118. // },
  119. // fail: function(error) {
  120. // console.error('获取位置失败:', error);
  121. // }
  122. // });
  123. // #endif
  124. },
  125. methods: {
  126. onBack() {},
  127. agreeChk() {
  128. if (this.is_agree == 0) {
  129. this.is_agree = 1;
  130. } else {
  131. this.is_agree = 0;
  132. }
  133. },
  134. getCodeTime() {
  135. this.captchaTime = 60;
  136. let timer = setInterval(() => {
  137. this.captchaTime--;
  138. // console.log(this.captchaTime)
  139. if (this.captchaTime < 1) {
  140. clearInterval(timer);
  141. this.captchaTime = 0
  142. }
  143. }, 1000)
  144. },
  145. getCode() {
  146. if (this.mobile.length != 11) {
  147. uni.showToast({
  148. title: '请输入手机号',
  149. icon: 'none'
  150. });
  151. return;
  152. }
  153. if (this.captchaTime > 0) {
  154. uni.showToast({
  155. title: '不能重复获取',
  156. icon: 'none'
  157. });
  158. return;
  159. }
  160. this.captchaTime = 60;
  161. uni.request({
  162. url: this.$apiHost + '/Web/getcode', //仅为示例,并非真实接口地址。
  163. data: {
  164. skey: this.skey,
  165. mobile: this.mobile,
  166. },
  167. header: {
  168. 'content-type': 'application/json' //自定义请求头信息
  169. },
  170. success: (res) => {
  171. console.log("----", res.data)
  172. uni.showToast({
  173. title: res.data.str,
  174. icon: 'none'
  175. })
  176. if (res.data.success == 'yes') {
  177. this.getCodeTime();
  178. } else {
  179. this.captchaTime = 0;
  180. }
  181. }
  182. });
  183. },
  184. goPage(page) {
  185. if (page == 'yhxy') {
  186. uni.navigateTo({
  187. url: '/pages/AboutUs/yhxy'
  188. })
  189. } else if (page == 'yszc') {
  190. // #ifdef APP-PLUS
  191. plus.runtime.openWeb('https://e.zhichao.art/web/yszc.php') // plus.runtime.openWeb(href);
  192. // #endif
  193. // #ifdef H5
  194. window.open('https://e.zhichao.art/web/yszc.php')
  195. // #endif
  196. // uni.navigateTo({
  197. // url: '/pages/AboutUs/yszc'
  198. // })
  199. } else {
  200. uni.navigateTo({
  201. url: page,
  202. });
  203. }
  204. },
  205. toReg() {
  206. if (this.is_agree == 0) {
  207. uni.showToast({
  208. title: "请确认并选择协议",
  209. icon: "none",
  210. });
  211. return;
  212. }
  213. if (this.mobile.length != 11) {
  214. uni.showToast({
  215. title: "请输入手机号",
  216. icon: "none",
  217. });
  218. return;
  219. }
  220. if (this.password.length < 6) {
  221. uni.showToast({
  222. title: "请输入不小于6位的密码",
  223. icon: "none",
  224. });
  225. return;
  226. }
  227. if (this.password != this.password2) {
  228. uni.showToast({
  229. title: "两次输入密码不一致",
  230. icon: "none",
  231. });
  232. return;
  233. }
  234. if (this.code.length < 4) {
  235. uni.showToast({
  236. title: "请输入手机验证码",
  237. icon: "none",
  238. });
  239. return;
  240. }
  241. let method = '/Web/reg';
  242. uni.showLoading({
  243. mask: true,
  244. });
  245. console.log("host", this.$apiHost + method);
  246. // 添加容错处理,如果推送token为空,用随机字符串代替
  247. const pushToken = this.push_token || ('dev_' + new Date().getTime());
  248. uni.request({
  249. url: this.$apiHost + method, //仅为示例,并非真实接口地址。
  250. data: {
  251. uuid: getApp().globalData.uuid,
  252. // nickname: this.nickname,
  253. mobile: this.mobile,
  254. password: this.password,
  255. ycode: this.ycode,
  256. code: this.code,
  257. is_web3: this.is_web3,
  258. push_token: pushToken,
  259. lat: this.lat,
  260. lng: this.lng,
  261. },
  262. header: {
  263. "content-type": "application/json"
  264. },
  265. success: (res) => {
  266. console.log("----", res.data);
  267. if (res.data.success == "yes") {
  268. if (res.data.uuid.length > 5) {
  269. uni.setStorageSync("app_uuid", res.data.uuid);
  270. getApp().globalData.uuid = res.data.uuid;
  271. }
  272. // #ifdef APP-PLUS
  273. uni.setStorageSync("wapptoken", res.data.skey);
  274. getApp().globalData.skey = res.data.skey;
  275. if (res.data.header_c != "") {
  276. getApp().globalData.headerSign = pubc.Encrypt(res.data.header_c + "_" +
  277. getApp().globalData.uuid);
  278. uni.setStorageSync("headerSign", getApp().globalData.headerSign);
  279. }
  280. getApp().globalData.headerC = res.data.header_c;
  281. uni.redirectTo({
  282. url: '/pages/my/step'
  283. });
  284. // uni.switchTab({
  285. // url: "/pages/index/index",
  286. // });
  287. // #endif
  288. // #ifdef H5
  289. uni.showToast({
  290. title: res.data.str,
  291. icon: "none",
  292. });
  293. setTimeout(function() {
  294. uni.navigateTo({
  295. url: '/pages/login/down'
  296. })
  297. }, 1000);
  298. // #endif
  299. // setTimeout(function() {}, 1500);
  300. // console.log("res.data", res.data);
  301. // uni.setStorageSync("wapptoken", res.data.skey);
  302. // getApp().globalData.skey = res.data.skey;
  303. // uni.switchTab({
  304. // url: "/pages/index/home",
  305. // });
  306. } else if (res.data.success == "no") {
  307. uni.showToast({
  308. title: res.data.str,
  309. icon: "none",
  310. });
  311. } else {
  312. uni.showToast({
  313. title: "操作失败,请联系客服",
  314. icon: "none",
  315. });
  316. }
  317. },
  318. complete: (com) => {
  319. uni.hideLoading();
  320. },
  321. });
  322. },
  323. }
  324. }
  325. </script>
  326. <style scoped lang="scss">
  327. @import 'reg.scss';
  328. </style>