feat:初始提交uni-app项目
This commit is contained in:
245
unpackage/dist/dev/mp-weixin/uni_modules/uni-rate/components/uni-rate/uni-rate.js
vendored
Normal file
245
unpackage/dist/dev/mp-weixin/uni_modules/uni-rate/components/uni-rate/uni-rate.js
vendored
Normal file
@@ -0,0 +1,245 @@
|
||||
"use strict";
|
||||
const common_vendor = require("../../../../common/vendor.js");
|
||||
const _sfc_main = {
|
||||
name: "UniRate",
|
||||
props: {
|
||||
isFill: {
|
||||
// 星星的类型,是否镂空
|
||||
type: [Boolean, String],
|
||||
default: true
|
||||
},
|
||||
color: {
|
||||
// 星星未选中的颜色
|
||||
type: String,
|
||||
default: "#ececec"
|
||||
},
|
||||
activeColor: {
|
||||
// 星星选中状态颜色
|
||||
type: String,
|
||||
default: "#ffca3e"
|
||||
},
|
||||
disabledColor: {
|
||||
// 星星禁用状态颜色
|
||||
type: String,
|
||||
default: "#c0c0c0"
|
||||
},
|
||||
size: {
|
||||
// 星星的大小
|
||||
type: [Number, String],
|
||||
default: 24
|
||||
},
|
||||
value: {
|
||||
// 当前评分
|
||||
type: [Number, String],
|
||||
default: 0
|
||||
},
|
||||
modelValue: {
|
||||
// 当前评分
|
||||
type: [Number, String],
|
||||
default: 0
|
||||
},
|
||||
max: {
|
||||
// 最大评分
|
||||
type: [Number, String],
|
||||
default: 5
|
||||
},
|
||||
margin: {
|
||||
// 星星的间距
|
||||
type: [Number, String],
|
||||
default: 0
|
||||
},
|
||||
disabled: {
|
||||
// 是否可点击
|
||||
type: [Boolean, String],
|
||||
default: false
|
||||
},
|
||||
readonly: {
|
||||
// 是否只读
|
||||
type: [Boolean, String],
|
||||
default: false
|
||||
},
|
||||
allowHalf: {
|
||||
// 是否显示半星
|
||||
type: [Boolean, String],
|
||||
default: false
|
||||
},
|
||||
touchable: {
|
||||
// 是否支持滑动手势
|
||||
type: [Boolean, String],
|
||||
default: true
|
||||
}
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
valueSync: "",
|
||||
userMouseFristMove: true,
|
||||
userRated: false,
|
||||
userLastRate: 1
|
||||
};
|
||||
},
|
||||
watch: {
|
||||
value(newVal) {
|
||||
this.valueSync = Number(newVal);
|
||||
},
|
||||
modelValue(newVal) {
|
||||
this.valueSync = Number(newVal);
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
stars() {
|
||||
const value = this.valueSync ? this.valueSync : 0;
|
||||
const starList = [];
|
||||
const floorValue = Math.floor(value);
|
||||
const ceilValue = Math.ceil(value);
|
||||
for (let i = 0; i < this.max; i++) {
|
||||
if (floorValue > i) {
|
||||
starList.push({
|
||||
activeWitch: "100%"
|
||||
});
|
||||
} else if (ceilValue - 1 === i) {
|
||||
starList.push({
|
||||
activeWitch: (value - floorValue) * 100 + "%"
|
||||
});
|
||||
} else {
|
||||
starList.push({
|
||||
activeWitch: "0"
|
||||
});
|
||||
}
|
||||
}
|
||||
return starList;
|
||||
},
|
||||
marginNumber() {
|
||||
return Number(this.margin);
|
||||
}
|
||||
},
|
||||
created() {
|
||||
this.valueSync = Number(this.value || this.modelValue);
|
||||
this._rateBoxLeft = 0;
|
||||
this._oldValue = null;
|
||||
},
|
||||
mounted() {
|
||||
setTimeout(() => {
|
||||
this._getSize();
|
||||
}, 100);
|
||||
},
|
||||
methods: {
|
||||
touchstart(e) {
|
||||
if (this.readonly || this.disabled)
|
||||
return;
|
||||
const {
|
||||
clientX,
|
||||
screenX
|
||||
} = e.changedTouches[0];
|
||||
this._getRateCount(clientX || screenX);
|
||||
},
|
||||
touchmove(e) {
|
||||
if (this.readonly || this.disabled || !this.touchable)
|
||||
return;
|
||||
const {
|
||||
clientX,
|
||||
screenX
|
||||
} = e.changedTouches[0];
|
||||
this._getRateCount(clientX || screenX);
|
||||
},
|
||||
/**
|
||||
* 兼容 PC @tian
|
||||
*/
|
||||
mousedown(e) {
|
||||
},
|
||||
mousemove(e) {
|
||||
},
|
||||
mouseleave(e) {
|
||||
},
|
||||
/**
|
||||
* 获取星星个数
|
||||
*/
|
||||
_getRateCount(clientX) {
|
||||
this._getSize();
|
||||
const size = Number(this.size);
|
||||
if (isNaN(size)) {
|
||||
return new Error("size 属性只能设置为数字");
|
||||
}
|
||||
const rateMoveRange = clientX - this._rateBoxLeft;
|
||||
let index = parseInt(rateMoveRange / (size + this.marginNumber));
|
||||
index = index < 0 ? 0 : index;
|
||||
index = index > this.max ? this.max : index;
|
||||
const range = parseInt(rateMoveRange - (size + this.marginNumber) * index);
|
||||
let value = 0;
|
||||
if (this._oldValue === index && !this.PC)
|
||||
return;
|
||||
this._oldValue = index;
|
||||
if (this.allowHalf) {
|
||||
if (range > size / 2) {
|
||||
value = index + 1;
|
||||
} else {
|
||||
value = index + 0.5;
|
||||
}
|
||||
} else {
|
||||
value = index + 1;
|
||||
}
|
||||
value = Math.max(0.5, Math.min(value, this.max));
|
||||
this.valueSync = value;
|
||||
this._onChange();
|
||||
},
|
||||
/**
|
||||
* 触发动态修改
|
||||
*/
|
||||
_onChange() {
|
||||
this.$emit("input", this.valueSync);
|
||||
this.$emit("update:modelValue", this.valueSync);
|
||||
this.$emit("change", {
|
||||
value: this.valueSync
|
||||
});
|
||||
},
|
||||
/**
|
||||
* 获取星星距离屏幕左侧距离
|
||||
*/
|
||||
_getSize() {
|
||||
common_vendor.index.createSelectorQuery().in(this).select(".uni-rate").boundingClientRect().exec((ret) => {
|
||||
if (ret) {
|
||||
this._rateBoxLeft = ret[0].left;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
if (!Array) {
|
||||
const _easycom_uni_icons2 = common_vendor.resolveComponent("uni-icons");
|
||||
_easycom_uni_icons2();
|
||||
}
|
||||
const _easycom_uni_icons = () => "../../../uni-icons/components/uni-icons/uni-icons.js";
|
||||
if (!Math) {
|
||||
_easycom_uni_icons();
|
||||
}
|
||||
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
|
||||
return {
|
||||
a: common_vendor.f($options.stars, (star, index, i0) => {
|
||||
return {
|
||||
a: "fccbd4e6-0-" + i0,
|
||||
b: "fccbd4e6-1-" + i0,
|
||||
c: star.activeWitch,
|
||||
d: index,
|
||||
e: common_vendor.o((...args) => $options.touchstart && $options.touchstart(...args), index),
|
||||
f: common_vendor.o((...args) => $options.touchmove && $options.touchmove(...args), index),
|
||||
g: common_vendor.o((...args) => $options.mousedown && $options.mousedown(...args), index),
|
||||
h: common_vendor.o((...args) => $options.mousemove && $options.mousemove(...args), index),
|
||||
i: common_vendor.o((...args) => $options.mouseleave && $options.mouseleave(...args), index)
|
||||
};
|
||||
}),
|
||||
b: common_vendor.p({
|
||||
color: $props.color,
|
||||
size: $props.size,
|
||||
type: $props.isFill ? "star-filled" : "star"
|
||||
}),
|
||||
c: common_vendor.p({
|
||||
color: $props.disabled ? $props.disabledColor : $props.activeColor,
|
||||
size: $props.size,
|
||||
type: "star-filled"
|
||||
}),
|
||||
d: $props.disabled ? 1 : "",
|
||||
e: $options.marginNumber + "px"
|
||||
};
|
||||
}
|
||||
const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
|
||||
wx.createComponent(Component);
|
||||
//# sourceMappingURL=../../../../../.sourcemap/mp-weixin/uni_modules/uni-rate/components/uni-rate/uni-rate.js.map
|
||||
6
unpackage/dist/dev/mp-weixin/uni_modules/uni-rate/components/uni-rate/uni-rate.json
vendored
Normal file
6
unpackage/dist/dev/mp-weixin/uni_modules/uni-rate/components/uni-rate/uni-rate.json
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"component": true,
|
||||
"usingComponents": {
|
||||
"uni-icons": "../../../uni-icons/components/uni-icons/uni-icons"
|
||||
}
|
||||
}
|
||||
1
unpackage/dist/dev/mp-weixin/uni_modules/uni-rate/components/uni-rate/uni-rate.wxml
vendored
Normal file
1
unpackage/dist/dev/mp-weixin/uni_modules/uni-rate/components/uni-rate/uni-rate.wxml
vendored
Normal file
@@ -0,0 +1 @@
|
||||
<view><view ref="uni-rate" class="uni-rate"><view wx:for="{{a}}" wx:for-item="star" wx:key="d" class="{{['uni-rate__icon', d && 'uni-cursor-not-allowed']}}" style="{{'margin-right:' + e}}" catchtouchstart="{{star.e}}" catchtouchmove="{{star.f}}" catchmousedown="{{star.g}}" catchmousemove="{{star.h}}" bindmouseleave="{{star.i}}"><uni-icons wx:if="{{b}}" u-i="{{star.a}}" bind:__l="__l" u-p="{{b}}"/><view style="{{'width:' + star.c}}" class="uni-rate__icon-on"><uni-icons wx:if="{{c}}" u-i="{{star.b}}" bind:__l="__l" u-p="{{c}}"/></view></view></view></view>
|
||||
44
unpackage/dist/dev/mp-weixin/uni_modules/uni-rate/components/uni-rate/uni-rate.wxss
vendored
Normal file
44
unpackage/dist/dev/mp-weixin/uni_modules/uni-rate/components/uni-rate/uni-rate.wxss
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
* 这里是uni-app内置的常用样式变量
|
||||
*
|
||||
* uni-app 官方扩展插件及插件市场(https://ext.dcloud.net.cn)上很多三方插件均使用了这些样式变量
|
||||
* 如果你是插件开发者,建议你使用scss预处理,并在插件代码中直接使用这些变量(无需 import 这个文件),方便用户通过搭积木的方式开发整体风格一致的App
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* 如果你是App开发者(插件使用者),你可以通过修改这些变量来定制自己的插件主题,实现自定义主题功能
|
||||
*
|
||||
* 如果你的项目同样使用了scss预处理,你也可以直接在你的 scss 代码中使用如下变量,同时无需 import 这个文件
|
||||
*/
|
||||
/* 颜色变量 */
|
||||
/* 行为相关颜色 */
|
||||
/* 文字基本颜色 */
|
||||
/* 背景颜色 */
|
||||
/* 边框颜色 */
|
||||
/* 尺寸变量 */
|
||||
/* 文字尺寸 */
|
||||
/* 图片尺寸 */
|
||||
/* Border Radius */
|
||||
/* 水平间距 */
|
||||
/* 垂直间距 */
|
||||
/* 透明度 */
|
||||
/* 文章场景相关 */
|
||||
.uni-rate {
|
||||
display: flex;
|
||||
line-height: 1;
|
||||
font-size: 0;
|
||||
flex-direction: row;
|
||||
}
|
||||
.uni-rate__icon {
|
||||
position: relative;
|
||||
line-height: 1;
|
||||
font-size: 0;
|
||||
}
|
||||
.uni-rate__icon-on {
|
||||
overflow: hidden;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
line-height: 1;
|
||||
text-align: left;
|
||||
}
|
||||
Reference in New Issue
Block a user