Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
U
uview-ui
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
李晖
uview-ui
Commits
219cb6e0
Commit
219cb6e0
authored
Apr 22, 2020
by
王博文
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
加入全局分享开关
parent
75ec1e33
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
127 additions
and
134 deletions
+127
-134
main.js
main.js
+15
-8
index.js
uview/index.js
+70
-88
mixin.js
uview/libs/mixin/mixin.js
+26
-38
wxshare.js
uview/libs/mixin/wxshare.js
+16
-0
No files found.
main.js
View file @
219cb6e0
/*
* @Desc: --- ----
* @Date: 2020-04-22 12:29:21
* @LastEditors: 王
* @LastEditTime: 2020-04-22 15:18:39
*/
import
Vue
from
'
vue
'
import
Vue
from
'
vue
'
import
App
from
'
./App
'
import
App
from
'
./App
'
...
@@ -6,21 +12,22 @@ Vue.config.productionTip = false
...
@@ -6,21 +12,22 @@ Vue.config.productionTip = false
App
.
mpType
=
'
app
'
App
.
mpType
=
'
app
'
// 此处为演示Vue.prototype使用,非uView的功能部分
// 此处为演示Vue.prototype使用,非uView的功能部分
Vue
.
prototype
.
vuePrototype
=
'
枣红
'
;
Vue
.
prototype
.
vuePrototype
=
'
枣红
'
// 引入全局uView
// 引入全局uView
import
uView
from
"
@/uview
"
;
// Vue.prototype.openShare = true // 是否开启全局分享
Vue
.
use
(
uView
);
import
uView
from
'
@/uview
'
Vue
.
use
(
uView
)
// 此处为演示vuex使用,非uView的功能部分
// 此处为演示vuex使用,非uView的功能部分
import
store
from
'
@/store
'
;
import
store
from
'
@/store
'
// 引入uView提供的对vuex的简写法文件
// 引入uView提供的对vuex的简写法文件
let
vuexStore
=
require
(
"
@/store/$u.mixin.js
"
);
let
vuexStore
=
require
(
'
@/store/$u.mixin.js
'
)
Vue
.
mixin
(
vuexStore
)
;
Vue
.
mixin
(
vuexStore
)
const
app
=
new
Vue
({
const
app
=
new
Vue
({
store
,
store
,
...
App
...
App
})
})
app
.
$mount
()
app
.
$mount
()
uview/index.js
View file @
219cb6e0
// 引入全局mixin
// 引入全局mixin
import
mixin
from
'
@/uview/libs/mixin/mixin.js
'
import
mixin
from
'
@/uview/libs/mixin/mixin.js
'
import
wxshare
from
'
@/uview/libs/mixin/wxshare.js
'
// 全局挂载引入http相关请求拦截插件
// 全局挂载引入http相关请求拦截插件
import
http
from
"
@/uview/libs/request
"
;
import
http
from
'
@/uview/libs/request
'
function
wranning
(
str
)
{
function
wranning
(
str
)
{
// 开发环境进行信息输出,主要是一些报错信息
// 开发环境进行信息输出,主要是一些报错信息
// 这个环境的来由是在程序编写时候,点击hx编辑器运行调试代码的时候,详见:
// 这个环境的来由是在程序编写时候,点击hx编辑器运行调试代码的时候,详见:
// https://uniapp.dcloud.io/frame?id=%e5%bc%80%e5%8f%91%e7%8e%af%e5%a2%83%e5%92%8c%e7%94%9f%e4%ba%a7%e7%8e%af%e5%a2%83
// https://uniapp.dcloud.io/frame?id=%e5%bc%80%e5%8f%91%e7%8e%af%e5%a2%83%e5%92%8c%e7%94%9f%e4%ba%a7%e7%8e%af%e5%a2%83
if
(
process
.
env
.
NODE_ENV
===
'
development
'
)
{
if
(
process
.
env
.
NODE_ENV
===
'
development
'
)
{
console
.
warn
(
str
);
console
.
warn
(
str
)
}
}
}
}
// 尝试判断在根目录的/store中是否有$u.mixin.js,此文件uView默认为需要挂在到全局的vuex的state变量
// 尝试判断在根目录的/store中是否有$u.mixin.js,此文件uView默认为需要挂在到全局的vuex的state变量
...
@@ -23,107 +23,89 @@ function wranning(str) {
...
@@ -23,107 +23,89 @@ function wranning(str) {
// }
// }
// post类型对象参数转为get类型url参数
// post类型对象参数转为get类型url参数
import
{
import
{
queryParams
}
from
'
@/uview/libs/function/queryParams.js
'
queryParams
}
from
'
@/uview/libs/function/queryParams.js
'
;
// 路由封装
// 路由封装
import
{
import
{
route
}
from
'
@/uview/libs/function/route.js
'
route
}
from
'
@/uview/libs/function/route.js
'
;
// 时间格式化
// 时间格式化
import
{
import
{
timeFormat
}
from
'
@/uview/libs/function/timeFormat.js
'
timeFormat
}
from
'
@/uview/libs/function/timeFormat.js
'
;
// 时间戳格式化,返回多久之前
// 时间戳格式化,返回多久之前
import
{
import
{
timeFrom
}
from
'
@/uview/libs/function/timeFrom.js
'
timeFrom
}
from
'
@/uview/libs/function/timeFrom.js
'
;
// 颜色渐变相关,colorGradient-颜色渐变,hexToRgb-十六进制颜色转rgb颜色,rgbToHex-rgb转十六进制
// 颜色渐变相关,colorGradient-颜色渐变,hexToRgb-十六进制颜色转rgb颜色,rgbToHex-rgb转十六进制
import
{
import
{
colorGradient
,
colorGradient
,
hexToRgb
,
hexToRgb
,
rgbToHex
rgbToHex
}
from
'
@/uview/libs/function/colorGradient.js
'
;
}
from
'
@/uview/libs/function/colorGradient.js
'
// 生成全局唯一guid字符串
// 生成全局唯一guid字符串
import
{
import
{
guid
}
from
'
@/uview/libs/function/guid.js
'
guid
}
from
'
@/uview/libs/function/guid.js
'
;
// 主题相关颜色,info|success|warning|primary|default|error,此颜色已在uview.scss中定义,但是为js中也能使用,故也定义一份
// 主题相关颜色,info|success|warning|primary|default|error,此颜色已在uview.scss中定义,但是为js中也能使用,故也定义一份
import
{
import
{
color
}
from
'
@/uview/libs/function/color.js
'
color
}
from
'
@/uview/libs/function/color.js
'
;
// 根据type获取图标名称
// 根据type获取图标名称
import
{
import
{
type2icon
}
from
'
@/uview/libs/function/type2icon.js
'
type2icon
}
from
'
@/uview/libs/function/type2icon.js
'
;
// 打乱数组的顺序
// 打乱数组的顺序
import
{
import
{
randomArray
}
from
'
@/uview/libs/function/randomArray.js
'
randomArray
}
from
"
@/uview/libs/function/randomArray.js
"
;
// 规则检验
// 规则检验
import
test
from
"
@/uview/libs/function/test.js
"
;
import
test
from
'
@/uview/libs/function/test.js
'
// 随机数
// 随机数
import
{
import
{
random
}
from
'
@/uview/libs/function/random.js
'
random
}
from
"
@/uview/libs/function/random.js
"
;
// 去除空格
// 去除空格
import
{
import
{
trim
}
from
'
@/uview/libs/function/trim.js
'
trim
}
from
"
@/uview/libs/function/trim.js
"
;
// toast提示,对uni.showToast的封装
// toast提示,对uni.showToast的封装
import
{
import
{
toast
}
from
'
@/uview/libs/function/toast.js
'
toast
}
from
"
@/uview/libs/function/toast.js
"
;
// 配置信息
// 配置信息
import
config
from
"
@/uview/libs/config/config.js
"
;
import
config
from
'
@/uview/libs/config/config.js
'
// 各个需要fixed的地方的z-index配置文件
// 各个需要fixed的地方的z-index配置文件
import
zIndex
from
"
@/uview/libs/config/zIndex.js
"
;
import
zIndex
from
'
@/uview/libs/config/zIndex.js
'
const
$u
=
{
const
$u
=
{
queryParams
,
queryParams
,
route
,
route
,
timeFormat
,
timeFormat
,
date
:
timeFormat
,
// 另名date
date
:
timeFormat
,
// 另名date
timeFrom
,
timeFrom
,
colorGradient
,
colorGradient
,
guid
,
guid
,
color
,
color
,
type2icon
,
type2icon
,
randomArray
,
randomArray
,
wranning
,
wranning
,
get
:
http
.
get
,
get
:
http
.
get
,
post
:
http
.
post
,
post
:
http
.
post
,
hexToRgb
,
hexToRgb
,
rgbToHex
,
rgbToHex
,
test
,
test
,
random
,
random
,
trim
,
trim
,
type
:
[
'
primary
'
,
'
success
'
,
'
error
'
,
'
warning
'
,
'
info
'
],
type
:
[
'
primary
'
,
'
success
'
,
'
error
'
,
'
warning
'
,
'
info
'
],
http
,
http
,
toast
,
toast
,
config
,
// uView配置信息相关,比如版本号
config
,
// uView配置信息相关,比如版本号
zIndex
,
zIndex
}
}
const
install
=
(
Vue
)
=>
{
const
install
=
Vue
=>
{
Vue
.
mixin
(
mixin
);
Vue
.
mixin
(
mixin
)
// Vue.mixin(vuexStore);
console
.
log
(
Vue
.
prototype
.
openShare
)
// 时间格式化,同时两个名称,date和timeFormat
if
(
Vue
.
prototype
.
openShare
)
{
Vue
.
filter
(
'
timeFormat
'
,
(
timestamp
,
format
)
=>
{
Vue
.
mixin
(
wxshare
)
return
timeFormat
(
timestamp
,
format
);
}
})
// Vue.mixin(vuexStore);
Vue
.
filter
(
'
date
'
,
(
timestamp
,
format
)
=>
{
// 时间格式化,同时两个名称,date和timeFormat
return
timeFormat
(
timestamp
,
format
);
Vue
.
filter
(
'
timeFormat
'
,
(
timestamp
,
format
)
=>
{
})
return
timeFormat
(
timestamp
,
format
)
// 将多久以前的方法,注入到全局过滤器
})
Vue
.
filter
(
'
timeFrom
'
,
(
timestamp
,
format
)
=>
{
Vue
.
filter
(
'
date
'
,
(
timestamp
,
format
)
=>
{
return
timeFrom
(
timestamp
,
format
);
return
timeFormat
(
timestamp
,
format
)
})
})
Vue
.
prototype
.
$u
=
$u
;
// 将多久以前的方法,注入到全局过滤器
Vue
.
filter
(
'
timeFrom
'
,
(
timestamp
,
format
)
=>
{
return
timeFrom
(
timestamp
,
format
)
})
Vue
.
prototype
.
$u
=
$u
}
}
export
default
{
export
default
{
install
install
}
}
uview/libs/mixin/mixin.js
View file @
219cb6e0
module
.
exports
=
{
module
.
exports
=
{
data
()
{
data
()
{
return
{}
return
{}
},
},
onLoad
()
{
methods
:
{
// getRect挂载到$u上,因为这方法需要使用in(this),所以无法把它独立成一个单独的文件导出
// 查询节点信息
this
.
$u
.
getRect
=
this
.
$uGetRect
;
$uGetRect
(
selector
,
all
)
{
return
new
Promise
(
resolve
=>
{
// 设置默认的转发参数
uni
this
.
$u
.
mpShare
=
{
.
createSelectorQuery
()
title
:
''
,
// 默认为小程序名称
.
in
(
this
)
path
:
''
,
// 默认为当前页面路径
[
all
?
'
selectAll
'
:
'
select
'
](
selector
)
imageUrl
:
''
// 默认为当前页面的截图
.
boundingClientRect
(
rect
=>
{
};
if
(
all
&&
Array
.
isArray
(
rect
)
&&
rect
.
length
)
{
},
resolve
(
rect
)
onShareAppMessage
()
{
}
return
this
.
$u
.
mpShare
;
if
(
!
all
&&
rect
)
{
},
resolve
(
rect
)
methods
:
{
}
// 查询节点信息
})
$uGetRect
(
selector
,
all
)
{
.
exec
()
return
new
Promise
(
resolve
=>
{
})
uni
.
createSelectorQuery
()
}
.
in
(
this
)[
all
?
'
selectAll
'
:
'
select
'
](
selector
)
},
.
boundingClientRect
(
rect
=>
{
onReachBottom
()
{
if
(
all
&&
Array
.
isArray
(
rect
)
&&
rect
.
length
)
{
uni
.
$emit
(
'
uOnReachBottom
'
)
resolve
(
rect
);
}
}
if
(
!
all
&&
rect
)
{
resolve
(
rect
);
}
})
.
exec
();
});
},
},
onReachBottom
()
{
uni
.
$emit
(
'
uOnReachBottom
'
);
}
}
}
uview/libs/mixin/wxshare.js
0 → 100644
View file @
219cb6e0
module
.
exports
=
{
onLoad
()
{
// getRect挂载到$u上,因为这方法需要使用in(this),所以无法把它独立成一个单独的文件导出
this
.
$u
.
getRect
=
this
.
$uGetRect
// 设置默认的转发参数
this
.
$u
.
mpShare
=
{
title
:
''
,
// 默认为小程序名称
path
:
''
,
// 默认为当前页面路径
imageUrl
:
''
// 默认为当前页面的截图
}
},
onShareAppMessage
()
{
return
this
.
$u
.
mpShare
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment