uni-id-pages-agreements.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <template>
  2. <view class="root" v-if="agreements.length">
  3. <template v-if="needAgreements">
  4. <checkbox-group @change="setAgree">
  5. <label class="checkbox-box">
  6. <checkbox :checked="isAgree" style="transform: scale(0.5);margin-right: -6px;" />
  7. <text class="text">同意</text>
  8. </label>
  9. </checkbox-group>
  10. <view class="content">
  11. <view class="item" v-for="(agreement,index) in agreements" :key="index">
  12. <text class="agreement text" @click="navigateTo(agreement)">{{agreement.title}}</text>
  13. <text class="text and" v-if="hasAnd(agreements,index)" space="nbsp"> 和 </text>
  14. </view>
  15. </view>
  16. </template>
  17. <!-- 弹出式 -->
  18. <uni-popup v-if="needAgreements||needPopupAgreements" ref="popupAgreement" type="center">
  19. <uni-popup-dialog confirmText="同意" @confirm="popupConfirm">
  20. <view class="content">
  21. <text class="text">请先阅读并同意</text>
  22. <view class="item" v-for="(agreement,index) in agreements" :key="index">
  23. <text class="agreement text" @click="navigateTo(agreement)">{{agreement.title}}</text>
  24. <text class="text and" v-if="hasAnd(agreements,index)" space="nbsp"> 和 </text>
  25. </view>
  26. </view>
  27. </uni-popup-dialog>
  28. </uni-popup>
  29. </view>
  30. </template>
  31. <script>
  32. import config from '@/uni_modules/uni-id-pages/config.js'
  33. let retryFun = ()=>console.log('为定义')
  34. /**
  35. * uni-id-pages-agreements
  36. * @description 用户服务协议和隐私政策条款组件
  37. * @property {String,Boolean} scope = [register|login] 作用于哪种场景如:register 注册(包括登录并注册,如:微信登录、苹果登录、短信验证码登录)、login 登录。默认值为:register
  38. */
  39. export default {
  40. name: "uni-agreements",
  41. computed: {
  42. agreements() {
  43. if(!config.agreements){
  44. return []
  45. }
  46. let {serviceUrl,privacyUrl} = config.agreements
  47. return [
  48. {
  49. url:serviceUrl,
  50. title:"用户服务协议"
  51. },
  52. {
  53. url:privacyUrl,
  54. title:"隐私政策条款"
  55. }
  56. ]
  57. }
  58. },
  59. props: {
  60. scope: {
  61. type: String,
  62. default(){
  63. return 'register'
  64. }
  65. },
  66. },
  67. methods: {
  68. popupConfirm(){
  69. console.log("popupConfirm");
  70. this.isAgree = true
  71. retryFun()
  72. // this.$emit('popupConfirm')
  73. },
  74. popup(Fun){
  75. this.needPopupAgreements = true
  76. // this.needAgreements = true
  77. this.$nextTick(()=>{
  78. if(Fun){
  79. retryFun = Fun
  80. }
  81. this.$refs.popupAgreement.open()
  82. })
  83. },
  84. navigateTo({
  85. url,
  86. title
  87. }) {
  88. uni.navigateTo({
  89. url: '/uni_modules/uni-id-pages/pages/common/webview/webview?url=' + url + '&title=' + title,
  90. success: res => {},
  91. fail: () => {},
  92. complete: () => {}
  93. });
  94. },
  95. hasAnd(agreements, index) {
  96. return agreements.length - 1 > index
  97. },
  98. setAgree(e) {
  99. this.isAgree = !this.isAgree
  100. this.$emit('setAgree', this.isAgree)
  101. }
  102. },
  103. created() {
  104. this.needAgreements = (config?.agreements?.scope || []).includes(this.scope)
  105. },
  106. data() {
  107. return {
  108. isAgree: false,
  109. needAgreements:true,
  110. needPopupAgreements:false
  111. };
  112. }
  113. }
  114. </script>
  115. <style lang="scss" scoped>
  116. /* #ifndef APP-NVUE */
  117. view {
  118. display: flex;
  119. box-sizing: border-box;
  120. flex-direction: column;
  121. }
  122. /* #endif */
  123. .root {
  124. flex-direction: row;
  125. align-items: center;
  126. font-size: 12px;
  127. color: #8a8f8b;
  128. }
  129. .checkbox-box ,.uni-label-pointer{
  130. align-items: center;
  131. display: flex;
  132. flex-direction: row;
  133. }
  134. .item {
  135. flex-direction: row;
  136. }
  137. .text{
  138. line-height: 26px;
  139. }
  140. .agreement {
  141. color: #04498c;
  142. cursor: pointer;
  143. }
  144. .checkbox-box ::v-deep .uni-checkbox-input{
  145. border-radius: 100%;
  146. }
  147. .checkbox-box ::v-deep .uni-checkbox-input.uni-checkbox-input-checked{
  148. border-color: $uni-color-primary;
  149. color: #FFFFFF !important;
  150. background-color: $uni-color-primary;
  151. }
  152. .content{
  153. flex-wrap: wrap;
  154. flex-direction: row;
  155. }
  156. .root ::v-deep .uni-popup__error{
  157. color: #333333;
  158. }
  159. </style>