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

368 lines
8.8 KiB

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