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

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