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

369 lines
8.8 KiB

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