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

374 lines
9.1 KiB

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