爱简收旧衣按件回收前端代码仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

382 lines
9.2 KiB

2 months ago
4 weeks ago
4 weeks ago
2 months ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
2 months ago
1 month ago
4 weeks ago
4 weeks ago
4 weeks ago
4 weeks ago
2 months ago
4 weeks ago
2 months ago
4 weeks ago
2 months ago
4 weeks ago
2 months ago
  1. <template>
  2. <view class="login-container">
  3. <!-- 应用标题和副标题 -->
  4. <view class="app-header">
  5. <image :src="logoImage"
  6. mode="aspectFill"
  7. style="width: 170rpx; height: 170rpx; display: block; margin: 0 auto;" />
  8. <view class="app-title">{{ logoName }}</view>
  9. <!-- <view class="app-subtitle">旧物很有用·回收很简单</view> -->
  10. </view>
  11. <!-- 登录操作区域 -->
  12. <view class="login-actions">
  13. <button class="login-btn" @click="handleLogin">登录</button>
  14. <button class="cancel-btn" @click="handleCancel">取消登录</button>
  15. <view class="agreement">
  16. <checkbox-group @change="handleAgreementChange" class="radio-group">
  17. <label class="radio-label">
  18. <checkbox :checked="agreed" color="#fdbd3e" class="custom-radio" />
  19. <text class="agreement-text">我已阅读并同意</text>
  20. <text class="protocol-link" @click.stop="openProtocol('service')">服务协议</text>
  21. <text class="agreement-text"></text>
  22. <text class="protocol-link" @click.stop="openProtocol('privacy')">隐私政策</text>
  23. </label>
  24. </checkbox-group>
  25. </view>
  26. </view>
  27. <!-- <uv-divider :dashed = "true"></uv-divider> -->
  28. <!-- <view class="admin-login" @click="goToAdminLogin">管理员登录</view> -->
  29. <PrivacyPopup ref="privacyPopup" :needPhone="needPhone" :appName="logoName" @agree="handleAgreePrivacy"
  30. @reject="handleRejectPrivacy" @open-protocol="openProtocol" />
  31. <ProtocolDialog ref="protocolDialog" :show="showProtocolDialog" :title="protocolDialogTitle"
  32. :content="protocolDialogContent" @close="showProtocolDialog = false" @agree="handleProtocolAgree"
  33. @reject="handleProtocolReject" />
  34. </view>
  35. </template>
  36. <script>
  37. import PrivacyPopup from '@/wxcomponents/privacy-popup/privacy-popup.vue'
  38. import ProtocolDialog from '@/wxcomponents/protocol-dialog/protocol-dialog.vue'
  39. // import {banner} from '@/api.uts'
  40. export default {
  41. components: {
  42. PrivacyPopup,
  43. ProtocolDialog
  44. },
  45. data() {
  46. return {
  47. agreed: false,
  48. showProtocolDialog: false,
  49. protocolDialogTitle: '',
  50. protocolDialogContent: '',
  51. configData: [], // 存储 getConfig 返回的 result
  52. needPhone: false // 控制是否需要手机号授权
  53. }
  54. },
  55. computed: {
  56. logoImage() {
  57. const item = this.configData.find(i => i.keyName === 'logo_image')
  58. uni.setStorageSync('logoImage', item ? item.keyContent : '')
  59. return item ? item.keyContent : ''
  60. },
  61. logoName() {
  62. const item = this.configData.find(i => i.keyName === 'logo_name')
  63. uni.setStorageSync('logoName', item ? item.keyContent : '')
  64. return item ? item.keyContent : ''
  65. }
  66. },
  67. onLoad(query) {
  68. if (query.shareId) {
  69. uni.setStorageSync('shareId', query.shareId)
  70. }
  71. this.getConfigData()
  72. },
  73. methods: {
  74. getConfigData() {
  75. this.$api('getConfig', {}, res => {
  76. // console.log('Config data response:', JSON.parse(JSON.stringify(res)) )
  77. if (res && res.success && Array.isArray(res.result)) {
  78. this.configData = res.result
  79. // console.log('Config data set:', JSON.parse(JSON.stringify(this.configData)) )
  80. }
  81. })
  82. },
  83. getConfigByKey(key) {
  84. const item = this.configData.find(i => i.keyName === key)
  85. return item ? item.keyContent : ''
  86. },
  87. handleLogin() {
  88. if (!this.agreed) {
  89. uni.showToast({
  90. title: '请阅读并勾选服务协议和隐私声明',
  91. icon: 'none'
  92. });
  93. return;
  94. }
  95. // this.$refs.privacyPopup.open()
  96. // uni.showLoading({
  97. // title: '登录中...'
  98. // });
  99. // setTimeout(() => {
  100. // uni.hideLoading();
  101. // uni.showToast({
  102. // title: '登录成功'
  103. // });
  104. // uni.reLaunch({
  105. // url: '/pages/index/index'
  106. // });
  107. // }, 1500);
  108. this.handleAgreePrivacy()
  109. },
  110. handleCancel() {
  111. // 关闭当前页面回到首页
  112. uni.reLaunch({
  113. url: '/pages/component/home'
  114. });
  115. },
  116. handleAgreementChange(e) {
  117. // console.log(this.agreed);
  118. // this.agreed = e.detail.value.length > 0;
  119. if (this.agreed) {
  120. this.agreed = false;
  121. } else {
  122. this.agreed = true;
  123. }
  124. },
  125. openProtocol(type) {
  126. console.log('Opening protocol:', type)
  127. console.log('Current configData:', this.configData)
  128. let protocol = null
  129. if (type === 'privacy') {
  130. protocol = this.configData.find(i => i.keyName === 'user_ys')
  131. } else if (type === 'service') {
  132. protocol = this.configData.find(i => i.keyName === 'user_xy')
  133. }
  134. console.log('Found protocol:', protocol)
  135. this.protocolDialogTitle = protocol ? protocol.keyValue : (type === 'privacy' ? '隐私政策' : '服务协议')
  136. this.protocolDialogContent = protocol && protocol.keyContent ? protocol.keyContent :
  137. (type === 'privacy' ?
  138. '<div style="padding: 20rpx;">暂无隐私政策内容</div>' :
  139. '<div style="padding: 20rpx;">暂无服务协议内容</div>')
  140. this.showProtocolDialog = true
  141. console.log('Dialog state:', {
  142. title: this.protocolDialogTitle,
  143. content: this.protocolDialogContent,
  144. show: this.showProtocolDialog
  145. })
  146. },
  147. goToAdminLogin() {
  148. uni.navigateTo({
  149. url: '/pages/component/admin_login'
  150. });
  151. },
  152. // 同意隐私政策
  153. handleAgreePrivacy() {
  154. uni.showLoading({
  155. title: '登录中...'
  156. })
  157. // 执行登录逻辑...
  158. let self = this
  159. let data = {
  160. code: res.code
  161. }
  162. if (uni.getStorageSync('shareId')) {
  163. data.shareId = uni.getStorageSync('shareId')
  164. }
  165. wx.login({
  166. success(res) {
  167. // console.log(res.code,'code')
  168. if (res.code) {
  169. self.$api('wxLogin', data, res => {
  170. console.log(res, 'login')
  171. if (res.code == 200) {
  172. uni.hideLoading();
  173. // console.log(res)
  174. uni.setStorageSync('token', res.result.token);
  175. uni.setStorageSync('userInfo', res.result.userInfo)
  176. uni.setStorageSync('openid', res.result.userInfo && res.result.userInfo
  177. .appletOpenid);
  178. getApp().globalData.login_status = true;
  179. if (res.result.userInfo) {
  180. const userInfo = res.result.userInfo;
  181. if (!userInfo.headImage || !userInfo.nickName) {
  182. uni.navigateTo({
  183. url: '/pages/wxUserInfo'
  184. });
  185. } else {
  186. uni.reLaunch({
  187. url: '/pages/component/home'
  188. });
  189. }
  190. } else {
  191. uni.navigateTo({
  192. url: '/pages/wxUserInfo'
  193. });
  194. }
  195. }
  196. })
  197. } else {
  198. uni.hideLoading();
  199. console.log('登录失败!' + res.errMsg)
  200. }
  201. }
  202. })
  203. },
  204. // 拒绝隐私政策
  205. handleRejectPrivacy() {
  206. uni.reLaunch({
  207. url: '/pages/component/home'
  208. });
  209. },
  210. // 打开协议页面
  211. openProtocolPage(type) {
  212. this.openProtocol(type)
  213. },
  214. handleProtocolAgree() {
  215. this.showProtocolDialog = false
  216. this.agreed = true
  217. // 你可以在这里添加同意后的其他逻辑
  218. },
  219. handleProtocolReject() {
  220. this.showProtocolDialog = false
  221. if (this.agreed) {
  222. this.agreed = false
  223. }
  224. // 你可以在这里添加拒绝后的其他逻辑
  225. }
  226. }
  227. }
  228. </script>
  229. <style scoped scss>
  230. view {
  231. padding-bottom: 0 !important;
  232. }
  233. .login-container {
  234. display: flex;
  235. flex-direction: column;
  236. height: 100vh;
  237. background-color: #f9ece5;
  238. padding: 0 40rpx;
  239. padding-bottom: env(safe-area-inset-bottom);
  240. }
  241. .app-header {
  242. margin-top: 320rpx;
  243. margin-bottom: 280rpx;
  244. text-align: center;
  245. }
  246. .app-title {
  247. display: flex;
  248. justify-content: center;
  249. align-items: center;
  250. font-family: Alimama ShuHeiTi;
  251. font-weight: 700;
  252. font-size: 28px;
  253. margin-top: 20rpx;
  254. }
  255. .app-subtitle {
  256. font-size: 28rpx;
  257. color: #fef6e3;
  258. margin-top: 1rem;
  259. letter-spacing: 0.11em;
  260. }
  261. .login-actions {
  262. /* height: 30%; */
  263. display: flex;
  264. flex-direction: column;
  265. align-items: center;
  266. justify-content: center;
  267. background-color: #f9ece5;
  268. border-radius: 30rpx;
  269. }
  270. .login-btn,
  271. .cancel-btn {
  272. width: 82%;
  273. height: 90rpx;
  274. line-height: 90rpx;
  275. border-radius: 45rpx;
  276. font-size: 32rpx;
  277. margin-bottom: 20rpx;
  278. border: none;
  279. }
  280. .login-btn {
  281. background-color: #f79400;
  282. color: white;
  283. }
  284. .cancel-btn {
  285. background-color: rgba(255, 253, 249);
  286. color: #f7990c;
  287. background-color: #f9ece5;
  288. border: 1px solid rgba(249, 178, 71);
  289. }
  290. .agreement {
  291. /* margin-top: 40rpx; */
  292. font-size: 24rpx;
  293. color: #333;
  294. display: flex;
  295. justify-content: center;
  296. }
  297. .radio-group {
  298. display: flex;
  299. align-items: center;
  300. }
  301. /* 自定义圆形checkbox样式 */
  302. .custom-radio {
  303. /* border-radius: 50%; */
  304. width: 32rpx;
  305. height: 32rpx;
  306. transform: scale(0.7);
  307. margin-right: 8rpx;
  308. }
  309. /* 覆盖uniapp默认checkbox样式 */
  310. .custom-radio .wx-checkbox-input,
  311. .custom-radio .uni-checkbox-input {
  312. border-radius: 50% !important;
  313. width: 32rpx !important;
  314. height: 32rpx !important;
  315. }
  316. .custom-radio .wx-checkbox-input.wx-checkbox-input-checked,
  317. .custom-radio .uni-checkbox-input.uni-checkbox-input-checked {
  318. background-color: #07C160 !important;
  319. border-color: #07C160 !important;
  320. color: #ffffff !important;
  321. }
  322. /* .radio-label {
  323. display: flex;
  324. align-items: center;
  325. } */
  326. .agreement-text {
  327. margin: 0 4rpx;
  328. }
  329. .protocol-link {
  330. color: #fabe65;
  331. }
  332. .admin-login {
  333. text-align: center;
  334. color: #fffffe;
  335. font-size: 28rpx;
  336. letter-spacing: 0.15em;
  337. }
  338. </style>