爱简收旧衣按件回收前端代码仓库
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.

385 lines
9.3 KiB

2 months ago
1 month ago
1 month ago
2 months ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
3 weeks ago
1 month ago
1 month ago
2 months ago
2 months ago
1 month ago
1 month ago
1 month ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month 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. this.handleAgreePrivacy()
  71. }
  72. this.getConfigData()
  73. },
  74. methods: {
  75. getConfigData() {
  76. this.$api('getConfig', {}, res => {
  77. // console.log('Config data response:', JSON.parse(JSON.stringify(res)) )
  78. if (res && res.success && Array.isArray(res.result)) {
  79. this.configData = res.result
  80. // console.log('Config data set:', JSON.parse(JSON.stringify(this.configData)) )
  81. }
  82. })
  83. },
  84. getConfigByKey(key) {
  85. const item = this.configData.find(i => i.keyName === key)
  86. return item ? item.keyContent : ''
  87. },
  88. handleLogin() {
  89. if (!this.agreed) {
  90. uni.showToast({
  91. title: '请阅读并勾选服务协议和隐私声明',
  92. icon: 'none'
  93. });
  94. return;
  95. }
  96. // this.$refs.privacyPopup.open()
  97. // uni.showLoading({
  98. // title: '登录中...'
  99. // });
  100. // setTimeout(() => {
  101. // uni.hideLoading();
  102. // uni.showToast({
  103. // title: '登录成功'
  104. // });
  105. // uni.reLaunch({
  106. // url: '/pages/index/index'
  107. // });
  108. // }, 1500);
  109. this.handleAgreePrivacy()
  110. },
  111. handleCancel() {
  112. // 关闭当前页面回到首页
  113. uni.reLaunch({
  114. url: '/pages/component/home'
  115. });
  116. },
  117. handleAgreementChange(e) {
  118. // console.log(this.agreed);
  119. // this.agreed = e.detail.value.length > 0;
  120. if (this.agreed) {
  121. this.agreed = false;
  122. } else {
  123. this.agreed = true;
  124. }
  125. },
  126. openProtocol(type) {
  127. console.log('Opening protocol:', type)
  128. console.log('Current configData:', this.configData)
  129. let protocol = null
  130. if (type === 'privacy') {
  131. protocol = this.configData.find(i => i.keyName === 'user_ys')
  132. } else if (type === 'service') {
  133. protocol = this.configData.find(i => i.keyName === 'user_xy')
  134. }
  135. console.log('Found protocol:', protocol)
  136. this.protocolDialogTitle = protocol ? protocol.keyValue : (type === 'privacy' ? '隐私政策' : '服务协议')
  137. this.protocolDialogContent = protocol && protocol.keyContent ? protocol.keyContent :
  138. (type === 'privacy' ?
  139. '<div style="padding: 20rpx;">暂无隐私政策内容</div>' :
  140. '<div style="padding: 20rpx;">暂无服务协议内容</div>')
  141. this.showProtocolDialog = true
  142. console.log('Dialog state:', {
  143. title: this.protocolDialogTitle,
  144. content: this.protocolDialogContent,
  145. show: this.showProtocolDialog
  146. })
  147. },
  148. goToAdminLogin() {
  149. uni.navigateTo({
  150. url: '/pages/component/admin_login'
  151. });
  152. },
  153. // 同意隐私政策
  154. handleAgreePrivacy() {
  155. uni.showLoading({
  156. title: '登录中...'
  157. })
  158. // 执行登录逻辑...
  159. let self = this
  160. wx.login({
  161. success(e) {
  162. // console.log(res.code,'code')
  163. if (e.code) {
  164. let data = {
  165. code: e.code
  166. }
  167. if (uni.getStorageSync('shareId')) {
  168. data.shareId = uni.getStorageSync('shareId')
  169. }
  170. self.$api('wxLogin', data, res => {
  171. console.log(res, 'login')
  172. if (res.code == 200) {
  173. uni.hideLoading();
  174. // console.log(res)
  175. uni.setStorageSync('token', res.result.token);
  176. uni.setStorageSync('userInfo', res.result.userInfo)
  177. uni.setStorageSync('openid', res.result.userInfo && res.result.userInfo
  178. .appletOpenid);
  179. getApp().globalData.login_status = true;
  180. if (res.result.userInfo) {
  181. const userInfo = res.result.userInfo;
  182. if (!userInfo.headImage || !userInfo.nickName) {
  183. uni.navigateTo({
  184. url: '/pages/wxUserInfo'
  185. });
  186. } else {
  187. uni.reLaunch({
  188. url: '/pages/component/home'
  189. });
  190. }
  191. } else {
  192. uni.navigateTo({
  193. url: '/pages/wxUserInfo'
  194. });
  195. }
  196. }
  197. })
  198. } else {
  199. uni.hideLoading();
  200. console.log('登录失败!' + res.errMsg)
  201. }
  202. }
  203. })
  204. },
  205. // 拒绝隐私政策
  206. handleRejectPrivacy() {
  207. uni.reLaunch({
  208. url: '/pages/component/home'
  209. });
  210. },
  211. // 打开协议页面
  212. openProtocolPage(type) {
  213. this.openProtocol(type)
  214. },
  215. handleProtocolAgree() {
  216. this.showProtocolDialog = false
  217. this.agreed = true
  218. // 你可以在这里添加同意后的其他逻辑
  219. },
  220. handleProtocolReject() {
  221. this.showProtocolDialog = false
  222. if (this.agreed) {
  223. this.agreed = false
  224. }
  225. // 你可以在这里添加拒绝后的其他逻辑
  226. }
  227. }
  228. }
  229. </script>
  230. <style scoped scss>
  231. view {
  232. padding-bottom: 0 !important;
  233. }
  234. .login-container {
  235. display: flex;
  236. flex-direction: column;
  237. height: 100vh;
  238. background-color: #f9ece5;
  239. padding: 0 40rpx;
  240. padding-bottom: env(safe-area-inset-bottom);
  241. }
  242. .app-header {
  243. margin-top: 320rpx;
  244. margin-bottom: 280rpx;
  245. text-align: center;
  246. }
  247. .app-title {
  248. display: flex;
  249. justify-content: center;
  250. align-items: center;
  251. font-family: Alimama ShuHeiTi;
  252. font-weight: 700;
  253. font-size: 28px;
  254. margin-top: 20rpx;
  255. }
  256. .app-subtitle {
  257. font-size: 28rpx;
  258. color: #fef6e3;
  259. margin-top: 1rem;
  260. letter-spacing: 0.11em;
  261. }
  262. .login-actions {
  263. /* height: 30%; */
  264. display: flex;
  265. flex-direction: column;
  266. align-items: center;
  267. justify-content: center;
  268. background-color: #f9ece5;
  269. border-radius: 30rpx;
  270. }
  271. .login-btn,
  272. .cancel-btn {
  273. width: 82%;
  274. height: 90rpx;
  275. line-height: 90rpx;
  276. border-radius: 45rpx;
  277. font-size: 32rpx;
  278. margin-bottom: 20rpx;
  279. border: none;
  280. }
  281. .login-btn {
  282. background-color: #f79400;
  283. color: white;
  284. }
  285. .cancel-btn {
  286. background-color: rgba(255, 253, 249);
  287. color: #f7990c;
  288. background-color: #f9ece5;
  289. border: 1px solid rgba(249, 178, 71);
  290. }
  291. .agreement {
  292. /* margin-top: 40rpx; */
  293. font-size: 24rpx;
  294. color: #333;
  295. display: flex;
  296. justify-content: center;
  297. }
  298. .radio-group {
  299. display: flex;
  300. align-items: center;
  301. }
  302. /* 自定义圆形checkbox样式 */
  303. .custom-radio {
  304. /* border-radius: 50%; */
  305. width: 32rpx;
  306. height: 32rpx;
  307. transform: scale(0.7);
  308. margin-right: 8rpx;
  309. }
  310. /* 覆盖uniapp默认checkbox样式 */
  311. .custom-radio .wx-checkbox-input,
  312. .custom-radio .uni-checkbox-input {
  313. border-radius: 50% !important;
  314. width: 32rpx !important;
  315. height: 32rpx !important;
  316. }
  317. .custom-radio .wx-checkbox-input.wx-checkbox-input-checked,
  318. .custom-radio .uni-checkbox-input.uni-checkbox-input-checked {
  319. background-color: #07C160 !important;
  320. border-color: #07C160 !important;
  321. color: #ffffff !important;
  322. }
  323. /* .radio-label {
  324. display: flex;
  325. align-items: center;
  326. } */
  327. .agreement-text {
  328. margin: 0 4rpx;
  329. }
  330. .protocol-link {
  331. color: #fabe65;
  332. }
  333. .admin-login {
  334. text-align: center;
  335. color: #fffffe;
  336. font-size: 28rpx;
  337. letter-spacing: 0.15em;
  338. }
  339. </style>