完善未完成功能:修复关注列表/评论发布/编辑器草稿等页面
This commit is contained in:
+243
-337
@@ -29,14 +29,6 @@
|
||||
disabled
|
||||
suffixIcon="arrow-right"/>
|
||||
</view>
|
||||
|
||||
<!-- <uni-easyinput v-model="pItems[p_index].text" disabled @click="p_open()"></uni-easyinput> -->
|
||||
<!-- <view class=""
|
||||
style="border: 2rpx solid #000;text-align: center;padding: 20rpx 0rpx;margin: 0 50rpx;border-radius: 10rpx;background-color: #efefef;font-size: 36rpx;"
|
||||
@click="p_open">
|
||||
{{ pItems[0][p_index].text }}
|
||||
</view> -->
|
||||
|
||||
</uni-forms-item>
|
||||
|
||||
<uni-forms-item label="文章分类">
|
||||
@@ -58,14 +50,6 @@
|
||||
|
||||
suffixIcon="arrow-right"/>
|
||||
</view>
|
||||
|
||||
<!-- <uni-easyinput v-model="pItems[p_index].text" disabled @click="p_open()"></uni-easyinput> -->
|
||||
<!-- <view class=""
|
||||
style="border: 2rpx solid #000;text-align: center;padding: 20rpx 0rpx;margin: 0 50rpx;border-radius: 10rpx;background-color: #efefef;font-size: 36rpx;"
|
||||
@click="p_open">
|
||||
{{ pItems[0][p_index].text }}
|
||||
</view> -->
|
||||
|
||||
</uni-forms-item>
|
||||
|
||||
<uni-section title="文章封面" type="line">
|
||||
@@ -77,7 +61,6 @@
|
||||
</uni-data-checkbox>
|
||||
</view>
|
||||
<view class="" v-if="thumbMode === 1">
|
||||
|
||||
<view class="container" @click="updateImage(0)">
|
||||
<view v-if="!thumbnail[0]">
|
||||
<view class="cross-line horizontal"></view>
|
||||
@@ -90,390 +73,313 @@
|
||||
|
||||
<view class="parent-container" v-if="thumbMode === 3">
|
||||
<view class="container"
|
||||
|
||||
@click="updateImage(index)"
|
||||
v-for="(item, index) in thumbnail" :key="index">
|
||||
<view v-if="!thumbnail[index] || !thumbnail[index]">
|
||||
<view class="cross-line horizontal"></view>
|
||||
<view class="cross-line vertical"></view>
|
||||
</view>
|
||||
<cloud-image v-else width="200rpx"
|
||||
height="200rpx" mode="scaleToFill" :src="thumbnail[index]">
|
||||
<cloud-image v-else width="200rpx" height="200rpx" mode="scaleToFill" :src="thumbnail[index]">
|
||||
</cloud-image>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
</uni-section>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import uPicker from "@/uni_modules/uview-ui/components/u-picker/u-picker.vue";
|
||||
import uInput from "@/uni_modules/uview-ui/components/u-input/u-input.vue";
|
||||
import { ref, reactive, onMounted, onHide, onUnload } from 'vue'
|
||||
import uPicker from "@/uni_modules/uview-ui/components/u-picker/u-picker.vue"
|
||||
import uInput from "@/uni_modules/uview-ui/components/u-input/u-input.vue"
|
||||
import cloudImage from "@/components/cloud-image.vue"
|
||||
|
||||
export default {
|
||||
components: {
|
||||
uPicker,
|
||||
uInput,
|
||||
cloudImage
|
||||
},
|
||||
onHide() {
|
||||
clearInterval(this.saveInterval);
|
||||
},
|
||||
onUnload() {
|
||||
clearInterval(this.saveInterval);
|
||||
clearTimeout(this.saveInterval);
|
||||
},
|
||||
async onReady() {
|
||||
},
|
||||
async onShow() {
|
||||
setup() {
|
||||
const saveInterval = ref(null)
|
||||
const tag_index = ref(0)
|
||||
const category_id = ref("")
|
||||
const tag_show = ref(false)
|
||||
const tags = ref([])
|
||||
const thumbMode = ref(0)
|
||||
const p_show = ref(false)
|
||||
const p_type = ref("1")
|
||||
const p_index = ref(0)
|
||||
|
||||
},
|
||||
async onLoad() {
|
||||
this.saveInterval = setInterval(this.save, 10000);
|
||||
let cms = uni.getStorageSync("cms");
|
||||
|
||||
let res = await uniCloud.importObject("uni-cms-categories").getTags();
|
||||
if (res.code === "200") {
|
||||
this.tags = [res.tags];
|
||||
}
|
||||
|
||||
if (cms.category_id) {
|
||||
this.category_id = cms.category_id;
|
||||
for (let i = 0 ; i < this.tags[0].length ; i ++ ) {
|
||||
if ( this.category_id === this.tags[0][i].value ) {
|
||||
this.tag_index = i ;
|
||||
break;
|
||||
const thumbnailType = ref([
|
||||
{ text: "无封面", value: 0 },
|
||||
{ text: "单图模式", value: 1 },
|
||||
{ text: "三图模式", value: 3 },
|
||||
])
|
||||
|
||||
const thumbnail = reactive([
|
||||
{ src: "" },
|
||||
{ src: "" },
|
||||
{ src: "" },
|
||||
])
|
||||
|
||||
const pItems = ref([
|
||||
[
|
||||
{ text: "空军", value: "1" },
|
||||
{ text: "海军", value: "2" },
|
||||
{ text: "陆军", value: "3" },
|
||||
{ text: "地勤保障", value: "4" },
|
||||
{ text: "武警", value: "5" },
|
||||
]
|
||||
])
|
||||
|
||||
onHide(() => {
|
||||
clearInterval(saveInterval.value)
|
||||
})
|
||||
|
||||
onUnload(() => {
|
||||
clearInterval(saveInterval.value)
|
||||
clearTimeout(saveInterval.value)
|
||||
})
|
||||
|
||||
onMounted(async () => {
|
||||
saveInterval.value = setInterval(save, 10000)
|
||||
let cms = uni.getStorageSync("cms")
|
||||
|
||||
let res = await uniCloud.importObject("uni-cms-categories").getTags()
|
||||
if (res.code === "200") {
|
||||
tags.value = [res.tags]
|
||||
}
|
||||
|
||||
if (cms.category_id) {
|
||||
category_id.value = cms.category_id
|
||||
for (let i = 0; i < tags.value[0].length; i++) {
|
||||
if (category_id.value === tags.value[0][i].value) {
|
||||
tag_index.value = i
|
||||
break
|
||||
}
|
||||
}
|
||||
} else {
|
||||
category_id.value = tags.value[0][0].value
|
||||
tag_index.value = 0
|
||||
}
|
||||
|
||||
if (cms.thumbnail) {
|
||||
thumbMode.value = cms.thumbnail.length
|
||||
if (thumbMode.value === 0) {
|
||||
thumbnail[0] = { src: "" }
|
||||
thumbnail[1] = { src: "" }
|
||||
thumbnail[2] = { src: "" }
|
||||
thumbMode.value = 0
|
||||
} else if (thumbMode.value === 1) {
|
||||
thumbnail[0] = cms.thumbnail[0]
|
||||
thumbnail[1] = { src: "" }
|
||||
thumbnail[2] = { src: "" }
|
||||
thumbMode.value = 1
|
||||
} else if (thumbMode.value === 3) {
|
||||
thumbnail[0] = cms.thumbnail[0]
|
||||
thumbnail[1] = cms.thumbnail[1]
|
||||
thumbnail[2] = cms.thumbnail[2]
|
||||
thumbMode.value = 3
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
this.category_id = this.tags[0][0].value;
|
||||
this.tag_index = 0;
|
||||
}
|
||||
console.log(this.category_id)
|
||||
console.log(cms.thumbnail);
|
||||
if ( cms.thumbnail ) {
|
||||
this.thumbMode = cms.thumbnail.length;
|
||||
if (this.thumbMode === 0) {
|
||||
this.thumbnail = [
|
||||
{
|
||||
src: "",
|
||||
},
|
||||
{
|
||||
src: "",
|
||||
},
|
||||
{
|
||||
src: "",
|
||||
},
|
||||
];
|
||||
this.thumbMode = 0;
|
||||
|
||||
} else if (this.thumbMode === 1) {
|
||||
this.thumbnail = [
|
||||
cms.thumbnail[0],
|
||||
{
|
||||
src: "",
|
||||
},
|
||||
{
|
||||
src: "",
|
||||
},
|
||||
];
|
||||
this.thumbMode = 1;
|
||||
} else if (this.thumbMode === 3) {
|
||||
this.thumbnail = cms.thumbnail;
|
||||
this.thumbMode = 3;
|
||||
}
|
||||
}
|
||||
console.log(cms.p_type);
|
||||
if (cms.p_type) {
|
||||
this.p_type = cms.p_type;
|
||||
|
||||
for (let i = 0 ; i < this.pItems[0].length ; i ++ ) {
|
||||
console.log(": ", this.pItems[0][i].value,this.p_type );
|
||||
if ( this.p_type === this.pItems[0][i].value ) {
|
||||
this.p_index = i ;
|
||||
|
||||
break;
|
||||
|
||||
if (cms.p_type) {
|
||||
p_type.value = cms.p_type
|
||||
for (let i = 0; i < pItems.value[0].length; i++) {
|
||||
if (p_type.value === pItems.value[0][i].value) {
|
||||
p_index.value = i
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
function getFileInfo(path) {
|
||||
const parts = path.split('/').pop()
|
||||
const [filename, ...extParts] = parts.split('.')
|
||||
const ext = extParts.length ? extParts.pop() : ''
|
||||
return { name: filename, extname: ext }
|
||||
}
|
||||
console.log(this.p_type);
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
saveInterval: {},
|
||||
|
||||
tag_index: 0,
|
||||
category_id: "",
|
||||
tag_show: false,
|
||||
tags: [],
|
||||
|
||||
thumbnailType:[
|
||||
{
|
||||
text: "无封面",
|
||||
value: 0,
|
||||
},
|
||||
{
|
||||
text: "单图模式",
|
||||
value: 1,
|
||||
},
|
||||
{
|
||||
text: "三图模式",
|
||||
value: 3,
|
||||
},
|
||||
],
|
||||
thumbMode: 0,
|
||||
thumbnail: [
|
||||
{
|
||||
src: "",
|
||||
},
|
||||
{
|
||||
src: "",
|
||||
},
|
||||
{
|
||||
src: "",
|
||||
},
|
||||
],
|
||||
|
||||
p_show: false,
|
||||
p_type: "1",
|
||||
p_index: 0,
|
||||
pItems: [
|
||||
[
|
||||
{
|
||||
text: "空军",
|
||||
value: "1"
|
||||
},
|
||||
{
|
||||
text: "海军",
|
||||
value: "2"
|
||||
},
|
||||
{
|
||||
text: "陆军",
|
||||
value: "3"
|
||||
},
|
||||
{
|
||||
text: "地勤保障",
|
||||
value: "4"
|
||||
},
|
||||
{
|
||||
text: "武警",
|
||||
value: "5"
|
||||
},
|
||||
]
|
||||
],
|
||||
|
||||
function formatBytes(bytes) {
|
||||
if (bytes === 0) return '0 Bytes'
|
||||
const k = 1024
|
||||
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB']
|
||||
const i = Math.floor(Math.log(bytes) / Math.log(k))
|
||||
if (i >= sizes.length) return '> 1 TB'
|
||||
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i]
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
getFileInfo(path) {
|
||||
const parts = path.split('/').pop();
|
||||
const [filename, ...extParts] = parts.split('.');
|
||||
const ext = extParts.length ? extParts.pop() : '';
|
||||
return {
|
||||
name: filename,
|
||||
extname: ext
|
||||
};
|
||||
},
|
||||
formatBytes(bytes) {
|
||||
if (bytes === 0) return '0 Bytes';
|
||||
const k = 1024;
|
||||
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
|
||||
|
||||
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
||||
|
||||
if (i >= sizes.length) return '> 1 TB';
|
||||
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
|
||||
},
|
||||
thumbnailChange(e) {
|
||||
|
||||
function thumbnailChange(e) {
|
||||
console.log(e)
|
||||
// this.thumbMode = e.detail.value;
|
||||
|
||||
},
|
||||
async updateImage(index) {
|
||||
const that = this;
|
||||
}
|
||||
|
||||
async function updateImage(index) {
|
||||
uni.chooseImage({
|
||||
type: "image",
|
||||
count: 1,
|
||||
success: async (res) => {
|
||||
console.log(res);
|
||||
if (res.tempFilePaths.length > 0) {
|
||||
let filePath = res.tempFilePaths[0];
|
||||
let {
|
||||
name,
|
||||
extname
|
||||
} = that.getFileInfo(filePath)
|
||||
const uniCloudStorageExtCo = uniCloud.importObject("ext-storage-co");
|
||||
console.log(`thumbnail/${name}_${Math.random().toString(36).substr(2,6)}`)
|
||||
let filePath = res.tempFilePaths[0]
|
||||
let { name, extname } = getFileInfo(filePath)
|
||||
const uniCloudStorageExtCo = uniCloud.importObject("ext-storage-co")
|
||||
const uploadFileOptionsRes = await uniCloudStorageExtCo.getUploadFileOptions({
|
||||
cloudPath: `thumbnail/${name}_${Math.random().toString(36).substr(2,6)}`
|
||||
});
|
||||
console.log(uploadFileOptionsRes)
|
||||
})
|
||||
await uniCloud.uploadFile({
|
||||
...uploadFileOptionsRes.uploadFileOptions,
|
||||
filePath: filePath,
|
||||
cloudPath: uploadFileOptionsRes.cloudPath,
|
||||
success: () => {
|
||||
const res = {
|
||||
const res2 = {
|
||||
cloudPath: uploadFileOptionsRes.cloudPath,
|
||||
fileID: uploadFileOptionsRes.fileID,
|
||||
fileURL: uploadFileOptionsRes.fileURL
|
||||
};
|
||||
console.log(res)
|
||||
console.log(this.thumbnail)
|
||||
this.$set(this.thumbnail, index, res.fileID);
|
||||
|
||||
console.log("上传成功", res);
|
||||
}
|
||||
thumbnail[index].src = res2.fileID
|
||||
},
|
||||
fail: (err) => {
|
||||
console.log("上传失败", err);
|
||||
console.log("上传失败", err)
|
||||
}
|
||||
});
|
||||
|
||||
} else {
|
||||
console.log("未选中文件")
|
||||
})
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
tag_close() {
|
||||
this.tag_show = false;
|
||||
},
|
||||
tag_open() {
|
||||
console.log(111)
|
||||
this.tag_show = true;
|
||||
},
|
||||
tag_select(e) {
|
||||
let index = e.indexs[0];
|
||||
|
||||
let {
|
||||
text,
|
||||
value
|
||||
} = e.value[0];
|
||||
|
||||
this.tag_index = index;
|
||||
this.category_id = value;
|
||||
this.tag_close();
|
||||
},
|
||||
p_select(e) {
|
||||
console.log(e)
|
||||
let index = e.indexs[0];
|
||||
let {
|
||||
text,
|
||||
value
|
||||
} = e.value[0];
|
||||
|
||||
this.p_index = index;
|
||||
this.p_type = value;
|
||||
this.p_close();
|
||||
},
|
||||
p_close() {
|
||||
this.p_show = false;
|
||||
},
|
||||
p_open() {
|
||||
this.p_show = true;
|
||||
},
|
||||
pItemChange(e) {
|
||||
console.log(e)
|
||||
},
|
||||
getTexts(items) {
|
||||
let lst = [];
|
||||
for (let i = 0 ; i < items.length ; i ++ ) {
|
||||
lst.push(items[i].text)
|
||||
}
|
||||
return lst;
|
||||
},
|
||||
bindPickerChange(e) {
|
||||
console.log('picker发送选择改变,携带值为', e)
|
||||
// this.index = e.detail.value
|
||||
},
|
||||
save() {
|
||||
console.log(this.thumbMode,this.thumbnail)
|
||||
let cms = uni.getStorageSync("cms");
|
||||
})
|
||||
}
|
||||
|
||||
cms.category_id = this.category_id;
|
||||
|
||||
cms.p_type = this.p_type;
|
||||
|
||||
if (this.thumbMode === 0) {
|
||||
cms.thumbnail = [];
|
||||
} else if (this.thumbMode === 1) {
|
||||
let thumbnail = [this.thumbnail[0]];
|
||||
cms.thumbnail = thumbnail;
|
||||
} else if (this.thumbMode === 3) {
|
||||
let thumbnail = thumbnail;
|
||||
for (let i = 0 ; i < 3 ; i ++ ) {
|
||||
if (this.thumbnail[i]) {
|
||||
thumbnail.push(this.thumbnail[i])
|
||||
function tag_close() {
|
||||
tag_show.value = false
|
||||
}
|
||||
|
||||
function tag_open() {
|
||||
tag_show.value = true
|
||||
}
|
||||
|
||||
function tag_select(e) {
|
||||
let index = e.indexs[0]
|
||||
let { text, value } = e.value[0]
|
||||
tag_index.value = index
|
||||
category_id.value = value
|
||||
tag_close()
|
||||
}
|
||||
|
||||
function p_select(e) {
|
||||
let index = e.indexs[0]
|
||||
let { text, value } = e.value[0]
|
||||
p_index.value = index
|
||||
p_type.value = value
|
||||
p_close()
|
||||
}
|
||||
|
||||
function p_close() {
|
||||
p_show.value = false
|
||||
}
|
||||
|
||||
function p_open() {
|
||||
p_show.value = true
|
||||
}
|
||||
|
||||
function save() {
|
||||
let cms = uni.getStorageSync("cms")
|
||||
cms.category_id = category_id.value
|
||||
cms.p_type = p_type.value
|
||||
|
||||
if (thumbMode.value === 0) {
|
||||
cms.thumbnail = []
|
||||
} else if (thumbMode.value === 1) {
|
||||
cms.thumbnail = [thumbnail[0]]
|
||||
} else if (thumbMode.value === 3) {
|
||||
let thumb = []
|
||||
for (let i = 0; i < 3; i++) {
|
||||
if (thumbnail[i]) {
|
||||
thumb.push(thumbnail[i])
|
||||
}
|
||||
}
|
||||
cms.thumbnail = thumbnail;
|
||||
}
|
||||
cms.thumbnail = thumb
|
||||
}
|
||||
|
||||
console.log(cms)
|
||||
|
||||
},
|
||||
back() {
|
||||
this.save();
|
||||
}
|
||||
|
||||
function back() {
|
||||
save()
|
||||
try {
|
||||
uni.navigateBack({delta: 1});
|
||||
} catch(e) {
|
||||
uni.switchTab({
|
||||
url:"/pages/index/index"
|
||||
})
|
||||
uni.navigateBack({ delta: 1 })
|
||||
} catch (e) {
|
||||
uni.switchTab({ url: "/pages/index/index" })
|
||||
}
|
||||
},
|
||||
toPreview() {
|
||||
let flag = true;
|
||||
|
||||
console.log(this.thumbMode,this.thumbnail)
|
||||
let cms = uni.getStorageSync("cms");
|
||||
|
||||
cms.category_id = this.category_id;
|
||||
|
||||
cms.p_type = this.p_type;
|
||||
|
||||
}
|
||||
|
||||
function toPreview() {
|
||||
let flag = true
|
||||
let cms = uni.getStorageSync("cms")
|
||||
|
||||
cms.category_id = category_id.value
|
||||
cms.p_type = p_type.value
|
||||
|
||||
if (!cms.p_type) {
|
||||
uni.showLoading({ title: `兵种不能为空` });
|
||||
setTimeout(() => uni.hideLoading(), 1000);
|
||||
flag = false;
|
||||
uni.showLoading({ title: `兵种不能为空` })
|
||||
setTimeout(() => uni.hideLoading(), 1000)
|
||||
flag = false
|
||||
} else if (!cms.category_id) {
|
||||
uni.showLoading({ title: `分类不能为空` });
|
||||
setTimeout(() => uni.hideLoading(), 1000);
|
||||
flag = false;
|
||||
uni.showLoading({ title: `分类不能为空` })
|
||||
setTimeout(() => uni.hideLoading(), 1000)
|
||||
flag = false
|
||||
} else {
|
||||
console.log(this.thumbMode, this.thumbnail)
|
||||
if (this.thumbMode === 0) {
|
||||
cms.thumbnail = [];
|
||||
} else if (this.thumbMode === 1) {
|
||||
let thumbnail = [this.thumbnail[0]];
|
||||
cms.thumbnail = thumbnail;
|
||||
} else if (this.thumbMode === 3) {
|
||||
let thumbnail = thumbnail;
|
||||
for (let i = 0 ; i < 3 ; i ++ ) {
|
||||
if (this.thumbnail[i]) {
|
||||
thumbnail.push(this.thumbnail[i])
|
||||
if (thumbMode.value === 0) {
|
||||
cms.thumbnail = []
|
||||
} else if (thumbMode.value === 1) {
|
||||
cms.thumbnail = [thumbnail[0]]
|
||||
} else if (thumbMode.value === 3) {
|
||||
let thumb = []
|
||||
for (let i = 0; i < 3; i++) {
|
||||
if (thumbnail[i]) {
|
||||
thumb.push(thumbnail[i])
|
||||
}
|
||||
}
|
||||
cms.thumbnail = thumbnail;
|
||||
}
|
||||
cms.thumbnail = thumb
|
||||
}
|
||||
}
|
||||
for(let i = 0 ; i < cms.thumbnail.length ; i ++ ) {
|
||||
|
||||
for (let i = 0; i < cms.thumbnail.length; i++) {
|
||||
if (cms.thumbnail[i] === "") {
|
||||
uni.showLoading({ title: `封面图不能为空` });
|
||||
setTimeout(() => uni.hideLoading(), 1000);
|
||||
flag = false;
|
||||
uni.showLoading({ title: `封面图不能为空` })
|
||||
setTimeout(() => uni.hideLoading(), 1000)
|
||||
flag = false
|
||||
}
|
||||
}
|
||||
uni.setStorageSync("cms", cms)
|
||||
|
||||
if (flag) {
|
||||
uni.navigateTo({
|
||||
url:"/pages2/editCms/preview"
|
||||
})
|
||||
}
|
||||
|
||||
},
|
||||
if (flag) {
|
||||
uni.navigateTo({ url: "/pages2/editCms/preview" })
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
saveInterval,
|
||||
tag_index,
|
||||
category_id,
|
||||
tag_show,
|
||||
tags,
|
||||
thumbMode,
|
||||
thumbnailType,
|
||||
thumbnail,
|
||||
p_show,
|
||||
p_type,
|
||||
p_index,
|
||||
pItems,
|
||||
getFileInfo,
|
||||
formatBytes,
|
||||
thumbnailChange,
|
||||
updateImage,
|
||||
tag_close,
|
||||
tag_open,
|
||||
tag_select,
|
||||
p_select,
|
||||
p_close,
|
||||
p_open,
|
||||
save,
|
||||
back,
|
||||
toPreview
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@@ -487,7 +393,7 @@
|
||||
|
||||
.container {
|
||||
position: relative;
|
||||
flex-shrink: 0; /* 禁止宽度压缩 */
|
||||
flex-shrink: 0;
|
||||
width: 200rpx;
|
||||
height: 200rpx;
|
||||
border: 1rpx solid #ccc;
|
||||
|
||||
Reference in New Issue
Block a user