提交 aa0b34e9 authored 作者: 曹末's avatar 曹末

bug修改

上级 6e45d29d
{ {
"permissions": { "permissions": {
"openapi": [ "openapi": [
"wxacode.get"
] ]
} }
} }
\ No newline at end of file
const createContract = require('./addContract/index');
const getContract = require('./getContract/index');
const updateContract = require('./updateContract/index');
const deleteContract = require('./deleteContract/index');
// 云函数入口函数
exports.main = async (event, context) => {
switch (event.type) {
case 'get':
return await getContract.main(event, context);
case 'add':
return await createContract.main(event, context);
case 'update':
return await updateContract.main(event, context);
case 'delete':
return await deleteContract.main(event, context);
}
};
\ No newline at end of file
{
"name": "contract",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"wx-server-sdk": "~3.0.1"
}
}
\ No newline at end of file
差异被折叠。
...@@ -22,7 +22,7 @@ exports.main = async (event) => { ...@@ -22,7 +22,7 @@ exports.main = async (event) => {
if (data.length !== 0) { if (data.length !== 0) {
return { return {
success: false, success: false,
msg: "用户名重复" msg: "账号重复"
} }
} }
......
{
"permissions": {
"openapi": [
]
}
}
\ No newline at end of file
const createContract = require('./createContract/index');
const getContract = require('./getContract/index');
const login = require('./login/index'); const login = require('./login/index');
const getUser = require('./getUser/index'); const getUser = require('./getUser/index');
const updateContract = require('./updateContract/index');
const deleteContract = require('./deleteContract/index');
const addUser = require('./addUser/index'); const addUser = require('./addUser/index');
const deleteUser = require('./deleteUser/index'); const deleteUser = require('./deleteUser/index');
const updateUser = require('./updateUser/index'); const updateUser = require('./updateUser/index');
...@@ -11,23 +7,15 @@ const updateUser = require('./updateUser/index'); ...@@ -11,23 +7,15 @@ const updateUser = require('./updateUser/index');
// 云函数入口函数 // 云函数入口函数
exports.main = async (event, context) => { exports.main = async (event, context) => {
switch (event.type) { switch (event.type) {
case 'getContract': case 'add':
return await getContract.main(event, context);
case 'createContract':
return await createContract.main(event, context);
case 'updateContract':
return await updateContract.main(event, context);
case 'deleteContract':
return await deleteContract.main(event, context);
case 'login':
return await login.main(event, context);
case 'getUser':
return await getUser.main(event, context);
case 'addUser':
return await addUser.main(event, context); return await addUser.main(event, context);
case 'deleteUser': case 'delete':
return await deleteUser.main(event, context); return await deleteUser.main(event, context);
case 'updateUser': case 'update':
return await updateUser.main(event, context); return await updateUser.main(event, context);
case 'login':
return await login.main(event, context);
case 'get':
return await getUser.main(event, context);
} }
}; };
\ No newline at end of file
...@@ -10,7 +10,6 @@ exports.main = async (event) => { ...@@ -10,7 +10,6 @@ exports.main = async (event) => {
} = event.data } = event.data
const db = cloud.database(); const db = cloud.database();
const _ = db.command const _ = db.command
// 如果云函数所在环境为 abc,则下面的调用就会请求到 abc 环境的数据库
let user = await db.collection('user').where({ let user = await db.collection('user').where({
username: _.eq(username) username: _.eq(username)
}).get() }).get()
...@@ -18,7 +17,7 @@ exports.main = async (event) => { ...@@ -18,7 +17,7 @@ exports.main = async (event) => {
if (!user || (user.password !== password)) { if (!user || (user.password !== password)) {
return { return {
success: false, success: false,
msg: "用户名或密码错误", msg: "账号或密码错误",
} }
} else { } else {
return { return {
......
{ {
"name": "test1", "name": "user",
"version": "1.0.0", "version": "1.0.0",
"description": "", "description": "",
"main": "index.js", "main": "index.js",
...@@ -9,6 +9,6 @@ ...@@ -9,6 +9,6 @@
"author": "", "author": "",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"wx-server-sdk": "~2.4.0" "wx-server-sdk": "~3.0.1"
} }
} }
\ No newline at end of file
...@@ -22,7 +22,7 @@ exports.main = async (event) => { ...@@ -22,7 +22,7 @@ exports.main = async (event) => {
if (data.length > 1) { if (data.length > 1) {
return { return {
success: false, success: false,
msg: "用户名重复" msg: "账号重复"
} }
} }
...@@ -33,6 +33,17 @@ exports.main = async (event) => { ...@@ -33,6 +33,17 @@ exports.main = async (event) => {
isAdmin, isAdmin,
} }
}) })
if (data.length === 0) {
const {
data: udata
} = db.collection('user').doc(id).get()
await db.collection("contract").where({
username: _.eq(udata.username)
}).update({
username: label
})
}
return { return {
success: true success: true
} }
......
{ {
"pages": [ "pages": [
"pages/index/index", "pages/index/index",
"pages/examples/index", "pages/about/index",
"pages/user-center/index", "pages/user-center/index",
"pages/contract/index", "pages/contract/index",
"pages/addContract/index", "pages/add-contract/index",
"pages/updateContract/index", "pages/update-contract/index",
"pages/login/index", "pages/login/index",
"pages/userManage/index", "pages/user-manage/index",
"pages/modifyUser/index" "pages/modify-user/index",
"pages/contract-detail/index"
], ],
"window": { "window": {
"backgroundColor": "#F6F6F6", "backgroundColor": "#F6F6F6",
...@@ -32,7 +33,7 @@ ...@@ -32,7 +33,7 @@
"selectedIconPath": "images/icons/home-active.png" "selectedIconPath": "images/icons/home-active.png"
}, },
{ {
"pagePath": "pages/examples/index", "pagePath": "pages/about/index",
"text": "基础能力", "text": "基础能力",
"iconPath": "images/icons/examples.png", "iconPath": "images/icons/examples.png",
"selectedIconPath": "images/icons/examples-active.png" "selectedIconPath": "images/icons/examples-active.png"
......
Component({
/**
* 页面的初始数据
*/
data: {
showTip: false,
},
properties: {
showTipProps: Boolean,
title:String,
content:String
},
observers: {
showTipProps: function(showTipProps) {
this.setData({
showTip: showTipProps
});
}
},
methods: {
onClose(){
this.setData({
showTip: !this.data.showTip
});
},
}
});
{
"usingComponents": {},
"component": true
}
\ No newline at end of file
<!--miniprogram/components/cloudTipModal/index.wxml-->
<!-- wx:if="{{showUploadTip}}" -->
<view class="install_tip" wx:if="{{showTip}}">
<view class="install_tip_back"></view>
<view class="install_tip_detail">
<image class="install_tip_close" bind:tap="onClose" src="../../images/icons/close.png"/>
<view class="install_tip_detail_title">{{title}}</view>
<view class="install_tip_detail_tip">{{content}}</view>
</view>
</view>
.install_tip_back {
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
background-color: rgba(0,0,0,0.4);
z-index: 1;
}
.install_tip_close{
position:absolute;
right: 10rpx;
top: 10rpx;
width: 32px;
height: 32px;
/* background-color: red; */
}
.install_tip_detail {
position: fixed;
background-color: white;
right: 0;
bottom: 0;
left: 0;
border-radius: 40rpx 40rpx 0 0;
padding: 50rpx 50rpx 100rpx 50rpx;
z-index: 9;
}
.install_tip_detail_title {
font-weight: 400;
font-size: 40rpx;
text-align: center;
}
.install_tip_detail_tip {
font-size: 25rpx;
color: rgba(0,0,0,0.4);
margin-top: 20rpx;
text-align: left;
}
.install_tip_detail_buttons {
padding-top: 50rpx;
display: flex;
}
.install_tip_detail_button {
color: #07C160;
font-weight: 500;
background-color: rgba(0,0,0,0.1);
width: 40%;
text-align: center;
/* height: 90rpx; */
/* line-height: 90rpx; */
border-radius: 10rpx;
margin: 0 auto;
}
.install_tip_detail_button_primary {
background-color: #07C160;
color: #fff;
}
\ No newline at end of file
Component({
data: {
modalVisible: false,
tipText: '云开发>云模板>模板中心',
},
properties: {
installModulePageTitleProps: String,
modalVisibleProps: Boolean,
tipTextProps: String,
installModuleNameProps: String,
},
observers: {
modalVisibleProps: function (modalVisibleProps) {
this.setData({
modalVisible: modalVisibleProps,
});
},
tipTextProps: function (tipTextProps) {
this.setData({
tipText: tipTextProps,
});
},
},
methods: {
hideModal() {
if (this.data.modalVisible) {
this.setData({
modalVisible: false,
});
}
},
onViewDetail() {
this.hideModal();
wx.navigateTo({
url: `/pages/cloudbaseModuleInstallTips/index?moduleName=${this.properties.installModuleNameProps}&title=${this.properties.installModulePageTitleProps}`,
});
},
},
});
{
"usingComponents": {},
"component": true
}
\ No newline at end of file
<!-- miniprogram/components/cloudTipModal/index.wxml -->
<view class="install_tip" wx:if="{{ modalVisible }}">
<view class="install_tip_back" bindtap="hideModal" />
<view class="install_tip_detail">
<view class="install_tip_detail_title">体验前需安装云模板</view>
<view class="install_tip_detail_tip">请按照以下路径安装对应云模板</view>
<view class="install_tip_detail_shell">{{ tipText }}</view>
<view bindtap="onViewDetail" class="install_tip_detail_button">查看详情{{ installModuleName }}</view>
</view>
</view>
.install_tip_back {
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
background-color: rgba(0,0,0,0.4);
z-index: 1;
}
.install_tip_detail {
position: fixed;
background-color: white;
right: 0;
bottom: 0;
left: 0;
top: 60%;
border-radius: 40rpx 40rpx 0 0;
padding: 50rpx;
z-index: 9;
}
.install_tip_detail_title {
font-weight: 400;
font-size: 40rpx;
text-align: center;
}
.install_tip_detail_tip {
font-size: 25rpx;
color: rgba(0,0,0,0.4);
margin-top: 20rpx;
text-align: center;
}
.install_tip_detail_shell {
margin: 70rpx 0;
display: flex;
justify-content: center;
}
.install_tip_detail_copy {
color: #546488;
margin-left: 10rpx;
}
.install_tip_detail_button {
color: #07C160;
font-weight: 500;
background-color: rgba(0,0,0,0.1);
width: 60%;
text-align: center;
height: 90rpx;
line-height: 90rpx;
border-radius: 10rpx;
margin: 0 auto;
}
\ No newline at end of file
// components/cloudbaseModuleInstallPath/index.js
Component({
/**
* 组件的属性列表
*/
properties: {
installModuleName: String,
},
/**
* 组件的初始数据
*/
data: {
},
/**
* 组件的方法列表
*/
methods: {
}
})
\ No newline at end of file
{
"component": true,
"usingComponents": {}
}
\ No newline at end of file
<view class="tip">可以在“云开发>云模板>模板中心>{{installModuleName}}”找到该模板</view>
\ No newline at end of file
.tip {
font-size: 23rpx;
color: rgba(0, 0, 0, 0.5);
width: 90%;
text-align: center;
margin: 30rpx auto 0 auto;
}
\ No newline at end of file
Component({
data: {
modalVisible: false,
},
properties: {
visible: Boolean,
imageSrc: String,
},
observers: {
visible: function (visible) {
this.setData({
modalVisible: visible
});
},
},
methods: {
onClose() {
this.setData({ modalVisible: false });
}
}
});
{
"usingComponents": {},
"component": true
}
\ No newline at end of file
<view class="modal_container" wx:if="{{ modalVisible }}">
<view class="icon_close" bind:tap="onClose">
<view>X</view>
</view>
<view class="image_container">
<image class="code_img" src="{{ imageSrc }}" />
</view>
</view>
\ No newline at end of file
.modal_container {
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
background-color: rgba(0,0,0,0.4);
z-index: 1;
width: 100%;
height: 100%;
}
.icon_close {
position: fixed;
right: 40rpx;
top: 40rpx;
width: 70rpx;
height: 70rpx;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
/* background-color: #07c160; */
background-color: rgba(0,0,0,0.7);
color: white;
font-size: 32rpx;
font-weight: bold;
}
.code_img {
width: 400rpx;
height: 400rpx;
margin-top: 50%;
margin-left: 50%;
transform: translateX(-50%);
border-radius: 30rpx;
}
.install_tip_back {
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
background-color: rgba(0,0,0,0.4);
z-index: 1;
}
.install_tip_detail {
position: fixed;
background-color: white;
right: 0;
bottom: 0;
left: 0;
top: 60%;
border-radius: 40rpx 40rpx 0 0;
padding: 50rpx;
z-index: 9;
}
.install_tip_detail_title {
font-weight: 400;
font-size: 40rpx;
text-align: center;
}
.install_tip_detail_tip {
font-size: 25rpx;
color: rgba(0,0,0,0.4);
margin-top: 20rpx;
text-align: center;
}
.install_tip_detail_shell {
margin: 70rpx 0;
display: flex;
justify-content: center;
}
.install_tip_detail_copy {
color: #546488;
margin-left: 10rpx;
}
.install_tip_detail_button {
color: #07C160;
font-weight: 500;
background-color: rgba(0,0,0,0.1);
width: 60%;
text-align: center;
height: 90rpx;
line-height: 90rpx;
border-radius: 10rpx;
margin: 0 auto;
}
\ No newline at end of file
...@@ -7,7 +7,7 @@ Component({ ...@@ -7,7 +7,7 @@ Component({
"icon": "home" "icon": "home"
}, },
{ {
"pagePath": "/pages/examples/index", "pagePath": "/pages/about/index",
"text": "品牌", "text": "品牌",
"icon": "building-1" "icon": "building-1"
}, },
......
// index.js
Page({
});
\ No newline at end of file
{ {
"navigationBarTitleText": "品牌", "navigationBarTitleText": "品牌",
"usingComponents": { "usingComponents": {
"cloud-tip-modal": "/components/cloudTipModal/index"
} }
} }
\ No newline at end of file
// pages/addPontract/index.js // pages/addPontract/index.js
import Message from 'tdesign-miniprogram/message/index';
import { import {
request request
} from "../../utils/request.js" } from "../../utils/request.js"
...@@ -26,7 +27,7 @@ Page({ ...@@ -26,7 +27,7 @@ Page({
userVisible: false userVisible: false
}, },
onShow() { onShow() {
request("getUser").then(res => { request("user/get").then(res => {
this.setData({ this.setData({
users: res.data.map(v => ({ users: res.data.map(v => ({
id: v._id, id: v._id,
...@@ -108,6 +109,10 @@ Page({ ...@@ -108,6 +109,10 @@ Page({
}); });
}, },
async createContract() { async createContract() {
if (!this.validate()) {
return
}
wx.showLoading({ wx.showLoading({
title: '', title: '',
}); });
...@@ -117,12 +122,19 @@ Page({ ...@@ -117,12 +122,19 @@ Page({
cloudPath: `contract/${this.data.username}/${this.data.name}/${this.data.tempFile.name}`, cloudPath: `contract/${this.data.username}/${this.data.name}/${this.data.tempFile.name}`,
filePath: this.data.tempFile.path, filePath: this.data.tempFile.path,
}).then(res => { }).then(res => {
request("createContract", { request("contract/add", {
username: this.data.username, username: this.data.username,
name: this.data.name, name: this.data.name,
type: this.data.type, type: this.data.type,
files: [res.fileID] files: [res.fileID]
}).then(res => { }).then(res => {
const list = getCurrentPages()
Message.success({
context: list[list.length - 2],
offset: [20, 32],
duration: 2000,
content: '创建成功',
});
wx.navigateBack() wx.navigateBack()
}).finally(res => { }).finally(res => {
wx.hideLoading() wx.hideLoading()
...@@ -138,12 +150,19 @@ Page({ ...@@ -138,12 +150,19 @@ Page({
}) })
})).then(res => { })).then(res => {
console.log(res) console.log(res)
request("createContract", { request("contract/add", {
username: this.data.username, username: this.data.username,
name: this.data.name, name: this.data.name,
type: this.data.type, type: this.data.type,
files: res.map(v => v.fileID) files: res.map(v => v.fileID)
}).then(res => { }).then(res => {
const list = getCurrentPages()
Message.success({
context: list[list.length - 2],
offset: [20, 32],
duration: 2000,
content: '创建成功',
});
wx.navigateBack() wx.navigateBack()
}).finally(res => { }).finally(res => {
wx.hideLoading() wx.hideLoading()
...@@ -154,6 +173,41 @@ Page({ ...@@ -154,6 +173,41 @@ Page({
} }
},
validate() {
if (this.data.username === "") {
wx.showToast({
title: '请选择账号',
icon: "none"
})
return false
} else if (this.data.name === "") {
wx.showToast({
title: '合同名称不能为空',
icon: "none"
})
return false
} else {
if (this.data.type === 0) {
console.log(this.data.tempFile.path)
if (!this.data.tempFile.path || this.data.tempFile.path === "") {
wx.showToast({
title: '请上传PDF文件',
icon: "none"
})
return false
}
} else {
if (this.data.originFiles.length === 0) {
wx.showToast({
title: '请上传图片',
icon: "none"
})
return false
}
}
return true
}
} }
}) })
......
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
<view class="add-container"> <view class="add-container">
<view> <view>
<t-cell class="mb-16" arrow hover note="{{username}}" bind:click="onUserPicker"> <t-cell class="mb-16" arrow hover note="{{username}}" bind:click="onUserPicker">
<view slot="title" class="custom-label"> 选择用户 </view> <view slot="title" class="custom-label"> 选择账号 </view>
</t-cell> </t-cell>
<t-picker visible="{{userVisible}}" value="{{userId}}" data-key="id" title="选择用户" cancelBtn="取消" confirmBtn="确认" bindconfirm="onColumnChange" bindcancel="onUserPickerCancel"> <t-picker visible="{{userVisible}}" value="{{userId}}" data-key="id" title="选择账号" cancelBtn="取消" confirmBtn="确认" bindconfirm="onColumnChange" bindcancel="onUserPickerCancel">
<t-picker-item options="{{users}}"></t-picker-item> <t-picker-item options="{{users}}"></t-picker-item>
</t-picker> </t-picker>
<t-input placeholder="请输入合同名称" model:value="{{name}}"> <t-input placeholder="请输入合同名称" model:value="{{name}}">
......
// pages/contract-detail/index.js
Page({
/**
* 页面的初始数据
*/
data: {
imageProps: {
mode: "aspectFill",
style: "width:200%"
}
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(e) {
const item = JSON.parse(e.item)
wx.setNavigationBarTitle({
title: item.text,
})
const l = item.fileIds[0].split("/")
const pdfname = l[l.length - 1]
this.setData({
username: item.username,
fileIds: item.fileIds,
name: item.text,
type: item.type,
pdfname
})
},
openFile() {
wx.cloud.downloadFile({
fileID: this.data.fileIds[0],
success: function (res) {
const filePath = res.tempFilePath
wx.openDocument({
filePath,
fileType: "pdf"
})
},
fail: console.log
})
},
imageClick(e) {
console.log()
wx.previewImage({
urls: this.data.fileIds,
current: this.data.fileIds[e.target.dataset.index]
})
}
})
\ No newline at end of file
{
"usingComponents": {
"t-cell": "tdesign-miniprogram/cell/cell",
"t-image": "tdesign-miniprogram/image/image",
"t-link": "tdesign-miniprogram/link/link",
"t-grid": "tdesign-miniprogram/grid/grid",
"t-grid-item": "tdesign-miniprogram/grid-item/grid-item",
"t-col": "tdesign-miniprogram/col/col",
"t-row": "tdesign-miniprogram/row/row"
}
}
\ No newline at end of file
<t-cell title="账号" hover note="{{username}}" />
<t-cell title="合同名称" hover note="{{name}}" />
<t-cell title="类型" hover note="{{type===0?'PDF':'图片'}}" />
<t-row gutter="16" class="image-container" wx:if="{{type}}">
<t-col span="8" wx:for="{{fileIds}}" wx:key="index">
<t-image src="{{item}}" mode="scaleToFill" shape="round" data-index="{{index}}" bind:tap="imageClick" />
</t-col>
</t-row>
<t-cell wx:else>
<t-link slot="title" size="large" theme="danger" content="{{pdfname}}" prefixIcon="link" hover bind:tap="openFile" />
</t-cell>
\ No newline at end of file
/* pages/contract-detail/index.wxss */
.image-container {
background-color: #fff;
padding: 20rpx;
}
.image-container .t-col {
position: relative;
}
.image-container .t-col::after {
content: "";
display: block;
width: 100%;
padding-top: 80%;
}
.t-image {
position: absolute;
width: 100%;
height: 100%;
}
\ No newline at end of file
...@@ -19,7 +19,7 @@ Page({ ...@@ -19,7 +19,7 @@ Page({
isAdmin: false isAdmin: false
}, },
onShow() { onShow() {
const userInfo = getApp().globalData.userInfo const userInfo = getApp().globalData.userInfo || {}
this.setData({ this.setData({
username: userInfo.username, username: userInfo.username,
isAdmin: userInfo.isAdmin isAdmin: userInfo.isAdmin
...@@ -30,7 +30,7 @@ Page({ ...@@ -30,7 +30,7 @@ Page({
this.setData({ this.setData({
enable: true enable: true
}); });
request("getContract", {}, { request("contract/get", {}, {
loadingMask: false, loadingMask: false,
needUsername: true needUsername: true
}).then(result => { }).then(result => {
...@@ -39,10 +39,10 @@ Page({ ...@@ -39,10 +39,10 @@ Page({
list: list.map(v => ({ list: list.map(v => ({
text: v.name, text: v.name,
createDate: dayjs(v.createDate).format('YYYY-MM-DD HH:mm:ss'), createDate: dayjs(v.createDate).format('YYYY-MM-DD HH:mm:ss'),
type: v.type === 0 ? "pdf" : "图片", type: v.type,
id: v._id, id: v._id,
fileIds: v.fileIds, fileIds: v.fileIds,
username:v.username username: v.username
})), })),
}); });
}).finally(() => { }).finally(() => {
...@@ -50,37 +50,10 @@ Page({ ...@@ -50,37 +50,10 @@ Page({
enable: false enable: false
}) })
}) })
// wx.cloud.callFunction({
// name: "test1",
// data: {
// type: "getContract",
// data: {
// username: getApp().globalData.userInfo.username
// }
// },
// success: (res) => {
// this.setData({
// list: res.result.result.data.map(v => ({
// text: v.name,
// createDate: dayjs(v.createDate).format('YYYY-MM-DD HH:mm:ss'),
// type: v.type === 0 ? "pdf" : "图片",
// id: v._id,
// fileIds: v.fileIds
// })),
// enable: false
// });
// },
// error: (err) => {
// this.setData({
// enable: false
// })
// }
// })
}, },
handleAction() { handleAction() {
wx.navigateTo({ wx.navigateTo({
url: '/pages/addContract/index', url: '/pages/add-contract/index',
}) })
}, },
openFile(item) { openFile(item) {
...@@ -88,24 +61,27 @@ Page({ ...@@ -88,24 +61,27 @@ Page({
type, type,
fileIds fileIds
} = item } = item
console.log(type) wx.navigateTo({
if (type === "pdf") { url: '/pages/contract-detail/index?item=' + JSON.stringify(item),
wx.cloud.downloadFile({
fileID: fileIds[0],
success(res) {
if (res.statusCode === 200) {
wx.openDocument({
filePath: res.tempFilePath,
fileType: "pdf"
})
}
}
})
} else {
wx.previewImage({
urls: fileIds // 需要预览的图片http链接列表
}) })
} // console.log(type)
// if (type === "pdf") {
// wx.cloud.downloadFile({
// fileID: fileIds[0],
// success(res) {
// if (res.statusCode === 200) {
// wx.openDocument({
// filePath: res.tempFilePath,
// fileType: "pdf"
// })
// }
// }
// })
// } else {
// wx.previewImage({
// urls: fileIds // 需要预览的图片http链接列表
// })
// }
}, },
openAction(e) { openAction(e) {
if (this.data.isAdmin) { if (this.data.isAdmin) {
...@@ -127,7 +103,7 @@ Page({ ...@@ -127,7 +103,7 @@ Page({
} else if (index === 1) { } else if (index === 1) {
//编辑 //编辑
wx.navigateTo({ wx.navigateTo({
url: '/pages/updateContract/index?item=' + JSON.stringify(tempitem), url: '/pages/update-contract/index?item=' + JSON.stringify(tempitem),
}) })
} else { } else {
//删除 //删除
...@@ -141,7 +117,7 @@ Page({ ...@@ -141,7 +117,7 @@ Page({
Dialog.confirm(dialogConfig) Dialog.confirm(dialogConfig)
.then(() => { .then(() => {
request("deleteContract", { request("contract/delete", {
id: tempitem.id id: tempitem.id
}).then(() => { }).then(() => {
this.onRefresh() this.onRefresh()
......
...@@ -7,7 +7,9 @@ ...@@ -7,7 +7,9 @@
"t-cell-group": "tdesign-miniprogram/cell-group/cell-group", "t-cell-group": "tdesign-miniprogram/cell-group/cell-group",
"t-tag": "tdesign-miniprogram/tag/tag", "t-tag": "tdesign-miniprogram/tag/tag",
"t-action-sheet": "tdesign-miniprogram/action-sheet/action-sheet", "t-action-sheet": "tdesign-miniprogram/action-sheet/action-sheet",
"t-dialog": "tdesign-miniprogram/dialog/dialog" "t-dialog": "tdesign-miniprogram/dialog/dialog",
"t-message": "tdesign-miniprogram/message/message"
}, },
"disableScroll": true, "disableScroll": true,
"navigationBarTitleText": "合同管理" "navigationBarTitleText": "合同管理"
......
<t-message id="t-message" />
<t-pull-down-refresh value="{{enable}}" bind:refresh="onRefresh"> <t-pull-down-refresh value="{{enable}}" bind:refresh="onRefresh">
<view class="pulldown-refresh"> <view class="pulldown-refresh">
<t-cell-group class="pulldown-refresh__content"> <t-cell-group class="pulldown-refresh__content">
<t-cell wx:for="{{list}}" wx:key="index" title="{{item.text}}" description="{{item.createDate}}" hover arrow data-item="{{item}}" bind:click="openAction"> <t-cell wx:for="{{list}}" wx:key="index" title="{{item.text}}" description="{{item.createDate}}" hover arrow data-item="{{item}}" bind:click="openAction">
<t-tag slot="note">{{item.type}}</t-tag> <t-tag slot="note" theme="{{item.type === 0?'danger':'default'}}">{{item.type === 0 ? "PDF" : "图片"}}</t-tag>
</t-cell> </t-cell>
</t-cell-group> </t-cell-group>
</view> </view>
......
// index.js
Page({
data: {
showTip: false,
powerList: [
{
title: '云函数',
tip: '安全、免鉴权运行业务代码',
showItem: false,
item: [
{
type: 'getOpenId',
title: '获取OpenId',
},
{
type: 'getMiniProgramCode',
title: '生成小程序码',
},
],
},
{
title: '数据库',
tip: '安全稳定的文档型数据库',
showItem: false,
item: [
{
type: 'createCollection',
title: '创建集合',
},
{
type: 'selectRecord',
title: '查询记录',
},
{
title: '更新记录',
page: 'updateRecord',
},
{
title: '聚合操作',
page: 'sumRecord',
},
],
},
{
title: '云存储',
tip: '自带CDN加速文件存储',
showItem: false,
item: [
{
type: 'uploadFile',
title: '上传文件',
},
],
},
{
type: 'singleTemplate',
title: '云模板',
tip: '基于页面模板,快速配置、搭建小程序页面',
tag: 'new',
},
{
type: 'cloudBackend',
title: '云后台',
tip: '开箱即用的小程序后台管理系统',
},
{
title: '云托管',
tip: '不限语言的全托管容器服务',
link: 'https://cloud.weixin.qq.com/cloudrun',
},
],
haveCreateCollection: false,
title: "",
content: ""
},
onClickPowerInfo(e) {
const index = e.currentTarget.dataset.index;
const powerList = this.data.powerList;
const selectedItem = powerList[index];
if (selectedItem.link) {
wx.navigateTo({
url: `../web/index?url=${selectedItem.link}&title=${selectedItem.title}`,
});
} else if (selectedItem.type) {
wx.navigateTo({
url: `/pages/exampleDetail/index?envId=${this.data.selectedEnv?.envId}&type=${selectedItem.type}`,
});
} else if (selectedItem.page) {
wx.navigateTo({
url: `/pages/${selectedItem.page}/index`,
});
} else if (
selectedItem.title === '数据库' &&
!this.data.haveCreateCollection
) {
this.onClickDatabase(powerList,selectedItem);
} else {
selectedItem.showItem = !selectedItem.showItem;
this.setData({
powerList,
});
}
},
jumpPage(e) {
const { type, page } = e.currentTarget.dataset;
if (type) {
wx.navigateTo({
url: `/pages/exampleDetail/index?envId=${this.data.selectedEnv?.envId}&type=${type}`,
});
} else {
wx.navigateTo({
url: `/pages/${page}/index?envId=${this.data.selectedEnv?.envId}`,
});
}
},
onClickDatabase(powerList,selectedItem) {
wx.showLoading({
title: '',
});
wx.cloud
.callFunction({
name: 'quickstartFunctions',
data: {
type: 'createCollection',
},
})
.then((resp) => {
if (resp.result.success) {
this.setData({
haveCreateCollection: true,
});
}
selectedItem.showItem = !selectedItem.showItem;
this.setData({
powerList,
});
wx.hideLoading();
})
.catch((e) => {
wx.hideLoading();
const { errCode, errMsg } = e
if (errMsg.includes('Environment not found')) {
this.setData({
showTip: true,
title: "云开发环境未找到",
content: "如果已经开通云开发,请检查环境ID与 `miniprogram/app.js` 中的 `env` 参数是否一致。"
});
return
}
if (errMsg.includes('FunctionName parameter could not be found')) {
this.setData({
showTip: true,
title: "请上传云函数",
content: "在'cloudfunctions/quickstartFunctions'目录右键,选择【上传并部署-云端安装依赖】,等待云函数上传完成后重试。"
});
return
}
});
},
});
...@@ -12,16 +12,29 @@ Page({ ...@@ -12,16 +12,29 @@ Page({
password: "" password: ""
}, },
login() { login() {
request("login", { if (this.data.username.trim() === "") {
wx.showToast({
title: '账号不能为空',
icon: "none"
})
return
}
if (this.data.password.trim() === "") {
wx.showToast({
title: '密码不能为空',
icon: "none"
})
return
}
request("user/login", {
username: this.data.username, username: this.data.username,
password: this.data.password password: this.data.password
}).then(result => { }).then(result => {
console.log()
getApp().globalData.userInfo = result.userInfo getApp().globalData.userInfo = result.userInfo
const pages=getCurrentPages() const pages = getCurrentPages()
if(pages.length>1){ if (pages.length > 1) {
wx.navigateBack() wx.navigateBack()
}else{ } else {
wx.switchTab({ wx.switchTab({
url: '/pages/user-center/index', url: '/pages/user-center/index',
}) })
......
<view> <view>
<t-input label="用户名" model:value="{{username}}" placeholder="请输入文字" /> <t-input label="账号" model:value="{{username}}" />
<t-input label="输入密码" type="password" model:value="{{password}}" suffixIcon="{{ { name: 'browse-off', ariaLabel: '密码' } }}" /> <t-input label="密码" type="password" model:value="{{password}}" suffixIcon="{{ { name: 'browse-off', ariaLabel: '密码' } }}" />
<t-button theme="primary" size="large" block t-class="external-class" bind:tap="login">登录</t-button> <t-button theme="primary" size="large" block t-class="external-class" bind:tap="login">登录</t-button>
</view> </view>
\ No newline at end of file
...@@ -23,7 +23,7 @@ Page({ ...@@ -23,7 +23,7 @@ Page({
item item
}) { }) {
wx.setNavigationBarTitle({ wx.setNavigationBarTitle({
title: item ? "编辑用户" : "新建用户" title: item ? "编辑账号" : "新建账号"
}) })
if (item) { if (item) {
const data1 = JSON.parse(item); const data1 = JSON.parse(item);
...@@ -47,7 +47,7 @@ Page({ ...@@ -47,7 +47,7 @@ Page({
} }
}, },
handleClick() { handleClick() {
request(this.data.isModify ? "updateUser" : "addUser", this.data.isModify ? { request(this.data.isModify ? "user/update" : "user/add", this.data.isModify ? {
label: this.data.label, label: this.data.label,
remark: this.data.remark, remark: this.data.remark,
isAdmin: this.data.isAdmin, isAdmin: this.data.isAdmin,
......
{ {
"navigationBarTitleText": "用户", "navigationBarTitleText": "账号",
"usingComponents": { "usingComponents": {
"t-input": "tdesign-miniprogram/input/input", "t-input": "tdesign-miniprogram/input/input",
"t-button": "tdesign-miniprogram/button/button", "t-button": "tdesign-miniprogram/button/button",
......
<view> <view>
<t-input label="用户名" model:value="{{label}}"></t-input> <t-input label="账号" model:value="{{label}}"></t-input>
<t-input wx:if="{{!isModify}}" label="密码" model:value="{{password}}" type="password"></t-input> <t-input wx:if="{{!isModify}}" label="密码" model:value="{{password}}" type="password"></t-input>
<t-input label="备注" model:value="{{remark}}"></t-input> <t-input label="备注" model:value="{{remark}}"></t-input>
<t-cell title="管理员" bordered="{{false}}"> <t-cell title="管理员" bordered="{{false}}">
......
// pages/addPontract/index.js // pages/addPontract/index.js
import Message from 'tdesign-miniprogram/message/index';
import { import {
request request
} from "../../utils/request.js" } from "../../utils/request.js"
...@@ -28,8 +29,7 @@ Page({ ...@@ -28,8 +29,7 @@ Page({
}, },
onLoad(e) { onLoad(e) {
const item = JSON.parse(e.item) const item = JSON.parse(e.item)
const type = item.type
const type = item.type === "pdf" ? 0 : 1
const l = item.fileIds[0].split("/"); const l = item.fileIds[0].split("/");
const pdfFileName = l[l.length - 1] const pdfFileName = l[l.length - 1]
this.setData({ this.setData({
...@@ -48,7 +48,7 @@ Page({ ...@@ -48,7 +48,7 @@ Page({
}) })
}, },
onShow() { onShow() {
request("getUser").then(res => { request("user/get").then(res => {
this.setData({ this.setData({
users: res.data.map(v => ({ users: res.data.map(v => ({
id: v._id, id: v._id,
...@@ -107,7 +107,6 @@ Page({ ...@@ -107,7 +107,6 @@ Page({
}, },
fail: console.log fail: console.log
}) })
}, },
handleSuccess(e) { handleSuccess(e) {
const { const {
...@@ -138,6 +137,9 @@ Page({ ...@@ -138,6 +137,9 @@ Page({
}); });
}, },
async createContract() { async createContract() {
if (!this.validate()) {
return
}
wx.showLoading({ wx.showLoading({
title: '', title: '',
}); });
...@@ -152,13 +154,20 @@ Page({ ...@@ -152,13 +154,20 @@ Page({
}) })
file = res.fileID file = res.fileID
} }
request("updateContract", { request("contract/update", {
id: this.data.item.id, id: this.data.item.id,
username: this.data.username, username: this.data.username,
name: this.data.name, name: this.data.name,
type: this.data.type, type: this.data.type,
files: [file] files: [file]
}).then(res => { }).then(res => {
const list = getCurrentPages()
Message.success({
context: list[list.length - 2],
offset: [20, 32],
duration: 2000,
content: '编辑成功',
});
wx.navigateBack() wx.navigateBack()
}).finally(res => { }).finally(res => {
wx.hideLoading() wx.hideLoading()
...@@ -178,12 +187,20 @@ Page({ ...@@ -178,12 +187,20 @@ Page({
filePath: v.url, filePath: v.url,
}) })
})) }))
request("createContract", { request("contract/update", {
id: this.data.item.id,
username: this.data.username, username: this.data.username,
name: this.data.name, name: this.data.name,
type: this.data.type, type: this.data.type,
files: res.map(v => v.fileID) files: res.map(v => v.fileID)
}).then(res => { }).then(res => {
const list = getCurrentPages()
Message.success({
context: list[list.length - 2],
offset: [20, 32],
duration: 2000,
content: '编辑成功',
});
wx.navigateBack() wx.navigateBack()
}).finally(res => { }).finally(res => {
wx.hideLoading() wx.hideLoading()
...@@ -194,6 +211,35 @@ Page({ ...@@ -194,6 +211,35 @@ Page({
} }
} }
},
validate() {
if (this.data.name === "") {
wx.showToast({
title: '合同名称不能为空',
icon: "none"
})
return false
} else {
if (this.data.type === 0) {
console.log(this.data.tempFile.path)
if (!this.data.tempFile.path || this.data.tempFile.path === "") {
wx.showToast({
title: '请上传PDF文件',
icon: "none"
})
return false
}
} else {
if (this.data.originFiles.length === 0) {
wx.showToast({
title: '请上传图片',
icon: "none"
})
return false
}
}
return true
}
} }
}) })
......
<!--pages/addPontract/index.wxml-->
<view class="add-container"> <view class="add-container">
<view> <view>
<t-cell class="mb-16" arrow hover note="{{username}}" bind:click="onUserPicker"> <t-cell class="mb-16" arrow hover note="{{username}}" bind:click="onUserPicker">
<view slot="title" class="custom-label"> 选择用户 </view> <view slot="title" class="custom-label"> 选择账号 </view>
</t-cell> </t-cell>
<t-picker visible="{{userVisible}}" value="{{userId}}" data-key="id" title="选择用户" cancelBtn="取消" confirmBtn="确认" bindconfirm="onColumnChange" bindcancel="onUserPickerCancel"> <t-picker visible="{{userVisible}}" value="{{userId}}" data-key="id" title="选择账号" cancelBtn="取消" confirmBtn="确认" bindconfirm="onColumnChange" bindcancel="onUserPickerCancel">
<t-picker-item options="{{users}}"></t-picker-item> <t-picker-item options="{{users}}"></t-picker-item>
</t-picker> </t-picker>
<t-input placeholder="请输入合同名称" model:value="{{name}}"> <t-input placeholder="请输入合同名称" model:value="{{name}}">
......
...@@ -39,11 +39,6 @@ Page({ ...@@ -39,11 +39,6 @@ Page({
url: '/pages/login/index', url: '/pages/login/index',
}) })
}, },
gotoWxCodePage() {
wx.navigateTo({
url: `/pages/exampleDetail/index?envId=${envList?.[0]?.envId}&type=getMiniProgramCode`,
});
},
handleSelected() { handleSelected() {
getApp().globalData.userInfo = {} getApp().globalData.userInfo = {}
this.setData({ this.setData({
......
{ {
"usingComponents": { "usingComponents": {
"cloud-tip-modal": "/components/cloudTipModal/index",
"t-cell-group": "tdesign-miniprogram/cell-group/cell-group", "t-cell-group": "tdesign-miniprogram/cell-group/cell-group",
"t-cell": "tdesign-miniprogram/cell/cell", "t-cell": "tdesign-miniprogram/cell/cell",
"t-icon": "tdesign-miniprogram/icon/icon", "t-icon": "tdesign-miniprogram/icon/icon",
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
<view class="settings_container"> <view class="settings_container">
<t-cell-group theme="card"> <t-cell-group theme="card">
<t-cell title="合同管理" leftIcon="collage" hover arrow type="navigateTo" url="/pages/contract/index" /> <t-cell title="合同管理" leftIcon="collage" hover arrow type="navigateTo" url="/pages/contract/index" />
<t-cell wx:if="{{isAdmin}}" title="用户管理" leftIcon="usergroup" hover arrow url="/pages/userManage/index" /> <t-cell wx:if="{{isAdmin}}" title="账号管理" leftIcon="usergroup" hover arrow url="/pages/user-manage/index" />
<t-cell title="联系客服" leftIcon="earphone" hover arrow /> <t-cell title="联系客服" leftIcon="earphone" hover arrow />
</t-cell-group> </t-cell-group>
</view> </view>
......
...@@ -24,7 +24,7 @@ Page({ ...@@ -24,7 +24,7 @@ Page({
this.setData({ this.setData({
enable: true enable: true
}); });
request("getUser", {}, { request("user/get", {}, {
loadingMask: false loadingMask: false
}).then(res => { }).then(res => {
this.setData({ this.setData({
...@@ -48,11 +48,11 @@ Page({ ...@@ -48,11 +48,11 @@ Page({
theme: ActionSheetTheme.List, theme: ActionSheetTheme.List,
selector: '#t-action-sheet', selector: '#t-action-sheet',
items: [{ items: [{
label: '编辑用户', label: '编辑账号',
color: '#0052D9', color: '#0052D9',
}, },
{ {
label: '删除用户', label: '删除账号',
color: '#e34d59', color: '#e34d59',
}, },
], ],
...@@ -60,7 +60,7 @@ Page({ ...@@ -60,7 +60,7 @@ Page({
}, },
handleAdd() { handleAdd() {
wx.navigateTo({ wx.navigateTo({
url: '/pages/modifyUser/index', url: '/pages/modify-user/index',
}) })
}, },
handleSelected(e) { handleSelected(e) {
...@@ -69,7 +69,7 @@ Page({ ...@@ -69,7 +69,7 @@ Page({
} = e.detail } = e.detail
if (index === 0) { if (index === 0) {
wx.navigateTo({ wx.navigateTo({
url: '/pages/modifyUser/index?item=' + JSON.stringify(tempitem), url: '/pages/modify-user/index?item=' + JSON.stringify(tempitem),
}) })
//编辑 //编辑
} else { } else {
...@@ -84,7 +84,7 @@ Page({ ...@@ -84,7 +84,7 @@ Page({
Dialog.confirm(dialogConfig) Dialog.confirm(dialogConfig)
.then(() => { .then(() => {
request("deleteUser", { request("user/delete", {
id: tempitem.id id: tempitem.id
}).then(() => { }).then(() => {
this.onRefresh() this.onRefresh()
......
{ {
"navigationBarTitleText": "用户管理", "navigationBarTitleText": "账号管理",
"usingComponents": { "usingComponents": {
"t-pull-down-refresh": "tdesign-miniprogram/pull-down-refresh/pull-down-refresh", "t-pull-down-refresh": "tdesign-miniprogram/pull-down-refresh/pull-down-refresh",
"t-skeleton": "tdesign-miniprogram/skeleton/skeleton", "t-skeleton": "tdesign-miniprogram/skeleton/skeleton",
......
const app = getApp();
let that = null;
Page({
onLoad(options) {
that = this;
if (options.url != null) {
this.setData({
webUrl: options.url,
});
if (options.title != null) {
wx.setNavigationBarTitle({
title: options.title,
});
}
} else {
wx.navigateBack({
delta: 1,
});
}
},
});
{
"usingComponents": {}
}
\ No newline at end of file
<web-view src="{{webUrl}}"></web-view>
\ No newline at end of file
web-view{
width: 100%;
height: 100%;
}
\ No newline at end of file
...@@ -16,11 +16,12 @@ export const request = async (type, data = {}, config = {}) => { ...@@ -16,11 +16,12 @@ export const request = async (type, data = {}, config = {}) => {
} }
transData.username = userInfo.username transData.username = userInfo.username
} }
const [name, type1] = type.split("/")
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
wx.cloud.callFunction({ wx.cloud.callFunction({
name: 'test1', name,
data: { data: {
type, type: type1,
data: transData, data: transData,
}, },
success: (res) => { success: (res) => {
......
...@@ -33,5 +33,6 @@ ...@@ -33,5 +33,6 @@
} }
}, },
"description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档:https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html", "description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档:https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html",
"projectname": "miniprogram-1" "projectname": "miniprogram-1",
"libVersion": "3.3.5"
} }
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论