jufubao-third 1.0.0-beta1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,261 @@
1
+ 'use strict';
2
+
3
+ //#ifdef H5
4
+ import cookie from "@/common/cookie";
5
+ //#endif
6
+ import storage from "@/common/storage";
7
+ const settings = require('./../../settings');
8
+ import Vue from 'vue';
9
+ let __jfbAuthorize = null;
10
+ import store from "@/store";
11
+
12
+ class JfbAuthorize {
13
+ /**
14
+ * @description 构造函数
15
+ * @param options {Object}
16
+ * @param options.siteId {String} 网站ID 【必填】
17
+ * @param options.xSite {String} 网站XID 【必填】
18
+ * @param options.cardPath {String} 购物登录地址 【选填】
19
+ * @param options.LoginPath {String} 用户登录地址 【选填】
20
+ */
21
+ constructor(options){
22
+ this.siteId = options.siteId;
23
+ this.xSite = options.xSite;
24
+ this.cardPath = options.cardPath;
25
+ this.LoginPath = options.LoginPath;
26
+
27
+ this.config = Object.assign({},{
28
+ 'user': 'JFB-CSRF-TOKEN-{siteID}',
29
+ 'card': 'JFB-CARD-TOKEN-{siteID}',
30
+ 'refresh': 'JFB-REFRESH-TOKEN-{siteID}',
31
+ 'access': 'JFB-ACCESS-TOKEN',
32
+ }, settings.token? settings.token: {});
33
+ }
34
+
35
+
36
+
37
+ /**
38
+ * @description 获取token键值
39
+ * @param key {String} {String} 设置cookie/storage键值,其值:card|user|refresh|access, 默认:user,【选填】
40
+ * @returns {string|*}
41
+ */
42
+ getTokenKeyword(key){
43
+ if (!this.config[key]) key = 'user';
44
+ if(key === 'access') return this.config.access;
45
+ else{
46
+ return `${this.config[key].replace("{siteID}", this.siteId)}`;
47
+ }
48
+ }
49
+
50
+ /**
51
+ * @description 获取request中token键值
52
+ * @param key {String} {String} 设置cookie/storage键值,其值:card|user|refresh|access, 默认:user,【选填】
53
+ * @returns {string|*}
54
+ */
55
+ getRequestTokenKey(key) {
56
+ if (!this.config[key]) key = 'user';
57
+ if (key === 'access') return this.config.access;
58
+ else {
59
+ return `${this.config[key].replace("-{siteID}", '')}`;
60
+ }
61
+ }
62
+
63
+ /**
64
+ * @description 设置token
65
+ * @param key {String} 设置cookie/storage键值,其值:card|user|refresh|access, 默认:user,【选填】
66
+ * @param value {*} 设置cookie/storage的值 【必填】
67
+ * @param options {Object} 可选项,{expires: 1, domain: ''}, 【选填】
68
+ * @param options.expires {Number} 过期时间单位:小时
69
+ * @param options.domain {String} 生效域名
70
+ */
71
+ setToken(key, value, options = {}) {
72
+ key = this.getTokenKeyword(key);
73
+ //#ifdef H5
74
+ cookie.set(key, value, options);
75
+ //#endif
76
+ storage.set(key, value, options.expires ? options.expires : 0)
77
+ }
78
+
79
+ /**
80
+ * @description 删除操作token
81
+ * @param key {String} 设置cookie/storage键值,其值:card|user|refresh|access, 默认:user
82
+ * @param options {Object} 可选项,{expires: 1, domain: ''}, 过期时间单位:小时
83
+ */
84
+ removeToken(key, options = {}) {
85
+ key = this.getTokenKeyword(key);
86
+ //#ifdef H5
87
+ cookie.remove(key, options);
88
+ console.warn(`cookie.key=${key}`);
89
+ //#endif
90
+ console.warn(`storage.key=${key}`);
91
+ storage.remove(key);
92
+ }
93
+
94
+ /**
95
+ * @description 获取token信息
96
+ * @param key {String} 设置cookie/storage键值,其值:card|user|refresh|access, 默认:user
97
+ * @param options {Object} 可选项,{expires: 1, domain: ''}, 【选填】
98
+ * @param options.expires {Number} 过期时间单位:小时
99
+ * @param options.domain {String} 生效域名
100
+ * @return {null|String}
101
+ */
102
+ getToken(key, options = {}) {
103
+ let tokenKey = this.getTokenKeyword(key);
104
+ let token = null;
105
+ if (storage.get(tokenKey)) token = storage.get(tokenKey);
106
+ //#ifdef H5
107
+ if (cookie.get(tokenKey, options)) token = cookie.get(tokenKey, options)
108
+ //#endif
109
+ return token
110
+ }
111
+
112
+ /**
113
+ * @description h5中获取base
114
+ * @param $vm {Vue}
115
+ */
116
+ getBasePath($vm){
117
+ let base = '';
118
+ //#ifdef H5
119
+ base = $vm.$router.history.base;
120
+ //#endif
121
+ return base;
122
+ }
123
+
124
+ /**
125
+ * @description 跳转到卡登陆页面
126
+ * @param $vm {Vue}
127
+ */
128
+ jumpToCardLogin($vm){
129
+ let redirect_url = '';
130
+ if (store.state.configProject.platform === 'mp.weixin') {
131
+ redirect_url = $vm['$xdUniHelper'].parseURL().source;
132
+ }
133
+ if (store.state.configProject.platform === 'h5') {
134
+ redirect_url = $vm.$route.fullPath;
135
+ }
136
+ $vm['$xdUniHelper'].redirectTo({
137
+ url: this.cardPath + `?inCallback=${encodeURIComponent(redirect_url)}`,
138
+ });
139
+ }
140
+
141
+ /**
142
+ * @description 跳转到用户登陆页面
143
+ * @param $vm {Vue}
144
+ */
145
+ jumpToUserLogin($vm) {
146
+ let redirect_url = '';
147
+ if(store.state.configProject.platform === 'mp.weixin') {
148
+ redirect_url = $vm['$xdUniHelper'].parseURL().source;
149
+ }
150
+ if (store.state.configProject.platform === 'h5') {
151
+ redirect_url = $vm.$route.fullPath;
152
+ }
153
+ $vm['$xdUniHelper'].redirectTo({
154
+ url: this.LoginPath + `?redirect_url=${encodeURIComponent(redirect_url)}`,
155
+ });
156
+ }
157
+
158
+ /**
159
+ * @description 用户是否已登录卡信息
160
+ * @param canCard {Boolean} 检查是否用登录购物车信息 默认:false
161
+ * @param $vm {Vue}
162
+ * @param isAutoJump {Boolean} 是否自己跳转 默认值:true
163
+ * @return {boolean} true 已登陆或者免登 false 未登陆
164
+ */
165
+ checkCardLogin(canCard = false, $vm, isAutoJump=true){
166
+ if(!canCard) return true;
167
+ if (!this.getToken('card')) {
168
+ if(isAutoJump) {
169
+ this.jumpToCardLogin($vm);
170
+ }
171
+ return false;
172
+ }
173
+ return true;
174
+ }
175
+
176
+ /**
177
+ * @description 用户已登录信息
178
+ * @param canSign {Boolean} 检查是否用登录信息 默认:false
179
+ * @param $vm {Vue}
180
+ * @param isAutoJump {Boolean} 是否自己跳转 默认值:true
181
+ * @return {Promise} true: 已登陆或者未启用,false:未登陆或刷新token已过期获取(从新交换token)
182
+ */
183
+ checkUserLogin(canSign, $vm, isAutoJump=true) {
184
+ return new Promise((resolve, reject)=>{
185
+ //免登陆操作
186
+ if (!canSign) resolve(true);
187
+
188
+ //用户登陆判断
189
+ let userToken = this.getToken('user');
190
+ //用户刷新token
191
+ let refreshToken = this.getToken('refresh');
192
+
193
+ //用户未登陆
194
+ if(!userToken && !refreshToken) {
195
+ if (isAutoJump) {
196
+ this.jumpToUserLogin($vm);
197
+ }
198
+ resolve(false);
199
+ return
200
+ }
201
+
202
+ //去刷新token
203
+ if (!userToken) store.dispatch('userRefreshToken')
204
+ .then(res => {
205
+ resolve(true);
206
+ })
207
+ .catch(error=>{
208
+ if (isAutoJump) {
209
+ this.jumpToUserLogin($vm);
210
+ }
211
+ resolve(false);
212
+ });
213
+ else{
214
+ resolve(true);
215
+ }
216
+ });
217
+ }
218
+
219
+ /**
220
+ * @description 客户端设置所有token
221
+ * @param result
222
+ * @param cb {Function|null}
223
+ */
224
+ setAllToken(result,cb = null){
225
+ //#ifdef MP-WEIXIN
226
+ this.setToken('user', result['csrf_token'], {expires: result['csrf_token_expire_in']/60/60});
227
+ this.setToken('access', result['access_token'], {expires: result['access_token_expire_in'] / 60 / 60})
228
+ this.setToken('refresh', result['refresh_token'], {expires: result['refresh_token_expire_in'] / 60 / 60})
229
+ if(typeof cb === 'function') cb();
230
+ //#endif
231
+ }
232
+
233
+ /**
234
+ * @description 客户端删除所有token
235
+ * @param cb {Function|null}
236
+ */
237
+ removeAllToken(cb=null){
238
+ //#ifdef MP-WEIXIN
239
+ this.removeToken('user');
240
+ this.removeToken('access');
241
+ this.removeToken('refresh');
242
+ if (store.state.jfbAuthorize !== null) {
243
+ store.state.jfbAuthorize.setAllToken(res)
244
+ }
245
+ //#endif
246
+ }
247
+ }
248
+
249
+ /**
250
+ * @description 单利初始化用户授权函数
251
+ * @param options {Object}
252
+ * @param options.siteId {String} 网站ID 【必填】
253
+ * @param options.cardPath {String} 购物登录地址 【选填】
254
+ * @param options.LoginPath {String} 用户登录地址 【选填】
255
+ */
256
+ export default function (options) {
257
+ if(__jfbAuthorize !== null) return __jfbAuthorize;
258
+ return __jfbAuthorize = new JfbAuthorize(options);
259
+ }
260
+
261
+
@@ -0,0 +1,39 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * @description 字符串转数字
5
+ * @param str {String} 字符串
6
+ * @returns {number} 返回数字
7
+ */
8
+ function stringToNumber(str) {
9
+ let result = 0;
10
+ let len = str.length;
11
+ for (let i = 0; i < len; i++) {
12
+ result = result + str.charCodeAt(i) + i;
13
+ }
14
+ return result;
15
+ }
16
+
17
+
18
+ /**
19
+ * @description 全局获取图片全路径方法
20
+ * @param path
21
+ * @param size {String} 压缩比例,支持值:size1 - size8
22
+ * @returns {String}
23
+ */
24
+ function getBusinessImageUrl(path, size = 'size8') {
25
+ if (Object.prototype.toString.call(path)!== '[object String]' || path === '') {
26
+ console.error('传入的路径(path)非字符串类型,请确认路径是否正确');
27
+ //throw new Error('传入的路径(path)非字符串类型,请确认路径是否正确');
28
+ }
29
+
30
+ let reg = /^(http:\/\/|https:\/\/|\/\/)+.+$/;
31
+ if (reg.test(path)) return path;
32
+
33
+ let index = stringToNumber(path) % 6;
34
+ let doMain = '//sandbox-img@index@.jufubao.cn/'.replace('@index@', index === 0 ? '': index);
35
+ let src = 'business/';
36
+ return `${doMain}${src}${path}?x-oss-process=style/${size}`;
37
+ }
38
+
39
+ export default getBusinessImageUrl;
@@ -0,0 +1,38 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * @description 字符串转数字
5
+ * @param str {String} 字符串
6
+ * @returns {number} 返回数字
7
+ */
8
+ function stringToNumber(str) {
9
+ let result = 0;
10
+ let len = str.length;
11
+ for (let i = 0; i < len; i++) {
12
+ result = result + str.charCodeAt(i) + i;
13
+ }
14
+ return result;
15
+ }
16
+
17
+
18
+ /**
19
+ * @description 全局获取图片全路径方法
20
+ * @param path
21
+ * @param size {String} 压缩比例,支持值:size1 - size8
22
+ * @returns {String}
23
+ */
24
+ function getServiceUrl(path, size = 'size8') {
25
+ if (Object.prototype.toString.call(path) !== '[object String]' || path === '') {
26
+ console.error('传入的路径(path)非字符串类型,请确认路径是否正确');
27
+ throw new Error('传入的路径(path)非字符串类型,请确认路径是否正确');
28
+ }
29
+
30
+ let reg = /^(http:\/\/|https:\/\/|\/\/)+.+$/;
31
+ if (reg.test(path)) return path;
32
+
33
+ let index = stringToNumber(path) % 6;
34
+ let doMain = '//sandbox-img@index@.jufubao.cn/'.replace('@index@', index === 0 ? '' : index);
35
+ return `${doMain}${path}?x-oss-process=style/${size}`;
36
+ }
37
+
38
+ export default getServiceUrl;
@@ -0,0 +1,98 @@
1
+ 'use strict';
2
+
3
+ import jwxSDK from "jweixin-module"
4
+ import {envTypeReg} from "@/common/host";
5
+
6
+ class InitWxAuthorize {
7
+ constructor(setting = {} , jsApiList){
8
+ this.setting = setting;
9
+ this.jsApiList = jsApiList;
10
+
11
+ }
12
+
13
+ /**
14
+ * @description 初始化微信
15
+ */
16
+ init(){
17
+
18
+ return new Promise((resolve, reject)=>{
19
+ if (jwxSDK && jwxSDK.config) {
20
+ jwxSDK.config({
21
+ debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
22
+ appId: this.setting.appId, // 必填,公众号的唯一标识
23
+ timestamp: this.setting.timestamp, // 必填,生成签名的时间戳
24
+ nonceStr: this.setting.nonceStr, // 必填,生成签名的随机串
25
+ signature: this.setting.signature,// 必填,签名
26
+ jsApiList: this.jsApiList // 必填,需要使用的JS接口列表
27
+ });
28
+
29
+ /**本地调试跳过微信授权检查**/
30
+ if (envTypeReg.test(window.location.host)) {
31
+ console.log('本地调试跳过微信授权检查!');
32
+ resolve({
33
+ jwxSDK,
34
+ status: 'jwxSDK.dev'
35
+ });
36
+ }
37
+
38
+ /**检测是否完成**/
39
+ jwxSDK.ready(() => {
40
+ resolve({
41
+ jwxSDK,
42
+ status: 'jwxSDK.ok'
43
+ });
44
+ });
45
+
46
+ //初始化失败事件
47
+ jwxSDK.error((error) => {
48
+ console.error(`初始化失败事件`);
49
+ console.error(error);
50
+ reject({
51
+ jwxSDK,
52
+ status: 'jwxSDK.invalid'
53
+ });
54
+ })
55
+ }
56
+ else {
57
+ //加载wxSDK失败
58
+ console.error('加载wxSDK失败');
59
+ reject({
60
+ jwxSDK,
61
+ status: 'jwxSDK.loading.fail'
62
+ });
63
+ }
64
+ })
65
+
66
+ }
67
+ }
68
+
69
+
70
+ /**
71
+ * @description jwxSDK 实例
72
+ * @type {InitWxAuthorize}
73
+ */
74
+ let jwxSDKObj = null;
75
+
76
+ //参考地址: https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/JS-SDK.html#0
77
+
78
+ /**
79
+ * @description 初始化微信接口能力
80
+ * @param setting {Object|null} //后台返回的微信公众号信息
81
+ * @param jsApiList { Object } jwx可用接口列表
82
+ * @returns {{}|Promise}
83
+ */
84
+ export function initWx (setting = null , jsApiList) {
85
+ if(setting === null) {
86
+ return new Promise((reject)=>{
87
+ reject({
88
+ jwxSDK,
89
+ status: 'jwxSDK.config.error'
90
+ });
91
+ });
92
+ }
93
+ if (!jwxSDKObj) {
94
+ jwxSDKObj = new InitWxAuthorize(setting, jsApiList).init();
95
+ return jwxSDKObj;
96
+ }
97
+ return jwxSDKObj;
98
+ }
@@ -0,0 +1,54 @@
1
+ 'use strict';
2
+
3
+ export default {
4
+ style: [],
5
+ advanced: [],
6
+ content: [
7
+ {
8
+ label: '背景颜色:', //label
9
+ ele: 'xd-color', //package 名称
10
+ valueKey: 'bgcolor', //form[valueKey]
11
+ value: '', //v-model
12
+ placeholder: '请输入占位框背景颜色',
13
+ classNmae: 'input80', //样式名称 //input100,input80,input70,input60,input50,input40,input30,input20,
14
+ rules: [
15
+ {
16
+ required: true,
17
+ message: '请输入占位框背景颜色',
18
+ trigger: 'blur'
19
+ },
20
+ ]
21
+ },
22
+ {
23
+ label: '选中路径:', //label
24
+ ele: 'xd-select-pages-path', //package 名称
25
+ valueKey: 'select-pages-path', //form[valueKey]
26
+ value: null,
27
+ setting: {
28
+ router: XdBus.getParentData('getPagesTree')
29
+ },
30
+ inline: false,
31
+ },
32
+ {
33
+ label: '高度:', //label
34
+ ele: 'el-input', //package 名称
35
+ type: 'number',
36
+ valueKey: 'height', //form[valueKey]
37
+ value: null, //v-model
38
+ placeholder: '请输入占位框高度,单位像素,默认:10px',
39
+ classNmae: 'input80', //样式名称 //input100,input80,input70,input60,input50,input40,input30,input20,
40
+ rules: [
41
+ {
42
+ required: true,
43
+ message: '请输入占位框高度',
44
+ trigger: 'blur'
45
+ },
46
+ ]
47
+ },
48
+ {
49
+ label: '', //label
50
+ ele: 'slot', //package 名称
51
+ slot: 'is_reference',
52
+ },
53
+ ],
54
+ };
@@ -0,0 +1,80 @@
1
+ <template>
2
+ <view
3
+ class="jfb-third-block"
4
+ @click="handleEditxSelect"
5
+ :class="{
6
+ editx : isEditx && active,
7
+ noBorder: noBorder
8
+ }"
9
+ >
10
+ <!--#ifdef H5-->
11
+ <view
12
+ class="jfb-third-block__edit"
13
+ :class="{ editx : isEditx && active }"
14
+ v-if="isEditx && active && !noBorder"
15
+ >
16
+ <view class="jfb-third-block__edit-icon" @click="delEdit">删除</view>
17
+ </view>
18
+ <!-- #endif -->
19
+ <view class="jfb-third-block__body">
20
+ <view :style="{height: height * 2 + 'rpx', background: bgcolor}"></view>
21
+ </view>
22
+ </view>
23
+ </template>
24
+
25
+ <script>
26
+ import XdFontIcon from "@/components/XdFontIcon/XdFontIcon";
27
+ import { jfbRootExec } from "@/utils/xd.event";
28
+ import JfbThirdBlockMixin from "./JfbThirdBlockMixin";
29
+ import {getContainerPropsValue} from "@/utils/xd.base";
30
+ import componentsMixins from "@/mixins/componentsMixins";
31
+
32
+ export default {
33
+ name: "JfbThirdBlock",
34
+ components: {
35
+ XdFontIcon
36
+ },
37
+ mixins: [
38
+ componentsMixins,
39
+ JfbThirdBlockMixin,
40
+ ],
41
+ data() {
42
+ return {
43
+ height: 10,
44
+ bgcolor: '#fff'
45
+ }
46
+ },
47
+ watch: {
48
+ container(value) {
49
+ this.init(value)
50
+ }
51
+ },
52
+ created() {
53
+ this.init(this.container);
54
+ },
55
+ methods: {
56
+ init(value) {
57
+ let bgcolor = getContainerPropsValue(value, 'content.bgcolor');
58
+ let height = getContainerPropsValue(value, 'content.height');
59
+ if (bgcolor) this.bgcolor = bgcolor;
60
+ if (height) this.height = height;
61
+ },
62
+ onJfbLoad(options) {
63
+
64
+ },
65
+ }
66
+ }
67
+
68
+
69
+ </script>
70
+
71
+ <style scoped lang="less">
72
+ @import "./JfbThirdBlockLess.less";
73
+
74
+ .jfb-third-block {
75
+
76
+ &__body{
77
+
78
+ }
79
+ }
80
+ </style>
@@ -0,0 +1,78 @@
1
+ /**
2
+ * @desc 获取绝对路径完整地址
3
+ * @param @path
4
+ **/
5
+ //例如:https://image.jufubao.cn/20220501010108/image/bg/default_gonghui_bg.png
6
+ @basePath: 'business/';
7
+ @doMain: '//sandbox-img.jufubao.cn/';
8
+
9
+ .getBusinessImageUrl(@path, @size: 'size8') {
10
+ @url: "@{doMain}@{basePath}@{path}?x-oss-process=style/@{size}";
11
+ background-image: url(@url);
12
+ }
13
+
14
+ //start
15
+ .jfb-third-block {
16
+ box-sizing: border-box;
17
+ min-height: unit(100, rpx);
18
+
19
+ &__body{
20
+ position: relative;
21
+ overflow: hidden;
22
+ z-index: 2
23
+ }
24
+
25
+ &.editx,&:hover {
26
+ position: relative;
27
+ z-index: 3;
28
+ &::after{
29
+ border: 2rpx dashed blue;
30
+ content: " ";
31
+ position: absolute;
32
+ top:0;
33
+ left:0;
34
+ bottom:0;
35
+ right:0;
36
+ z-index: 4;
37
+ cursor: pointer;
38
+ }
39
+ }
40
+
41
+
42
+ &__edit {
43
+ cursor: pointer;
44
+ position: absolute;
45
+ right: unit(0, rpx);
46
+ top: unit(-52, rpx);
47
+ height: unit(50, rpx);
48
+ line-height: unit(50, rpx);
49
+ display: flex;
50
+ justify-content: center;
51
+ align-items: center;
52
+ background: rgba(0, 0, 0, .6);
53
+ border-radius: unit(10, rpx);
54
+ box-shadow: 0 0 10px rbga(0, 0, 0, 0.3);
55
+ color: #fff;
56
+ font-size: unit(22, rpx);
57
+
58
+ &-icon{
59
+ padding: 0 unit(20, rpx);
60
+ }
61
+
62
+ &.editx {
63
+ box-sizing: border-box;
64
+
65
+ }
66
+ }
67
+ }
68
+ //end
69
+
70
+
71
+ /**notPreview**/
72
+ .jfb-third-block {
73
+ //&:before {
74
+ //content: " ";
75
+ //display: table;
76
+ //}
77
+ }
78
+ /**endNotPreview**/
@@ -0,0 +1,30 @@
1
+ 'use strict';
2
+
3
+
4
+ //@AttrImport
5
+ import Attr from "./Attr";
6
+ //@EndAttrImport
7
+
8
+
9
+ export default {
10
+ data() {
11
+ return {
12
+ //#ifdef H5
13
+
14
+ //@AttrData
15
+ Attr:{}, //对外开发编辑属性
16
+ //@EndAttrData
17
+
18
+ // #endif
19
+ cssRoot: 'jfb-third-block'
20
+ }
21
+ },
22
+ created() {
23
+
24
+ //@AttrDataCreated
25
+ this.Attr = this.$xdUniHelper.customClone(Attr);
26
+ //@EndAttrDataCreated
27
+
28
+
29
+ },
30
+ }
@@ -0,0 +1,6 @@
1
+ 'use strict';
2
+
3
+ export default {
4
+
5
+ }
6
+
@@ -0,0 +1,13 @@
1
+ 'use strict';
2
+
3
+ export default {
4
+ "type": "test",
5
+ "NODE_ENV": "development",
6
+ "UNI_PLATFORM": "h5",
7
+ "platform": "h5",
8
+ "viewType": "preview",
9
+ "isPreview": true,
10
+ "server": "server",
11
+ "copypack": "server",
12
+ "fileDir": "resource"
13
+ }