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

365 lines
8.7 KiB

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